credo_gateway 0.0.2
credo_gateway: ^0.0.2 copied to clipboard
Official plugin for Credo Payment gateway https://credocentral.com/
example/lib/main.dart
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:credo_gateway/credo_gateway.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Credo Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage());
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({
Key? key,
}) : super(key: key);
@override
MyHomePageState createState() => MyHomePageState();
}
class MyHomePageState extends State<MyHomePage> {
CredoPlugin? credoPlugin;
Future<void> initPayment() async {
try {
if (kDebugMode) {
print('Initial payment with credo');
}
InitPaymentResponse initial = await credoPlugin!.initialPayment(
amount: 100.0,
currency: 'NGN',
customerEmail: 'charlesarchibong10@gmail.com',
customerName: 'Charles Archibong',
customerPhoneNo: '09039311559',
);
if (kDebugMode) {
print(initial.toMap());
}
} catch (e) {
if (kDebugMode) {
print(e);
}
if (e is CredoException) {
if (kDebugMode) {
print(e.message);
}
} else {
if (kDebugMode) {
print(e);
}
}
}
}
Future<void> makePayment() async {
try {
if (kDebugMode) {
print('Make payment with credo');
}
var res = await credoPlugin!.payWithWebUI(
context: context,
amount: 100.0,
currency: 'NGN',
customerEmail: 'jerryakem99@gmail.com',
customerName: 'Jerry Akem',
customerPhoneNo: '08132368804');
if (kDebugMode) {
print(res);
}
} catch (e) {
if (kDebugMode) {
print(e);
}
if (e is CredoException) {
if (kDebugMode) {
print(e.message);
}
} else {
if (kDebugMode) {
print(e);
}
}
}
}
@override
void initState() {
credoPlugin = const CredoPlugin(
publicKey: 'pk_demo-Ghz9Wo4cGeebxzDwfNZdooKLFtX7op.cXgwh6MyBs-d',
);
makePayment();
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Credo'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'Your payment slug :',
),
Text(
'...',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
);
}
}