You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter集成Stripe:如何预设Apple Pay的customer_email自定义Webhook返回邮箱

解决Stripe托管支付页面Apple Pay支付时Webhook邮箱自定义问题

方法一:关联固定Customer对象(推荐)

创建Checkout Session前先创建Stripe Customer并指定自定义邮箱,后续支付流程绑定该Customer后,Apple Pay不会覆盖邮箱字段:

  • 服务器端调用Stripe API创建Customer,传入目标邮箱:
    # Python后端示例代码
    customer = stripe.Customer.create(
      email="your_target_user_email@example.com"
    )
    
  • 创建Checkout Session时,将customer字段设置为上述Customer的ID:
    session = stripe.checkout.Session.create(
      payment_method_types=["card", "apple_pay"],
      line_items=[...],
      mode="payment",
      customer=customer.id,  # 绑定已创建的Customer
      success_url="...",
      cancel_url="..."
    )
    
  • 此时Webhook的checkout.session.completed事件中,customer_email会直接使用Customer对象的邮箱,不受Apple Pay账户邮箱影响。

方法二:通过Metadata存储自定义邮箱

若无需创建Customer,可在Checkout Session的Payment Intent元数据中存入自定义邮箱,Webhook处理时优先读取该字段:

  • 创建Checkout Session时,在payment_intent_data.metadata中添加自定义邮箱字段:
    session = stripe.checkout.Session.create(
      payment_method_types=["card", "apple_pay"],
      line_items=[...],
      mode="payment",
      customer_email="pre_filled_email@example.com",  # 预填邮箱可能被Apple Pay覆盖
      payment_intent_data={
        "metadata": {
          "custom_customer_email": "your_target_user_email@example.com"
        }
      },
      success_url="...",
      cancel_url="..."
    )
    
  • 在Webhook处理逻辑中,忽略customer_email,直接读取Metadata中的自定义值:
    # Webhook处理示例
    event = stripe.Webhook.construct_event(
      payload, sig_header, endpoint_secret
    )
    if event["type"] == "checkout.session.completed":
      session = event["data"]["object"]
      # 获取自定义邮箱
      custom_email = session["payment_intent"]["metadata"]["custom_customer_email"]
      # 后续业务逻辑使用custom_email
    

关键说明

  • Stripe默认行为:未关联已有Customer时,Apple Pay支付会用账户联系信息填充customer_email;绑定Customer后会优先使用Customer的邮箱。
  • 自定义邮箱必须在服务器端传入,避免客户端篡改风险。

内容的提问来源于stack exchange,提问作者Arshpreet Singh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 08:42:07