10/25/1
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_stripe/flutter_stripe.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:ride/constant/credential.dart';
|
||||
import 'package:ride/controller/home/map_passenger_controller.dart';
|
||||
|
||||
import '../../constant/box_name.dart';
|
||||
@@ -58,7 +60,7 @@ class PaymentController extends GetxController {
|
||||
update();
|
||||
}
|
||||
|
||||
void applyPromoCodetoPassenger() async {
|
||||
void applyPromoCodeToPassenger() async {
|
||||
//TAWJIHI
|
||||
CRUD().get(link: AppLink.getPassengersPromo, payload: {
|
||||
'promo_code': promo.text,
|
||||
@@ -77,6 +79,35 @@ class PaymentController extends GetxController {
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> makePayment(int amount, String currency) async {
|
||||
try {
|
||||
String clientSecret =
|
||||
await _getClientSecret((amount).toString(), currency);
|
||||
await initializePaymentSheet(clientSecret);
|
||||
await Stripe.instance.presentPaymentSheet();
|
||||
} catch (e) {
|
||||
throw Exception(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> initializePaymentSheet(String clientSecret) async {
|
||||
Stripe.instance.initPaymentSheet(
|
||||
paymentSheetParameters: SetupPaymentSheetParameters(
|
||||
paymentIntentClientSecret: clientSecret,
|
||||
merchantDisplayName: 'Sefer',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
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},
|
||||
);
|
||||
final jsonResponse = jsonDecode(res);
|
||||
return jsonResponse['client_secret'];
|
||||
}
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
getPassengerWallet();
|
||||
|
||||
Reference in New Issue
Block a user