Google pay button not showing in flutter_stripe package payment sheet - flutter

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');
}
}

Related

How can I get token from stripe payment flutter?

I'm doing stripe payment method very first time and the Api developer told me to give him token for stripe payment. I've seen tutorial about but couldn't find about token from anywhere. I also have implemented it and success the payment but how to find token now. I need help.
Thanks
Here is how I was trying to do but getting error
Future<void> makePayment() async {
try {
paymentIntent = await createPaymentIntent("20", "USD");
if (paymentIntent == null) {
// handle the error
print("Error creating payment intent");
return;
}
await Stripe.instance
.initPaymentSheet(
paymentSheetParameters: SetupPaymentSheetParameters(
paymentIntentClientSecret: paymentIntent?['client_secret'],
// applePay: PaymentSheetApplePay(merchantCountryCode: "+971"),
// googlePay: PaymentSheetGooglePay(testEnv: true, currencyCode: "AE"),
style: ThemeMode.dark,
merchantDisplayName: "Marketingo"))
.then((value) {});
displayPaymentSheet();
var tokenData = await Stripe.instance.createToken(params);
if (tokenData.tokenId != null) {
var token = tokenData.tokenId;
// Use the token to complete the payment on your server.
}
} catch (e) {
print("exception $e");
}
}

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.

Flutter_stripe default payment sheet inside Google pay option is not showing

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();

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