Copy import 'package:flutter/material.dart';
import 'package:kkiapay_flutter_sdk/kkiapay_flutter_sdk.dart';
void main() => runApp(App());
void callback(response, context) {
switch ( response['status'] ) {
case PAYMENT_CANCELLED:
Navigator.pop(context);
debugPrint(PAYMENT_CANCELLED);
break;
case PAYMENT_INIT:
debugPrint(PAYMENT_INIT);
break;
case PENDING_PAYMENT:
debugPrint(PENDING_PAYMENT);
break;
case PAYMENT_SUCCESS:
Navigator.pop(context);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SuccessScreen(
amount: response['requestData']['amount'],
transactionId: response['transactionId'],
),
),
);
break;
default:
debugPrint(UNKNOWN_EVENT);
break;
}
}
final kkiapay = KKiaPay(
amount: 1000,//
countries: ["BJ","CI","SN","TG"],//
phone: "22961000000",//
name: "John Doe",//
email: "[email protected] ",//
reason: 'Transaction reason',//
data: 'Fake data',//
sandbox: true,//
apikey: public_api_key,//
callback: callback,//
theme: defaultTheme, // Ex : "#222F5A",
partnerId: 'AxXxXXxId',//
paymentMethods: ["momo","card"]//
);
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
backgroundColor: nColorPrimary,
title: Text('Kkiapay Sample'),
centerTitle: true,
),
body: KkiapaySample(),
),
);
}
}
class KkiapaySample extends StatelessWidget {
const KkiapaySample({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
ButtonTheme(
minWidth: 500.0,
height: 100.0,
child: TextButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Color(0xff222F5A)),
foregroundColor: MaterialStateProperty.all(Colors.white),
),
child: const Text(
'Pay Now',
style: TextStyle(color: Colors.white),
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => kkiapay),
);
},
),
),
const SizedBox(height: 50,),
ButtonTheme(
minWidth: 500.0,
height: 100.0,
child: TextButton(
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all(const Color(0xff222F5A)),
foregroundColor: MaterialStateProperty.all(Colors.white),
),
child: const Text(
'Pay Now ( WEB )',
style: TextStyle(color: Colors.white),
),
onPressed: () {
KkiapayFlutterSdkPlatform.instance.pay(kkiapay, context, callback);
},
),
)
],
)
);
}
}