Thawani.pay constructor
Thawani.pay(
- BuildContext context, {
- required String api,
- required List<
Product> products, - required void onCreate(
- Create create
- required void onCancelled(),
- required void onPaid(),
- Widget? child,
- int? expiredInMinuets,
- required String pKey,
- required Map<
String, dynamic> metadata, - required String clintID,
- ButtonStyle? buttonStyle,
- bool? testMode,
- String? customerID,
- required bool saveCard,
- void onError(
- Map error
- void onCreateCustomer(
- CreateCustomerModel data
- Color? savedCardBackground,
- Color? savedCardTextColor,
- Widget? savedCardsAppBarText,
- void getSavedCustomer(
- String data
- String? deleteTextError,
- String? deleteText,
- String? selectCardText,
- void savedCards()?,
- String? successUrl,
- 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);
});
}