【问题标题】:Store metadata in a subscription with Stripe使用 Stripe 将元数据存储在订阅中
【发布时间】:2020-10-19 21:49:06
【问题描述】:

我正在尝试弄清楚如何将元数据直接存储到 Stripe CC 支付订阅中。我正在使用 PHP SDK 并且拥有:

  $test = $stripe->checkout->sessions->create([
      'customer_email' => $_GET["who"],
      'success_url' => $success_url,
      'payment_method_types' => ['card'],
      'cancel_url' => "https://www.example.com",
      'line_items' => [
        [
          'price' => $price_plan_id,
          'quantity' => 1,
        ],
      ],
      'payment_intent_data' => [
        'metadata' => [
            'who' => $_GET["who"],
            'total' => $_GET["total"],
            'period' => $_GET["period"],
            'description' => $_GET["description"],
            'district' => $_GET["district"],
            'what' => $_GET["what"],
            'ip' => $_SERVER["REMOTE_ADDR"]
        ]
      ],
      'mode' => $mode 'subscription',
    ]);

这给了我一个错误:

你不能在subscription模式下通过payment_intent_data

我已经尝试过:

  $test = $stripe->checkout->sessions->create([
      'customer_email' => $_GET["who"],
      'success_url' => $success_url,
      'payment_method_types' => ['card'],
      'cancel_url' => "https://www.example.com",
      'line_items' => [
        [
          'price' => $price_plan_id,
          'quantity' => 1,
        ],
      ],
      'metadata' => [
          'who' => $_GET["who"],
          'total' => $_GET["total"],
          'period' => $_GET["period"],
          'description' => $_GET["description"],
          'district' => $_GET["district"],
          'what' => $_GET["what"],
          'ip' => $_SERVER["REMOTE_ADDR"]
      ],
      'mode' => $mode 'subscription',
    ]);

虽然它有点工作,但它没有分配给订阅(当你查看它时,元数据是空的)

我该如何传递这个?我想将此数据保存在订阅元素中(不仅仅是付款)

谢谢

【问题讨论】:

    标签: stripe-payments


    【解决方案1】:

    您希望通过将元数据设置为subscription_data.metadata 将元数据传递给生成的订阅对象:https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-subscription_data-metadata

    【讨论】:

    • 天哪,这就是我如此喜欢的原因!在过去的几天里,我一直在绕圈子。希望我直接来这里!这就像一个魅力!
    • 很高兴有帮助!您也可以通过irc.lc/freenode/stripe 直接向 Stripe 的工程师询问类似这样的 API 问题,以供将来参考。
    猜你喜欢
    • 2017-04-02
    • 2017-10-02
    • 2021-03-28
    • 1970-01-01
    • 2012-11-11
    • 2021-02-22
    • 2017-07-03
    • 2017-12-27
    • 2021-07-15
    相关资源
    最近更新 更多