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
|
||||
|
||||
Reference in New Issue
Block a user