2014-02-12 71 views
2

我正嘗試使用解析創建條帶客戶,但似乎無法從響應中獲取customer.id值。使用解析創建條帶客戶

var newCustomer; 

Stripe.Customers.create(


    card: request.params.cardToken, 
    email: request.params.email 
    //These values are a success but below is where I have an issue. 

).then(function(customer){ 

    newCustomer = customer.id; 
    //newCustomer never gets set to the id, it's always undefined. 

}, function(error){ 


}); 
+0

您使用的解析雲代碼鍵? – james075

回答

6

以下是使用解析條帶模塊api解析雲代碼的新客戶的一種方法。

解析參考:http://parse.com/docs/js/symbols/Stripe.Customers.html

,應確保已存儲在發佈API

var Stripe = require('stripe'); 

Stripe.initialize('sk_test_***************'); 

Parse.Cloud.define("createCustomer", function(request, response) {  
    Stripe.Customers.create({ 
     account_balance: 0, 
     email: request.params.email, 
     description: 'new stripe user', 
     metadata: { 
      name: request.params.name, 
      userId: request.params.objectId, // e.g PFUser object ID 
      createWithCard: false 
     } 
    }, { 
     success: function(httpResponse) { 
      response.success(customerId); // return customerId 
     }, 
     error: function(httpResponse) { 
      console.log(httpResponse); 
      response.error("Cannot create a new customer."); 
     } 
    }); 
}); 
+0

謝謝你的信息,這工作。 – user3255336

+0

但是,如何爲該用戶添加卡?我只需要添加一個卡片密鑰值對? – jsetting32

相關問題