使用Parse创建条带客户

时间:2014-02-12 15:22:32

标签: javascript ios parse-platform

我正在尝试使用解析创建条带客户,但似乎无法从响应中获取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){


 });

1 个答案:

答案 0 :(得分: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.");
        }
    });
});