medapay 0.1.0
medapay: ^0.1.0 copied to clipboard
The MedaPay Flutter SDK provides convenient access to the MedaPay API from applications written in dart for Flutter.
import 'package:example/theme.dart';
import 'package:flutter/material.dart';
import 'package:medapay/entity.dart';
import 'package:medapay/medapay.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'MedaPay SDK Demo',
theme: ThemeData(
primarySwatch: mtpalette,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'MedaPay SDK Demo'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
MedaPayLauncher launcher = MedaPayLauncher(
paymentTitle: 'Store Name', authToken: "eyJhbxxx", isSandbox: true);
void onReferenceNumber(String referenceNumber) {
print("Reference Number: " + referenceNumber);
}
void onSuccess(MedaPayBillInfo billInfo) {
print("Success Data: " + billInfo.toString());
}
void onError(MedaPayError error) {
print("Error: " + error.toString());
}
void onCancel() {
print("Canceled by user");
}
void onBillInfo(MedaPayBillInfo billInfo) {
print("Bill Info Data: " + billInfo.toString());
}
void _initPayment(context) {
launcher.initWithReferenceNumber(
context: context,
referenceNumber: '10000515',
onSuccess: onSuccess,
onCancel: onCancel,
onError: onError,
onBillInfo: onBillInfo);
// launcher.init(
// context: context,
// payment: new MedaPayPayment(
// orderId: 'xx1235678',
// customerName: "Ayele Mekite",
// accountNumber: "251913008595",
// description:
// "Flutter SDK Demo Payment Flutter SDK Demo Payment Flutter SDK Demo Payment",
// amount: 6000.55,
// callbackUrl: 'https://example.com/callback',
// cancelUrl: 'https://example.com/cancel'),
// onReferenceNumber: onReferenceNumber,
// onSuccess: onSuccess,
// onError: onError,
// onCancel: onCancel,
// paymentMethods: MedaPayPaymentMethods.NON_USSD_METHODS,
// preferedPaymentMethod: MedaPayPaymentMethods.AMOLE);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
RaisedButton(
onPressed: () {
_initPayment(context);
},
color: mtpalette,
child: const Text(
'Launch Test Payment',
style: TextStyle(
fontSize: 16,
color: Colors.white,
fontWeight: FontWeight.bold),
)),
])),
// This trailing comma makes auto-formatting nicer for build methods.
);
}
}