Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using stripe in Flutter Web! How to transfer customer_email?

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

@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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading