foree_checkout 0.0.5 foree_checkout: ^0.0.5 copied to clipboard
A new flutter plugin project.
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:foree_checkout/foree_checkout.dart';
import 'package:flutter/services.dart';
void main() => runApp(MyApp());
late Map<String, dynamic> data;
late String message="",referencenum="",status="";
late bool createbill, istesting;
final keycontroller = TextEditingController();
final amountcontroller = TextEditingController();
final referencenumbercontroller = TextEditingController();
final customeremailcontroller = TextEditingController();
final customernumbercontroller = TextEditingController();
final consumernamecontroller = TextEditingController();
final tokencontroller = TextEditingController();
final paymentmethodcontroller = TextEditingController();
final billdetailidcontroller = TextEditingController();
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
]);
return MaterialApp(
title: 'Welcome to Flutter',
home: Scaffold(body: Checkout(title: "Checkout")),
);
}
}
class Checkout extends StatefulWidget {
Checkout({required this.title});
final String title;
@override
_CheckoutState createState() => _CheckoutState();
}
class _CheckoutState extends State<Checkout> {
@override
void initState() {
super.initState();
keycontroller.text = "<APIKEY>";
referencenumbercontroller.text = "<REFERENCE_NUMBER>";
amountcontroller.text = "<AMOUNT>";
customeremailcontroller.text = "<EMAIL>";
customernumbercontroller.text = "<PHONE_NUMBER>";
consumernamecontroller.text = "<NAME>";
billdetailidcontroller.text = "<BILL_DETAIL_ID>";
paymentmethodcontroller.text = "<PAYMENT_METHOD>";
}
int _billValue = 0;
int _isTestingValue = 0;
void _handleBillValueChange(int value){
setState(() {
_billValue = value;
switch (_billValue) {
case 0:
createbill = false;
break;
case 1:
createbill = true;
break;
}
});
}
void _handleIsTestingValueChange(int value){
setState(() {
_isTestingValue = value;
switch (_isTestingValue) {
case 0:
istesting = false;
break;
case 1:
istesting = true;
break;
}
});
}
@override
Widget build(BuildContext context) {
final node = FocusScope.of(context);
double Width = MediaQuery.of(context).size.width;
return ListView(
children: [
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
child: Column(
children: [
Container(
margin: EdgeInsets.only(
left: 5.0, top: 25.0, right: 5.0, bottom: 5.0),
child: TextField(
// textInputAction: TextInputAction.next,
// onEditingComplete: () => node.nextFocus(),
controller: keycontroller,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: "Key",
),
),
),
Container(
width: Width ,
margin:
EdgeInsets.only(left: 20.0, right: 10.0, top: 5.0, bottom: 5.0),
child: Text("Create Bill", style: TextStyle(fontSize: 18.0, fontWeight: FontWeight.bold))
),
Container(
child: Column(
children: [
ListTile(
title: Text(
'False'),
leading: Radio(
value: 0,
groupValue: _billValue,
onChanged: (value){
_handleBillValueChange(0);
},
),
),
ListTile(
title: Text(
'True'),
leading: Radio(
value: 1,
groupValue: _billValue,
onChanged: (value){
_handleBillValueChange(1);
},
),
),
],
),
),
Container(
width: Width ,
margin:
EdgeInsets.only(left: 20.0, right: 10.0, top: 5.0, bottom: 5.0),
child: Text("Is Testing ", style: TextStyle(fontSize: 18.0, fontWeight: FontWeight.bold))
),
Container(
child: Column(
children: [
ListTile(
title: Text(
'False'),
leading: Radio(
value: 0,
groupValue: _isTestingValue,
onChanged: (value){
_handleIsTestingValueChange(0);
},
),
),
ListTile(
title: Text(
'True'),
leading: Radio(
value: 1,
groupValue: _isTestingValue,
onChanged: (value){
_handleIsTestingValueChange(1);
},
),
),
],
),
),
Container(
margin:
EdgeInsets.symmetric(vertical: 5.0, horizontal: 5.0),
child: TextField(
controller: amountcontroller,
// textInputAction: TextInputAction.done,
// onEditingComplete: () => node.nextFocus(),
enableSuggestions: false,
autocorrect: false,
keyboardType: TextInputType.number,
decoration: InputDecoration(
border: OutlineInputBorder(),
fillColor: Colors.white,
labelText: "Amount",
),
),
),
Container(
margin:
EdgeInsets.symmetric(vertical: 5.0, horizontal: 5.0),
child: TextField(
controller: paymentmethodcontroller,
// textInputAction: TextInputAction.done,
// onEditingComplete: () => node.nextFocus(),
enableSuggestions: false,
autocorrect: false,
decoration: InputDecoration(
border: OutlineInputBorder(),
fillColor: Colors.white,
labelText: "Payment Method",
),
),
),
Container(
margin:
EdgeInsets.symmetric(vertical: 5.0, horizontal: 5.0),
child: TextField(
controller: referencenumbercontroller,
// textInputAction: TextInputAction.done,
// onEditingComplete: () => node.nextFocus(),
enableSuggestions: false,
autocorrect: false,
decoration: InputDecoration(
border: OutlineInputBorder(),
fillColor: Colors.white,
labelText: "Reference Number",
),
),
),
Container(
margin:
EdgeInsets.symmetric(vertical: 5.0, horizontal: 5.0),
child: TextField(
controller: customeremailcontroller,
// textInputAction: TextInputAction.done,
// onEditingComplete: () => node.nextFocus(),
enableSuggestions: false,
autocorrect: false,
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
border: OutlineInputBorder(),
fillColor: Colors.white,
labelText: "Email",
),
),
),
Container(
margin:
EdgeInsets.symmetric(vertical: 5.0, horizontal: 5.0),
child: TextField(
controller: customernumbercontroller,
// textInputAction: TextInputAction.done,
// onEditingComplete: () => node.nextFocus(),
enableSuggestions: false,
autocorrect: false,
keyboardType: TextInputType.number,
textInputAction: TextInputAction.next,
decoration: InputDecoration(
border: OutlineInputBorder(),
fillColor: Colors.white,
labelText: "Phone",
),
),
),
Container(
margin:
EdgeInsets.symmetric(vertical: 5.0, horizontal: 5.0),
child: TextField(
controller: consumernamecontroller,
// textInputAction: TextInputAction.done,
// onEditingComplete: () => node.nextFocus(),
enableSuggestions: false,
autocorrect: false,
decoration: InputDecoration(
border: OutlineInputBorder(),
fillColor: Colors.white,
labelText: "Name",
),
),
),
Container(
margin:
EdgeInsets.symmetric(vertical: 5.0, horizontal: 5.0),
child: TextField(
controller: tokencontroller,
// textInputAction: TextInputAction.done,
// onEditingComplete: () => node.nextFocus(),
enableSuggestions: false,
autocorrect: false,
decoration: InputDecoration(
border: OutlineInputBorder(),
fillColor: Colors.white,
labelText: "Token",
),
),
),
Container(
margin:
EdgeInsets.symmetric(vertical: 5.0, horizontal: 5.0),
child: TextField(
controller: billdetailidcontroller,
// textInputAction: TextInputAction.done,
// onEditingComplete: () => node.nextFocus(),
enableSuggestions: false,
autocorrect: false,
decoration: InputDecoration(
border: OutlineInputBorder(),
fillColor: Colors.white,
labelText: "Bill Detail Id",
),
),
),
Container(
margin: EdgeInsets.all(25.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5.0),
color: Colors.blue),
child: FlatButton(
onPressed: () {
if(int.parse(amountcontroller.text) > 1000000 || int.parse(amountcontroller.text) <= 0 && keycontroller.text.length == 0 && referencenumbercontroller.text.length == 0 && customeremailcontroller.text.length == 0 && customernumbercontroller.text.length == 0){
return;
}
data = {
'key': keycontroller.text,
'amount': int.parse(amountcontroller.text).abs().toString(),
'create_bill': _billValue,
'reference_number': referencenumbercontroller.text,
'callback': 'callbackflutter',
'customer_email_address':
customeremailcontroller.text,
'customer_phone_number':
customernumbercontroller.text,
'token': tokencontroller.text,
'payment_method': paymentmethodcontroller.text,
'consumer_name': consumernamecontroller.text,
'bill_detail_id': billdetailidcontroller.text,
};
Foree.initiateCheckOut(
isTesting: istesting,
data: data,
context: context,
callBack: (data) {
var args = json.decode(data);
var statusdata = "", referencenumber ="",messagedata = "";
if(args['status'] != null) statusdata = args['status'].toString();
if(args['reference_number'] != null) referencenumber = args['reference_number'];
if(args['message'] != null) messagedata = args['message'];
setState(() {
status = statusdata;
referencenum = referencenumber;
message = messagedata;
});
},
);
},
child: Text("Pay Now")),
),
Container(
width: Width ,
margin:
EdgeInsets.only(left: 20.0, right: 10.0, top: 5.0, bottom: 20.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
children: [
Text("Status: $status", style: TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.bold,
),
),
Text("Ref No: $referencenum", style: TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.bold,
),
),
Text("Message: $message", style: TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.bold,
),
),
],
)
),
],
),
)
],
)
],
);
}
}