使用Stripe在Flutter Web中!如何传递customer_email?

huangapple go评论66阅读模式
英文:

Using stripe in Flutter Web! How to transfer customer_email?

问题

这是你的代码片段,其中包含了问题所在的部分:

customer_email: "test@gmail.com",

问题出在 customer_email 参数上,Stripe 的 redirectToCheckout 方法不接受 customer_email 参数。这就是为什么你在运行程序时遇到了错误。

你需要使用不同的方法来将客户的电子邮件传递给 Stripe,可能是在创建订阅之前将客户的电子邮件关联到他们的 Stripe 账户中。

希望这能帮助你解决问题。如果你需要进一步的帮助,请提出具体的问题。

英文:

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.

答案1

得分: 0

使用以下方式的 redirectToCheckout 已经被弃用,不再是 Stripe 推荐的方法,但对于这种模式,参数应该是 customerEmail
https://stripe.com/docs/js/deprecated/redirect_to_checkout#stripe_checkout_redirect_to_checkout-options-customerEmail

不要再像这样创建会话,而是应该使用自己的后端调用会话创建端点(API 参考),然后重定向客户到会话的 urlAPI 参考),可以使用服务器或客户端重定向。

英文:

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.

huangapple
  • 本文由 发表于 2023年6月5日 23:19:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76407856.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定