Flutter_stripe default payment sheet inside Google pay option is not showing - flutter

I have used flutter_stripe SDK 5.0.0 and and I am trying to implement google pay functionality in default sheet. also I have enable google pay option inside SetupPaymentSheetParameters
final googlePaySupported = await Stripe.instance.isGooglePaySupported(IsGooglePaySupportedParams());
This is return True value.
await Stripe.instance
.initPaymentSheet(
paymentSheetParameters: SetupPaymentSheetParameters(
// Main params
paymentIntentClientSecret:
apiPaymentResponse.data!.data!.paymentIntent,
merchantDisplayName: 'My Store ',
// Customer params
customerId: apiPaymentResponse.data!.data!.customer,
customerEphemeralKeySecret:
apiPaymentResponse.data!.data!.ephemeralKey,
// Extra params
applePay: const PaymentSheetApplePay(
merchantCountryCode: 'DE',
),
googlePay: const PaymentSheetGooglePay(
merchantCountryCode: 'US', testEnv: true, currencyCode: "DE"),
style: ThemeMode.system,
billingDetails: billingDetails,
),
)
.then((value) async {
loaderClose();
confirmPayment(
context: context,
state: state,
);
});
await Stripe.instance.presentPaymentSheet();

Related

How to make the Stripe payment sheet for iOS in Flutter barrierDismissible: false?

I am using Stripe for iOS in my Flutter app and I want to disable the ability for the user to dismiss the payment sheet by tapping outside of it. Currently, when the user taps outside of the payment sheet, I am receiving an error from Stripe. I know that the barrierDismissible option is not available for the presentPaymentSheet() method, but I am wondering if there is some other way to enable this behavior for the payment sheet.
Here is my code demonstrating how I am currently displaying the payment sheet:
Future<void> makePayment(String amount, String currency) async {
try {
paymentIntentData = await createPaymentIntent(amount, currency);
if (paymentIntentData != null) {
await Stripe.instance.initPaymentSheet(
paymentSheetParameters: SetupPaymentSheetParameters(
billingDetails: BillingDetails(
name: _nameController.text,
phone: _phoneController.text,
email: _emailController.text,
),
allowsDelayedPaymentMethods: false,
customerEphemeralKeySecret: paymentIntentData!['ephemeralkey'],
paymentIntentClientSecret: paymentIntentData!['client_secret'],
customerId: paymentIntentData!['customer'],
style: ThemeMode.dark,
merchantDisplayName: 'company',
),
);
}
//Payment Sheet
///now finally display payment sheet
displayPaymentSheet();
//displayPaymentSheet();
} catch (e, s) {
print('ERROR exception:$e$s');
}
}
displayPaymentSheet() async {
try {
await Stripe.instance.presentPaymentSheet().then((value) async {
// Code to handle the result of the payment
}).onError((error, stackTrace) {
print('Error is:--->$error $stackTrace');
});
} on StripeException catch (e) {
print('StripeException Error is:---> $e');
showDialog(
context: context,
builder: (_) => const AlertDialog(
content: Text("Cancelled "),
));
} catch (e) {
print('$e');
}
}
Is there any way to make the payment sheet barrierDismissible: false using the presentPaymentSheet() method or some other method in Stripe for iOS in Flutter?
The flutter_stripe package does provide native integration of the Stripe payment sheet within your Flutter app, it is not a flutter's bottom sheet widget, so you can't actually control and make such as change like this to the presentPaymentSheet() bottom sheet.
Also other Stripe's CardField() and CardFormField() are technically native platform-specific views integrated inside the flutter app.

Google pay button not showing in flutter_stripe package payment sheet

I used flutter_stripe: ^3.3.0 to implement stripe payment, everything goes well but I can't see google pay button on top of stripe payment sheet. I have enable google pay according to https://docs.page/flutter-stripe/flutter_stripe/sheet. and below is what i am getting.
Future<void> makePayment(
{String amount,String currency}) async {
try {
paymentIntentData = await createPaymentIntent(amount, currency);
if (paymentIntentData != null) {
await Stripe.instance.initPaymentSheet(
paymentSheetParameters: SetupPaymentSheetParameters(
applePay: true,
googlePay: true,
testEnv: true,
merchantCountryCode: 'US',
merchantDisplayName: 'Prospects',
customerId: paymentIntentData['customer'],
paymentIntentClientSecret: paymentIntentData['client_secret'],
customerEphemeralKeySecret: paymentIntentData['ephemeralKey'],
));
displayPaymentSheet();
}
} catch (e, s) {
print('exception:$e$s');
}
}

'PresentPaymentSheetParameters' is deprecated and shouldn't be used. Parameters are now inherited from initPaymentSheet

I am integrating Stripe Payment Gateway into my e-commerce application. I am new to stripe payment gateway, I am facing a depreciation error which is as
'parameters' is deprecated and shouldn't be used. Params are now inherited from initPaymentSheet so this 'parameters' can be removed.
The current stripe plugin I am using is flutter_stripe: ^3.3.0. Just want to know how to fix this depreciation issue. Attaching the error screenshot also
CODE IS AS :
displayPaymentSheet(OrderProvider orderProvider) async {
try {
await Stripe.instance
.presentPaymentSheet(
parameters: PresentPaymentSheetParameters(
clientSecret: paymentIntentData!['client_secret'],
confirmPayment: true,
))
.then((newValue) {
print('payment intent ${paymentIntentData!['id']}');
print('payment intent ${paymentIntentData!['client_secret']}');
print('payment intent ${paymentIntentData!['amount']}');
print('payment intent $paymentIntentData');
//orderPlaceApi(paymentIntentData!['id'].toString());
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: const Text("Paid successfully")));
orderProvider.success = true;
Navigator.pop(context);
setState(() {
paymentIntentData = null;
});
}).onError((error, stackTrace) {
print('Exception/DISPLAYPAYMENTSHEET==> $error $stackTrace');
});
} on StripeException catch (e) {
print('Exception/DISPLAYPAYMENTSHEET==> $e');
showDialog(
context: context,
builder: (_) => AlertDialog(
content: Text("Cancelled "),
));
} catch (e) {
print('$e');
}
}
Try using initPaymentSheet.
await Stripe.instance
.initPaymentSheet(
paymentSheetParameters: SetupPaymentSheetParameters(
paymentIntentClientSecret: "",
),
)

Flutter web Stripe Error: WebUnsupportedError: initPaymentSheet is not supported for Web

I am trying to implement Stripe inside my application, but I do get this error.
The error I get is Error: WebUnsupportedError:
initPaymentSheet is not supported for Web i don't know how to make it work on the web.
WidgetsFlutterBinding.ensureInitialized();
Get.put(MenuController());
Get.put(NavigationController());
await initialization;
Stripe.publishableKey =
'pk_test_5555851KuZKPKYrgcm5L1......';
Stripe.merchantIdentifier = 'merchant.flutter.stripe.test';
Stripe.urlScheme = 'flutterstripe';
await Stripe.instance.applySettings();
runApp((MultiProvider(
providers: [
ChangeNotifierProvider(
create: (context) => ApplicationState(),
builder: (context, _) => MyApp(),
)
],
// child: MyApp(),
)));
}
Future<void> makePayment(String amount, String currency) async {
try {
paymentIntentData = await createPaymentIntent(amount, currency);
await Stripe.instance.initPaymentSheet(
paymentSheetParameters: SetupPaymentSheetParameters(
paymentIntentClientSecret: paymentIntentData!['client_secret'],
applePay: true,
googlePay: true,
merchantCountryCode: 'US',
merchantDisplayName: 'KasaiMart'));
displayPaymentSheet();
} on StripeException catch (e) {
print('Exeption ${e.toString()}');
}
}
displayPaymentSheet() async {
try {
await Stripe.instance.presentPaymentSheet();
paymentIntentData = null;
Get.defaultDialog(
title: 'Select project to contribute to',
middleText: 'Paid Sucessfully');
} catch (e) {
print('Exeption ${e.toString()}');
}
}
createPaymentIntent(String amount, String currency) async {
try {
Map<String, dynamic> body = {
'amount': calculateAmount(amount),
'currency': currency,
'payment_method_types[]': 'card'
};
var response = await http.post(
Uri.parse('https://api.stripe.com/v1/payment_intents'),
body: body,
headers: {
'Authorization':
'pk_test_51K......',
'Content-Type': 'application/x-www-form-urlencoded'
});
return jsonDecode(response.body.toString());
} catch (e) {
print('Exeption ${e.toString()}');
}
}
I am struggling to display the initPaymentSheet?
In which method am I doing something wrong? is it possible to fix this issue or is it from package itself?
Stripe for Web is still highly experimental. From the README on Github: Notice right now it is highly experimental and only a subset of features is implemented.
You can also check in the stripe_web plugin repository that the initPaymentSheet is still not implemented. It throws a WebUnsupportedError right away. Also, check the other unsupported methods in the same place.
initPaymentSheet doesn't work on the web. Stripe's React Native SDK is exclusive to iOS/Android.
If you want to present something similar to the Payment Sheet via the web, you might consider using the Payment Element instead: https://stripe.com/docs/payments/payment-element

Stripe wont intialize paymentsheet

I am trying to implement Stripe to my flutter app, but i am running in to this issue:
StripeException(error: LocalizedErrorMessage(code: FailureCode.Failed, localizedMessage: No payment sheet has been initialized yet, message: No payment sheet has been initialized yet, stripeErrorCode: null, declineCode: null, type: null))
My current code is:
Future<void> makePayment() async {
final response = await http.post(
Uri.parse(
api_string,
),
headers: {"Content-Type": "application/json; charset=utf-8"},
body: json.encode({"Amount": "250"}),
);
var data = json.decode(response.body);
await Stripe.instance.initPaymentSheet(
paymentSheetParameters: SetupPaymentSheetParameters(
paymentIntentClientSecret: data['clientSecret'],
merchantDisplayName: 'Flutter test app',
applePay: true,
googlePay: true,
style: ThemeMode.dark,
testEnv: true,
merchantCountryCode: 'DK',
),
);
setState(() {});
await displayPaymentSheet();
}
Future<void> displayPaymentSheet() async {
try {
await Stripe.instance.presentPaymentSheet();
} catch (e) {
print(e);
}
}
I have checked the official flutter_stripe documentation, but the example with my API changed gives the same error, and my api return "clientSecret": Secret}
As stated in the comment, the fix was to add a merchantId to the Stripe initialization