簡體   English   中英

使用測試卡創建客戶時出錯

[英]Error when creating a customer using test card

嘗試為新創建的客戶開始訂閱時,我從Stripe收到以下錯誤:

invalid_request_error錯誤:此客戶沒有附加的付款來源

創建客戶似乎很好。 我正在使用Stripe Checkout來收集卡令牌。 為了進行測試,我使用Stripe的4242 4242 4242 4242卡號以及隨機信息。 令牌似乎正在創建並傳遞到我的服務器。 下面是我的服務器端代碼:

stripe.plans.retrieve(
    "basic-monthly",
    function(err, plan) {
        if (err) {
            console.error(err)
            res.sendStatus(500)
        } else {
            stripe.customers.create({
                email: owner,
                source: token.id,
            }, function(err, customer) {
                if (err) {
                    console.error(err)
                    res.sendStatus(500)
                  } else {
                    stripe.subscriptions.create({
                      customer: customer.id,
                      items: [
                        {
                          plan: "basic-monthly",
                          quantity: 1
                        },
                      ],
                    }, function(err, subscription) {
                      if (err) {
                        console.error(err)
                        console.log('@@@@@ UNABLE TO CREATE SUBSCRIPTION @@@@')
                        res.sendStatus(500)
                      } else {
                         console.log('Subscription created.')
                         console.dir(subscription)
                         res.sendStatus(200);
                      }     
                    });
                  }
                });
              }
            });

@@@@@ UNABLE TO CREATE SUBSCRIPTION @@@@ ,以及上述錯誤。 我了解錯誤的含義,但不確定如何發生。 如您在上方看到的,我在創建客戶時傳入令牌ID, source: token.id,

這是什么問題?

此處最可能的原因是token.id為空,因此創建的客戶沒有源。 我建議記錄token的內容,看看會得到什么。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM