I'm using stripe checkout in flutter via webview
along with some other plugins mentioned below. I have used the same code for another app and its totally working fine over there. While its showing this error in my current app:
{"error":{"message":"Invalid array","param":"payment_method_types","type":"invalid_request_error"}}
Parameters which I'm passing here in reference to Stripe checkout doc:
final body = {
'payment_method_types': ["card"],
'line_items': [
{
'name': "$serviceName",
'amount': price.round(),
"currency": "usd",
'quantity': 1,
}
],
'mode': 'payment',
'success_url': 'https://success.com/{CHECKOUT_SESSION_ID}',
'cancel_url': 'https://cancel.com/',
};
webview_flutter: ^2.0.8
dio: ^4.0.0
js: ^0.6.3
This code is basically returning a sessionId
which then I'm using further.
class StripeServer {
final String serviceName;
final int price;
StripeServer({this.serviceName, this.price});
Future<String> createCheckout() async {
final auth = "Basic " + base64Encode(utf8.encode(dotenv.env['secretKey']));
final body = {
'payment_method_types': ["card"],
'line_items': [
{
'name': "$serviceName",
'amount': price.round(),
"currency": "usd",
'quantity': 1,
}
],
'mode': 'payment',
'success_url': 'https://success.com/{CHECKOUT_SESSION_ID}',
'cancel_url': 'https://cancel.com/',
};
try {
final result = await Dio().post(
"https://api.stripe.com/v1/checkout/sessions",
data: body,
options: Options(
headers: {HttpHeaders.authorizationHeader: auth},
contentType: "application/x-www-form-urlencoded",
),
);
return result.data['id'];
} on DioError catch (e) {
print(e.response);
throw e;
}
}
}
Any help will be appreciated, in case you need more details please let me know I will update.
This is what worked for me.
final body = {
'payment_method_types[]': "card",
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With