dgepay 1.0.0
dgepay: ^1.0.0 copied to clipboard
DGePay is the first licensed Payment System Operator (PSO) in Bangladesh from Bangladesh Bank for White Label Merchant Acquiring (WLMA). We are building the largest merchant payment network allowing s [...]
example/lib/main.dart
import 'dart:math';
import 'package:dgepay/dgepay.dart';
import 'package:dgepay/models/config.dart';
import 'package:dgepay/models/dgepay_status_resp_model.dart';
import 'package:dgepay/models/dgepay_payment_req_model.dart';
import 'package:dgepay/models/dgepay_payment_resp_model.dart';
import 'package:dgepay/utilities/constants.dart';
import 'package:flutter/material.dart';
void main() {
// initializeDGePay(environment: 'uat');
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'DGePay Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.red),
useMaterial3: true,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
DGePay dGePay = DGePay();
DGePayConfigs dGePayConfigs = DGePayConfigs(
env: DGePayEnvironmentType.uat,
clientID: 'b20699df06a7456fbd251d0b98530dd4',
clientSecretKey: '98c055a82a0efe19',
clientAPIKey: '6bed50b19c1340f4b61ed376b22ec243');
TextEditingController amountFieldController = TextEditingController();
TextEditingController noteFieldController = TextEditingController();
TextEditingController phoneFieldController = TextEditingController();
DGePayPaymentRespModel paymentRespModel = DGePayPaymentRespModel();
DGePayStatusRespModel statusRespModel = DGePayStatusRespModel();
String generateHexId(int length) {
const chars = '0123456789abcdef';
final random = Random();
return List.generate(length, (index) => chars[random.nextInt(16)]).join();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('DGePay Demo', style: TextStyle(color: Colors.white)),
backgroundColor: Colors.red,
),
body: Padding(
padding: const EdgeInsets.all(16),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
const SizedBox(
width: double.infinity,
child: Text(
'Amount',
style: TextStyle(fontSize: 16),
),
),
const SizedBox(
height: 5,
),
TextField(
controller: amountFieldController,
keyboardType: TextInputType.number,
decoration: const InputDecoration(
filled: true,
fillColor: Colors.white,
hintText: 'Enter Amount',
),
),
const SizedBox(
height: 10,
),
const SizedBox(
width: double.infinity,
child: Text(
'Note',
style: TextStyle(fontSize: 16),
),
),
const SizedBox(
height: 5,
),
TextField(
controller: noteFieldController,
keyboardType: TextInputType.text,
decoration: const InputDecoration(
filled: true,
fillColor: Colors.white,
hintText: 'Enter Note',
),
),
const SizedBox(
height: 10,
),
const SizedBox(
width: double.infinity,
child: Text(
'Customer Phone No',
style: TextStyle(fontSize: 16),
),
),
const SizedBox(
height: 5,
),
TextField(
controller: phoneFieldController,
keyboardType: TextInputType.phone,
maxLength: 11,
decoration: const InputDecoration(
filled: true,
fillColor: Colors.white,
hintText: 'Enter Customer Phone No',
),
),
const SizedBox(
height: 15,
),
ElevatedButton(
onPressed: () async {
FocusScope.of(context).unfocus();
DGePayPaymentReqModel paymentReqMode = DGePayPaymentReqModel(
amount: double.parse(amountFieldController.text),
customerToken: null,
note: noteFieldController.text,
uniqueTxnId: generateHexId(32),
dialCode: '+88',
phoneNumber: phoneFieldController.text,
dGePayConfigs: dGePayConfigs);
paymentRespModel = await dGePay.makePayment(
context: context,
dGePayConfigs: dGePayConfigs,
dGePayPaymentReqModel: paymentReqMode,
);
if (paymentRespModel.status == true) {
debugPrint(paymentRespModel.status.toString());
debugPrint(paymentRespModel.message);
debugPrint(paymentRespModel.dGePayOrderId);
}
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
padding: const EdgeInsets.symmetric(horizontal: 45, vertical: 20),
textStyle:
const TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
child:
const Text('MAKE PAYMENT', style: TextStyle(color: Colors.white)),
),
const SizedBox(
height: 15,
),
ElevatedButton(
onPressed: () async {
FocusScope.of(context).unfocus();
statusRespModel = await dGePay.checkStatus(
context: context,
dGePayConfigs: dGePayConfigs,
uniqueTxnId: '97f7dda2c12dfcb6c9875e629d1c2f07',
);
if (statusRespModel.status == true) {
debugPrint(statusRespModel.status.toString());
debugPrint(statusRespModel.amount.toString());
debugPrint(statusRespModel.message);
debugPrint(statusRespModel.dGePayOrderId);
}
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
padding: const EdgeInsets.symmetric(horizontal: 45, vertical: 20),
textStyle:
const TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
child: const Text('Check Transaction',
style: TextStyle(color: Colors.white)),
),
],
),
),
);
}
}