iframe_cashpay_plugin 3.0.0 copy "iframe_cashpay_plugin: ^3.0.0" to clipboard
iframe_cashpay_plugin: ^3.0.0 copied to clipboard

A plugin to add payments iframe_cashpay to your flutter application..

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:iframe_cashpay_plugin/iframe_cashpay_plugin.dart';
import 'package:iframe_cashpay_plugin/cash_pay_button.dart';

void main() {
  runApp(const PayMaterialApp());
}

class PayMaterialApp extends StatelessWidget {
  const PayMaterialApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: 'Pay for Flutter Demo',
      home: PaySampleApp(title: 'PaySampleApp'),
    );
  }
}

class PaySampleApp extends StatefulWidget {
  final String title;
  const PaySampleApp({Key? key, required this.title}) : super(key: key);

  @override
  State<PaySampleApp> createState() => PaySampleAppState();
}

class PaySampleAppState extends State<PaySampleApp> {
  String orderId = "";

  /// This function Send itemList for yor server.
  ///
  /// @param itemList.
  /// @return iframeURL and orderId.
  ///
  /// Example:
  ///
  /// ```
  /// var res = sendItems(itemList);
  /// print(res.then((iframeURL)=>iframeURL)); // "https://########"
  /// ```
  Future<String> sendItems(itemList) async {
    //Send itemList for yor server and post CreateOrder.
    //iframeURL returned from Response CreateOrder
    //Documentation https://documenter.getpostman.com/view/17550185/2s93XzwN9o
    String iframeURL = "";
    //orderID returned from Response CreateOrder
    //Store the orderID in the orderId variable to use on function onConfirmPayment
    orderId = "";
    return iframeURL;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
        ),
        backgroundColor: Colors.white,
        body: ListView(children: [
          CashPayButton(width:MediaQuery.of(context).size.width ,onTap: () async {
            await sendItems({
              {
                "itemName": "كتاب",
                "amount": 2000,
              },
              {
                "itemName": "ساعة",
                "amount": 5000,
              }
            }).then((iframeURL) => showModalBottomSheet(
                context: context,
                isDismissible: false,
                shape: const RoundedRectangleBorder(
                  borderRadius: BorderRadius.vertical(
                    top: Radius.circular(30.0),
                  ),
                ),
                isScrollControlled: true,
                builder: (BuildContext context) {
                  return Container(
                      padding: const EdgeInsets.only(
                          left: 10.0, right: 10.0, top: 10.0),
                      height: MediaQuery.of(context).size.height * 0.7,
                      //IframeCashPay widget displays the Cash E-wallet payment iframe.
                      /// This widget IframeCashPay displays the Cash E-wallet payment iframe.
                      ///
                      /// @param iframeURL .
                      /// @param onConfirmPayment.
                      /// @param onCancel.
                      /// @param onError.
                      /// @return message onConfirmPayment or onCancel or onError.
                      ///
                      /// Example:
                      ///
                      /// ```
                      ///  IframeCashPay( iframeURL: "https://########",
                      ///    onConfirmPayment: onConfirmPayment,
                      ///    onCancel: onCancel,
                      ///    onError: onError,);
                      /// ```
                      child: IframeCashPay(
                        iframeURL: iframeURL,
                        onConfirmPayment: onConfirmPayment,
                        onCancel: onCancel,
                        onError: onError,
                      ));
                }));})
        ]));
  }

  /// This function callback onConfirmPayment.
  ///
  /// @param message.
  /// @return message onConfirmPayment.
  ///
  /// Example:
  ///
  /// ```
  /// onConfirmPayment("NEEDTOCHECK");
  /// ```
  onConfirmPayment(message) {
    //After Confirmatin from iFrameCashPay.
    if (orderId.isNotEmpty) {
      //Here use CheckOrderStatus on your server to check order status.
      //Documentation https://documenter.getpostman.com/view/17550185/2s93XzwN9o
    }
    Navigator.pop(context);
  }

  /// This function callback onCancel.
  ///
  /// @param message.
  /// @return message onCancel.
  ///
  /// Example:
  ///
  /// ```
  /// onCancel("Cancel");
  /// ```
  onCancel(message) {
    //After Cancel from iFrameCashPay.
    Navigator.pop(context);
  }

  /// This function callback onError.
  ///
  /// @param message.
  /// @return message onError.
  ///
  /// Example:
  ///
  /// ```
  /// onError("Error");
  /// ```
  onError(message) {
    //After return Error from iFrameCashPay.
    Navigator.pop(context);
  }
}
5
likes
150
points
24
downloads

Publisher

unverified uploader

Weekly Downloads

A plugin to add payments iframe_cashpay to your flutter application..

Repository (GitHub)
View/report issues

Documentation

API reference

License

ISC (license)

Dependencies

flutter, flutter_inappwebview

More

Packages that depend on iframe_cashpay_plugin