2017-09-28 67 views
0

當試圖開始認購新創建的客戶創建一個客戶時,我收到以下錯誤,從條紋:錯誤使用測試卡

invalid_request_error Error: This customer has no attached payment source

客戶似乎要創建就好了。我正在使用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,

問題是什麼嗎?

回答

1

最有可能在這裏的原因是token.id是空的,所以被無源創建的客戶。我建議記錄token的內容,看看你得到了什麼。

+0

'token.id'不是空的,並且包含客戶結帳流程通過令牌ID。 – Orbit

+0

我錯了,我想'token.id'是,當我在我的路線的開始打印,其打印到控制檯預期就好了。我只是增加了一個日誌語句直接調用上面'stripe.customers.create()',它實際上是在某種程度上'undefined'。這怎麼可能?它是完全相同的變量,並且不會在我的路線中的任何地方進行修改。 – Orbit

+0

所以原來的令牌正在變成通過'JSON.stringify()'在客戶端上的字符串。它將所有內容打印到控制檯,但自然'token.id'返回undefined。我很感激幫助。 – Orbit