【问题标题】:Stripe Payments Linking my own database table to a customer ID on StripeStripe Payments 将我自己的数据库表链接到 Stripe 上的客户 ID
【发布时间】:2019-12-23 15:53:44
【问题描述】:

我希望有人可以在这里帮助我。

我正在尝试通过条带处理订阅付款

<script>
    var stripe = Stripe('pk_test_CJ3p2EuKzHOC0mQrx9AIDZ3R00TR4ysmyS');

    document.getElementById("checkout-button").addEventListener('click', function () {
      stripe.redirectToCheckout({
        items: [{
          // Define the product and plan in the Dashboard first, and use the plan
          // ID in your client-side code.
          plan: 'plan_Fd6dQD8JT0sl0C',
          quantity: 1,

        }],
        successUrl: 'https://www.example.com/success',
        cancelUrl: 'https://www.example.com/cancel'
      });
    });
</script>

然后,我设置了一个 webhook,以便在完成后进行一些处理:

<?php
require_once('vendor/autoload.php');

Stripe\Stripe::setApiKey("TEST KEY");
// retrieve the request's body and parse it as JSON
$body = @file_get_contents('php://input');
$event_json = json_decode($body);
// for extra security, retrieve from the Stripe API
$event_id = $event_json->id;
$event = \Stripe\Event::retrieve($event_id);
// This will send receipts on succesful invoices


if ($event->type == 'invoice.payment_succeeded') {
    include 'email_template_functions/email_function.php';
    include 'email_template_functions/password_reset_email_templatetest.php';

    sendemail('triggertraders.com','richard@triggertraders.com','Bluebanana1995',465,'richard@triggertraders.com', 'Richard','rglass5565@gmail.com','richard@triggertraders.com',
    'Information','Reset Password Trigger Trader','This has worked!!','This is the body in plain text for non-HTML mail clients');
}

所以这很好用,并且付款正在进行中,这是我想知道的下一步。

我的数据库中有一个实体表,其中包含所有具有 entity_id 的“客户”数据。我正在尝试找出一种方法将条带 customer_id 链接到我本地数据库中的 entity_id,以便在付款时更新他们的帐户,但我不知道该怎么做。

有没有什么方法可以在设置付款时发送我自己的 entity_id 进行条带化,这样当我从 webhook 检索该数据并可以正确更新我的数据库时?

【问题讨论】:

    标签: php stripe-payments webhooks


    【解决方案1】:

    我发现这个https://stripe.com/docs/stripe-js/reference#stripe-redirect-to-checkout 引用了clientReferenceId,我可以使用它来存储我需要的ID。

    <script>
        var stripe = Stripe('pk_test_CJ3p2EuKzHOC0mQrx9AIDZ3R00TR4ysmyS');
    
        document.getElementById("checkout-button").addEventListener('click', function () {
          stripe.redirectToCheckout({
            items: [{
              // Define the product and plan in the Dashboard first, and use the plan
              // ID in your client-side code.
              plan: 'plan_Fd6dQD8JT0sl0C',
              quantity: 1,
    
    
    
            }],
            clientReferenceId: '123',
            successUrl: 'https://www.example.com/success',
            cancelUrl: 'https://www.example.com/cancel'
          });
        });
    </script>
    

    然后我可以在我的 webhook 中使用它 - 有人知道其他方法吗?

    【讨论】:

      猜你喜欢
      • 2017-04-20
      • 2015-11-28
      • 1970-01-01
      • 2020-02-24
      • 2021-12-27
      • 2017-03-13
      • 2021-06-07
      • 2020-07-30
      • 1970-01-01
      相关资源
      最近更新 更多