paymentComponent function

Widget paymentComponent(
  1. bool displayError,
  2. dynamic context,
  3. dynamic transactionAmount,
  4. dynamic _formKey,
  5. dynamic _autoValidate,
  6. dynamic phoneController,
  7. dynamic xApiKey,
  8. dynamic transactionId,
  9. dynamic transactionCallBackUrl,
  10. dynamic providerShortTag,
  11. dynamic merchandPassword,
  12. dynamic merchandUserName,
  13. dynamic actionAfterProccess,
  14. Function isvalidPhoneState,
  15. String sandbox,
  16. String pspName,
  17. 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,
          ),
        )
      ],
    ),
  );
}