【问题标题】:Stripe Payment 'client_reference_id'条纹支付'client_reference_id'
【发布时间】:2020-12-30 04:33:40
【问题描述】:

我正在与 Stripe 支付网关集成 - API 的最新版本。

除了“client_reference_id”没有传递给 webhook 或事务(没有出现在日志中)之外,这一切都在工作 - 我需要这个来更新数据库中的订单。

我的代码是:

$session = \Stripe\Checkout\Session::create([
            'billing_address_collection' => 'required',
            'payment_method_types' => ['card'],
            'line_items' => [[
                'amount' => 1011,
                'currency' => 'GBP',
                'name' => 'Purchase',
                'description' => 'test',
                'quantity' => 1,
            ]],
            'client_reference_id' => 'TEST1111223',
            'mode' => 'payment',
            'success_url' => 'https://example.com/success',
            'cancel_url' => 'https://example.com/cancel'
        ]);

根据文档,这应该通过:https://stripe.com/docs/api/checkout/sessions/create

我做错了吗?

其他人问了同样的问题但没有得到回答:The "client_reference_id" argument is not passed

【问题讨论】:

    标签: stripe-payments


    【解决方案1】:

    引用 Checkout 会话的唯一字符串。这可以是客户 ID、购物车 ID 或类似名称。它包含在 checkout.session.completed webhook 中,可用于完成购买。

    来源https://stripe.com/docs/js/checkout/redirect_to_checkout

    【讨论】:

      【解决方案2】:

      我做了一些挖掘,我想我知道发生了什么。您的客户端引用没问题,但您可能没有同时监听两个 webhook(例如,如果您使用的是 stripe connect,您将在两个 hook 上都收到可能具有欺骗性的事件)。

      我会为该客户参考使用真正唯一的 ID,这样您就不会有混合内容。这个 v4 功能非常有效。

      public static function v4() 
          {
              return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
      
              // 32 bits for "time_low"
              mt_rand(0, 0xffff), mt_rand(0, 0xffff),
      
              // 16 bits for "time_mid"
              mt_rand(0, 0xffff),
      
              // 16 bits for "time_hi_and_version",
              // four most significant bits holds version number 4
              mt_rand(0, 0x0fff) | 0x4000,
      
              // 16 bits, 8 bits for "clk_seq_hi_res",
              // 8 bits for "clk_seq_low",
              // two most significant bits holds zero and one for variant DCE1.1
              mt_rand(0, 0x3fff) | 0x8000,
      
              // 48 bits for "node"
              mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
              );
          }
      

      【讨论】:

        【解决方案3】:

        customer.created 事件具有client_reference_id 是有意义的。然而事实并非如此!它确实出现在 checkout.session.completed 事件中。

        以下是对象详细信息

        Stripe\Event Object
        (
            [id] => evt_1KCO7....dffL4wc0
            [object] => event
            [api_version] => 2020-08-27
            [created] => 1640868753
            [data] => Stripe\StripeObject Object
                (
                    [object] => Stripe\Checkout\Session Object
                        (
                            [id] => cs_test_a1A....NhSTmvD
                            [object] => checkout.session
                            [after_expiration] => 
                            [allow_promotion_codes] => 
                            [amount_subtotal] => 15000
                            [amount_total] => 15000
                            [automatic_tax] => Stripe\StripeObject Object
                                (
                                    [enabled] => 
                                    [status] => 
                                )
        
                            [billing_address_collection] => 
                            [cancel_url] => http://example.org/cancel
                            [client_reference_id] => 3181234
                            [consent] => 
                            [consent_collection] => 
                            [currency] => usd
                            [customer] => cus_Ks8...bT
                            [customer_details] => Stripe\StripeObject Object
                                (
                                    [email] => user@exmaple.org
                                    [phone] => 
                                    [tax_exempt] => none
                                    [tax_ids] => Array
                                        (
                                        )
        
                                )
        
                            [customer_email] => user@exmaple.org
                            [expires_at] => 1640955127
                            [livemode] => 
                            [locale] => 
                            [metadata] => Stripe\StripeObject Object
                                (
                                )
        
                            [mode] => payment
                            [payment_intent] => pi_3K...1p2sJ
                            [payment_method_options] => Array
                                (
                                )
        
                            [payment_method_types] => Array
                                (
                                    [0] => card
                                )
        
                            [payment_status] => paid
                            [phone_number_collection] => Stripe\StripeObject Object
                                (
                                    [enabled] => 
                                )
        
                            [recovered_from] => 
                            [setup_intent] => 
                            [shipping] => 
                            [shipping_address_collection] => 
                            [shipping_options] => Array
                                (
                                )
        
                            [shipping_rate] => 
                            [status] => complete
                            [submit_type] => 
                            [subscription] => 
                            [success_url] => http://exmaple.org/success
                            [total_details] => Stripe\StripeObject Object
                                (
                                    [amount_discount] => 0
                                    [amount_shipping] => 0
                                    [amount_tax] => 0
                                )
        
                            [url] => 
                        )
        
                )
        
            [livemode] => 
            [pending_webhooks] => 2
            [request] => Stripe\StripeObject Object
                (
                    [id] => 
                    [idempotency_key] => 
                )
        
            [type] => checkout.session.completed
        )
        

        在customer.created 中,如果您在结帐时通过了email,您确实会得到客户email。您也可以使用它将其连接回您的客户,而无需 client_reference_id。我签入这两个事件,并在第一次成功时使用条带客户 ID 更新数据库。

        【讨论】:

          猜你喜欢
          • 2017-09-14
          • 2021-08-02
          • 2021-11-19
          • 2021-10-08
          • 2016-08-02
          • 2020-03-06
          • 2018-08-20
          • 2018-07-13
          • 2016-10-22
          相关资源
          最近更新 更多