I want to create a subscription page in flutter, with stripe. It works fine, beside I cannot transfer the customer_email to stripe.
That is my code, I added the parameter from the stripe api, as you can see below. But the program crashes…
The Stripe Api has this option.
@JS()
library stripe;
import 'package:flutter/material.dart';
import 'package:flutter_stripe_demo/constants.dart';
import 'package:js/js.dart';
void redirectToCheckout(BuildContext _) async {
final stripe = Stripe(apiKey);
stripe.redirectToCheckout(CheckoutOptions(
lineItems: [
LineItem(price: nikesPriceId, quantity: 1),
],
** customer_email: "test@gmail.com",**
mode: 'subscription',
successUrl: 'http://localhost:8080/#/success',
cancelUrl: 'http://localhost:8080/#/cancel',
));
}
@JS()
class Stripe {
external Stripe(String key);
external redirectToCheckout(CheckoutOptions options);
}
@JS()
@anonymous
class CheckoutOptions {
external List<LineItem> get lineItems;
external String get mode;
external String get successUrl;
external String get cancelUrl;
**external String get customer_email;**
external factory CheckoutOptions({
List<LineItem> lineItems,
String mode,
String successUrl,
String cancelUrl,
String sessionId,
** String customer_email,**
});
}
@JS()
@anonymous
class LineItem {
external String get price;
external int get quantity;
external factory LineItem({String price, int quantity});
}
Here is the error:
An Observatory debugger and profiler on Chrome is available at: http://127.0.0.1:51110/k2ADZWot2J4=
Flutter Web Bootstrap: Auto
The Flutter DevTools debugger and profiler on Chrome is available at: http://127.0.0.1:9104?uri=http://127.0.0.1:51110/k2ADZWot2J4=
You may test your Stripe.js integration over HTTP. However, live Stripe.js integrations must use HTTPS.
IntegrationError: Invalid stripe.redirectToCheckout parameter: customer_email is not an accepted parameter.
>Solution :
Using redirectToCheckout like this is deprecated and no longer something Stripe recommends, but for that pattern the parameter would be customerEmail:
https://stripe.com/docs/js/deprecated/redirect_to_checkout#stripe_checkout_redirect_to_checkout-options-customerEmail
Instead of creating the session like this, you should use your own back end to call the session create endpoint (API ref), and then redirect the customer to the session url (API ref), using either a server or client redirect.