ercaspay 0.0.3+1 ercaspay: ^0.0.3+1 copied to clipboard
A Flutter package for ercaspay.
import 'package:ercaspay/ercaspay.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Ercaspay Example',
theme: ThemeData(
primarySwatch: Colors.red,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Ercaspay Example"),
),
body: Center(
child: SizedBox(
child: ElevatedButton(
onPressed: () => gotoPaymentGateway(),
child: const Text('Go to Ercaspay Checkout'),
),
)),
);
}
gotoPaymentGateway() async {
final ercaspay = Ercaspay(
context: context,
token: 'ECRS-TEST-SKldkjsdwehweuh3u4h3h42uh3UeoOhSK5mPB',
amount: 100,
paymentReference: 'R5md7gd9b4s3h2j5d2q',
redirectUrl: 'https://omolabakeventures.com',
currency: 'NGN',
feeBearer: 'customer',
paymentMethods: 'card,bank-transfer,ussd,qrcode',
customerDetails: CustomerDetails(name: 'Ola',email: 'ola@gmail.com',phoneNumber: '07023456789'),
description: 'The description for this payment goes here',
metadata: {
"firstname": "Ola",
"lastname": "Benson",
"email": "iie@mail.com"
},
live: false
);
PaymentResponse? response = await ercaspay.chargeTransaction();
if (response != null) {
if (response.success!) {
//handle success response
} else {
//Handle not successful
}
} else {
//User cancelled checkout
}
}
}