10/25/2
This commit is contained in:
@@ -79,19 +79,23 @@ class PaymentController extends GetxController {
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> makePayment(int amount, String currency) async {
|
||||
late String clientSecret;
|
||||
|
||||
Future<void> makePayment(int amount, String currency, Function method) async {
|
||||
var newAmount = amount * 100;
|
||||
|
||||
try {
|
||||
String clientSecret =
|
||||
await _getClientSecret((amount).toString(), currency);
|
||||
clientSecret = await getClientSecret(newAmount.toString(), currency);
|
||||
await initializePaymentSheet(clientSecret);
|
||||
await Stripe.instance.presentPaymentSheet();
|
||||
method();
|
||||
} catch (e) {
|
||||
throw Exception(e.toString());
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> initializePaymentSheet(String clientSecret) async {
|
||||
Stripe.instance.initPaymentSheet(
|
||||
await Stripe.instance.initPaymentSheet(
|
||||
paymentSheetParameters: SetupPaymentSheetParameters(
|
||||
paymentIntentClientSecret: clientSecret,
|
||||
merchantDisplayName: 'Sefer',
|
||||
@@ -99,13 +103,23 @@ class PaymentController extends GetxController {
|
||||
);
|
||||
}
|
||||
|
||||
Future<String> _getClientSecret(String amount, currency) async {
|
||||
Future<String> getClientSecret(String amount, currency) async {
|
||||
var res = await CRUD().postStripe(
|
||||
link: 'https://api.stripe.com/v1/payment_intents',
|
||||
payload: {'amount': amount, 'currency': currency},
|
||||
);
|
||||
|
||||
// Convert the res object to a JSON object
|
||||
final jsonResponse = jsonDecode(res);
|
||||
return jsonResponse['client_secret'];
|
||||
print(jsonResponse);
|
||||
// Check if the client_secret property exists and is not null
|
||||
if (jsonResponse.containsKey('client_secret') &&
|
||||
jsonResponse['client_secret'] != null) {
|
||||
// Return the client_secret property
|
||||
return jsonResponse['client_secret'] as String;
|
||||
} else {
|
||||
throw Exception('Failed to fetch client secret');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -195,7 +195,11 @@ class HomeCaptain extends StatelessWidget {
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
PaymentController().makePayment(18, 'JOD');
|
||||
PaymentController().makePayment(
|
||||
14,
|
||||
'USD',
|
||||
() => Get.snackbar('Yes you pay success', '',
|
||||
backgroundColor: Colors.greenAccent));
|
||||
},
|
||||
child: const Text(
|
||||
"Pay 18 dollar",
|
||||
|
||||
@@ -84,7 +84,7 @@ class PassengerWallet extends StatelessWidget {
|
||||
height: 10,
|
||||
),
|
||||
GetBuilder<CreditCardController>(
|
||||
builder: (reditCardControllerc) => Row(
|
||||
builder: (creditCardController) => Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
MyElevatedButton(
|
||||
@@ -94,19 +94,19 @@ class PassengerWallet extends StatelessWidget {
|
||||
.validate()) {
|
||||
SecureStorage().saveData(
|
||||
BoxName.cardNumber,
|
||||
reditCardControllerc
|
||||
creditCardController
|
||||
.cardNumberController.text);
|
||||
SecureStorage().saveData(
|
||||
BoxName.cardHolderName,
|
||||
reditCardControllerc
|
||||
creditCardController
|
||||
.cardHolderNameController.text);
|
||||
SecureStorage().saveData(
|
||||
BoxName.cvvCode,
|
||||
reditCardControllerc
|
||||
creditCardController
|
||||
.cvvCodeController.text);
|
||||
SecureStorage().saveData(
|
||||
BoxName.expiryDate,
|
||||
reditCardControllerc
|
||||
creditCardController
|
||||
.expiryDateController.text);
|
||||
}
|
||||
},
|
||||
@@ -423,73 +423,15 @@ class PassengerWallet extends StatelessWidget {
|
||||
'You will choose one of above !'.tr,
|
||||
AppColor.redColor);
|
||||
}
|
||||
// controller.changePromoSheetDialogue();
|
||||
// Get.to(() {
|
||||
// UsePaypal(
|
||||
// sandboxMode: true,
|
||||
// clientId:
|
||||
// "AXE7bR3WzFEfAInUA2PBDOsW4zolx11Qr3jVOOjjJ7KGDLY3tnMIhZgyFT5Qkvj1NKWPaE8VZbG4UrZs",
|
||||
// secretKey:
|
||||
// "EJPW01FKqOm-SKKP16LQ_2cr3b124aZgmE0vi3JfbkWgLffv2xIjT4iCIfQv8RYn3W8h4DzxgZu_UxZC",
|
||||
// returnURL:
|
||||
// "https://samplesite.com/return",
|
||||
// cancelURL:
|
||||
// "https://samplesite.com/cancel",
|
||||
// transactions: const [
|
||||
// {
|
||||
// "amount": {
|
||||
// "total": '10.12',
|
||||
// "currency": "USD",
|
||||
// "details": {
|
||||
// "subtotal": '10.12',
|
||||
// "shipping": '0',
|
||||
// "shipping_discount": 0
|
||||
// }
|
||||
// },
|
||||
// "description":
|
||||
// "The payment transaction description.",
|
||||
// // "payment_options": {
|
||||
// // "allowed_payment_method":
|
||||
// // "INSTANT_FUNDING_SOURCE"
|
||||
// // },
|
||||
// "item_list": {
|
||||
// "items": [
|
||||
// {
|
||||
// "name": "A demo product",
|
||||
// "quantity": 1,
|
||||
// "price": '10.12',
|
||||
// "currency": "USD"
|
||||
// }
|
||||
// ],
|
||||
|
||||
// // shipping address is not required though
|
||||
// "shipping_address": {
|
||||
// "recipient_name": "Jane Foster",
|
||||
// "line1": "Travis County",
|
||||
// "line2": "",
|
||||
// "city": "Austin",
|
||||
// "country_code": "US",
|
||||
// "postal_code": "73301",
|
||||
// "phone": "+00000000",
|
||||
// "state": "Texas"
|
||||
// },
|
||||
// }
|
||||
// }
|
||||
// ],
|
||||
// note:
|
||||
// "Contact us for any questions on your order.",
|
||||
// onSuccess: (Map params) async {
|
||||
// print("onSuccess: $params");
|
||||
// },
|
||||
// onError: (error) {
|
||||
// print("onError: $error");
|
||||
// },
|
||||
// onCancel: (params) {
|
||||
// print('cancelled: $params');
|
||||
// });
|
||||
// });
|
||||
},
|
||||
),
|
||||
MyElevatedButton(
|
||||
title: 'Pay with Credit Card'.tr,
|
||||
onPressed: () => controller.makePayment(
|
||||
controller.selectedAmount as int,
|
||||
'JOD',
|
||||
() => Get.snackbar('Hi', '')),
|
||||
),
|
||||
MyElevatedButton(
|
||||
title: 'Cancel'.tr,
|
||||
kolor: AppColor.redColor,
|
||||
|
||||
Reference in New Issue
Block a user