10/25/1
This commit is contained in:
@@ -33,6 +33,25 @@ class CRUD {
|
||||
}
|
||||
}
|
||||
|
||||
Future<dynamic> postStripe({
|
||||
required String link,
|
||||
Map<String, dynamic>? payload,
|
||||
}) async {
|
||||
var url = Uri.parse(
|
||||
link,
|
||||
);
|
||||
var response = await http.post(
|
||||
url,
|
||||
body: payload,
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
'Authorization': 'Bearer ${StripeKey.secretKey}',
|
||||
},
|
||||
);
|
||||
|
||||
return response.body;
|
||||
}
|
||||
|
||||
Future<dynamic> post({
|
||||
required String link,
|
||||
Map<String, dynamic>? payload,
|
||||
|
||||
@@ -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();
|
||||
|
||||
0
lib/controller/payment/stripe.dart
Normal file
0
lib/controller/payment/stripe.dart
Normal file
Reference in New Issue
Block a user