Thawani.pay constructor

Thawani.pay(
  1. BuildContext context, {
  2. required String api,
  3. required List<Product> products,
  4. required void onCreate(
    1. Create create
    ),
  5. required void onCancelled(
    1. Map<String, dynamic> payStatus
    ),
  6. required void onPaid(
    1. Map<String, dynamic> payStatus
    ),
  7. Widget? child,
  8. int? expiredInMinuets,
  9. required String pKey,
  10. required Map<String, dynamic> metadata,
  11. required String clintID,
  12. ButtonStyle? buttonStyle,
  13. bool? testMode,
  14. String? customerID,
  15. required bool saveCard,
  16. void onError(
    1. Map error
    )?,
  17. void onCreateCustomer(
    1. CreateCustomerModel data
    )?,
  18. Color? savedCardBackground,
  19. Color? savedCardTextColor,
  20. Widget? savedCardsAppBarText,
  21. void getSavedCustomer(
    1. String data
    )?,
  22. String? deleteTextError,
  23. String? deleteText,
  24. String? selectCardText,
  25. void savedCards(
    1. List<CardData> data
    )?,
  26. String? successUrl,
  27. String? cancelUrl,
})

Implementation

Thawani.pay(BuildContext context,
    {required this.api,
    required this.products,
    required this.onCreate,
    required this.onCancelled,
    required this.onPaid,
    this.child,
      this.expiredInMinuets,
    required this.pKey,
      required  this.metadata,
    required this.clintID,
    this.buttonStyle,
    this.testMode,
    this.customerID,
    required this.saveCard,
    this.onError,
    this.onCreateCustomer,
    this.savedCardBackground,
    this.savedCardTextColor,
    this.savedCardsAppBarText,
    this.getSavedCustomer,
    this.deleteTextError,
    this.deleteText,
    this.selectCardText,
    this.savedCards,
    this.successUrl,
    this.cancelUrl}) {
  // ThawaniKeys k=ThawaniKeys();
  userApiKey = api;
  userClintID = clintID;
  userMetadata = metadata;
  userPKey = pKey;
  userProducts = products;
  isTestMode = testMode ?? false;
  userSuccessUrl = successUrl;
  userCancelUrl = cancelUrl;
  userSavedCardBackground = savedCardBackground ?? const Color(0xff0d0d10);
  userSavedCardTextColor = savedCardTextColor ?? const Color(0xffffffff);
  userSavedCardsAppBar = savedCardsAppBarText ?? const Text("Saved Cards");
  userDeleteLoading = deleteText ?? "Deleting...";
  userSelectCardLoading = selectCardText ?? "Loading...";
  userDeleteError = deleteTextError ?? "Error, Can't delete this card";
  userSaveCard = saveCard;

  ThawaniCustomers().checker(
    // customerID: customerID,
      customer: customerID,
      testMode: isTestMode,
      apiKey: api,
      customerId: clintID,
      // function to get the error
      onError: (error) {
        onError?.call(error);

      },
      // function to get the customer id
      onDone: (id, clint) {
        // function to get the customer id
        getSavedCustomer?.call(id);
        userCustomerID = id;
        if (saveCard) {
          // get the saved cards
          ThawaniCards().get(
            // customer id
              testMode: isTestMode,
              // api key
              customerId: id,

              apiKey: api,
              onError: (error) {
               onError?.call(error);
              },
              onDone: (data) {
                if (data.data!.isEmpty) {
                  payApi(
                      context: context,
                      api: api,
                      metadata: userMetadata,
                      publishKey: pKey,
                      clintID: clintID,
                      products: products,
                      onCreate: onCreate,
                      onCancelled: onCancelled,
                      onPaid: onPaid,
                      onError: onError,
                      customerID: id,
                      testMode: isTestMode);
                } else {
                  savedCards?.call(data.data!);

                  int totalAmount = 0;
// get the total amount of the products
                  for (var product in products) {
                    totalAmount +=
                        int.parse(product.unitAmount.toString()) *
                            product.quantity;
                  }
                  // show the saved cards screen
                  Navigator.push(
                      context,
                      MaterialPageRoute(
                          builder: (context) => SavedCardsScreen(
                                saved: data,
                                apiKey: api,
                                amount: totalAmount,
                                returnLink: successUrl ??
                                    'https://abom.me/package/thawani/suc.php',
                                testMode: isTestMode,
                                metadata: metadata,
                                onCancelledCard:
                                    (Map<String, dynamic> payStatus) {
                                  Navigator.pop(context);

                                  onCancelled(payStatus);
                                },
                                onPaidCard: (Map<String, dynamic> payStatus) {
                                  Navigator.pop(context);
                                  onPaid(payStatus);
                                },
                                onCreateCard: (Create data) {
                                  onCreate(data);
                                },
                              )));
                }
              });
        } else {
          // if the user don't want to save the card
          payApi(
              context: context,
              api: api,
              metadata: userMetadata,
              publishKey: pKey,
              clintID: clintID,
              products: products,
              onCreate: onCreate,
              onCancelled: onCancelled,
              onPaid: onPaid,
              onError: onError,
              customerID: id,
              testMode: isTestMode);
        }
      },
      newCustomer: (CreateCustomerModel userData) async {
        SharedPreferences share = await SharedPreferences.getInstance();
        share.setString("customerId", userData.data!.id!);
        if (userData.data != null) onCreateCustomer?.call(userData);
      });
}