paymentComponent function
Widget
paymentComponent(
- bool displayError,
- dynamic context,
- dynamic transactionAmount,
- dynamic _formKey,
- dynamic _autoValidate,
- dynamic phoneController,
- dynamic xApiKey,
- dynamic transactionId,
- dynamic transactionCallBackUrl,
- dynamic providerShortTag,
- dynamic merchandPassword,
- dynamic merchandUserName,
- dynamic actionAfterProccess,
- Function isvalidPhoneState,
- String sandbox,
- String pspName,
- String imageUrl
Implementation
Widget paymentComponent(
bool displayError,
context,
transactionAmount,
_formKey,
_autoValidate,
phoneController,
xApiKey,
transactionId,
transactionCallBackUrl,
providerShortTag,
merchandPassword,
merchandUserName,
actionAfterProccess,
Function isvalidPhoneState,
String sandbox,
String pspName,
String imageUrl,
) {
return Padding(
padding: const EdgeInsets.only(left: 30, right: 30),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
GestureDetector(
onTap: () {
Navigator.of(context).pop();
},
child: const Icon(
Icons.arrow_back_ios,
color: Colors.black,
),
),
const SizedBox(
width: 15,
),
SizedBox(
width: MediaQuery.of(context).size.width * 0.12,
child: Image.network(imageUrl),
),
const SizedBox(
width: 15,
),
Text(
pspName,
style: const TextStyle(color: Colors.black, fontWeight: FontWeight.bold, fontSize: 18),
),
const SizedBox(
width: 60,
),
],
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.01,
),
const Divider(
color: Colors.black,
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.02,
),
Text(
"Amount to pay",
style: TextStyle(
color: Colors.black, fontSize: MediaQuery.of(context).size.width * 0.045, fontWeight: FontWeight.w700),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.01,
),
Text(
"${getOcy().format((int.parse(transactionAmount)))} XAF",
style: TextStyle(color: payUnitGreenColor, fontSize: 40, fontWeight: FontWeight.bold),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.015,
),
Form(
key: _formKey,
autovalidateMode: AutovalidateMode.always,
child: Column(
children: [
const SizedBox(height: 10),
TextFormField(
keyboardType: TextInputType.number,
controller: phoneController,
decoration: InputDecoration(
contentPadding: EdgeInsets.all(MediaQuery.of(context).size.height * 0.020),
hintText: "Payer's phone number",
hintStyle: TextStyle(
color: Colors.grey,
// fontWeight: FontWeight.bold,
fontStyle: FontStyle.italic,
fontSize: MediaQuery.of(context).size.width * 0.032,
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
),
prefixIcon: Icon(
FontAwesomeIcons.phone,
color: payUnitGreenColor,
size: 20,
),
),
validator: (String? arg) {
if (arg!.isEmpty) {
return 'Enter a phone number';
} else if (arg.length < 9) {
return 'The phone number must be 9 digits , example: 6562090** ';
} else if (arg.length > 9) {
return 'The phone number must be 9 digits , example: 6562090** ';
} else
return null;
},
),
const SizedBox(height: 20),
AnimButton(
color: payUnitGreenColor,
pressEvent: () {
/// verifier si les champs sont vide .
if (_formKey.currentState.validate()) {
// If all data are correct then save data to out variables
_formKey.currentState.save();
AwesomeDialog(
dismissOnBackKeyPress: false,
dismissOnTouchOutside: false,
context: context,
dialogType: DialogType.NO_HEADER,
animType: AnimType.BOTTOMSLIDE,
title: "Confirm",
desc: 'Do you confirm this payment',
btnOkColor: payUnitGreenColor,
btnOkText: "OK",
btnOkIcon: Icons.check,
btnOkOnPress: () {
//set the stream to true if the payment is running
// set the stream to false to visible this part of the code
// Navigator.pop(context);
payUnitStream.paymentSink.add(true);
// Navigator.pop(context);
ApiService api = ApiService();
api.makePayment(
paymentType: null,
xApiKey: xApiKey,
transactionAmount: transactionAmount,
transactionId: transactionId,
transactionCallBackUrl: transactionCallBackUrl,
phoneNumber: phoneController.text,
providerShortTag: providerShortTag,
merchandPassword: merchandPassword,
merchandUserName: merchandUserName,
context: context,
currency: "XAF",
actionAfterProccess: actionAfterProccess,
mode: sandbox,
userName: '',
);
},
btnCancelOnPress: () {},
btnCancelColor: Colors.red,
btnCancelIcon: Icons.cancel,
btnCancelText: 'Cancel')
.show();
} else {
//If all data are not valid then start auto validation.
isvalidPhoneState();
}
},
text: 'CONTINUE',
icon: null,
)
],
),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.05,
),
poweredText(),
// buildPayUnitWidget(context),
Visibility(
visible: displayError,
child: const Text(
"Hummm something didn't work, please retry ",
style: TextStyle(color: Colors.red, fontSize: 12),
textAlign: TextAlign.center,
),
)
],
),
);
}