使用 Parse 创建 Stripe 客户 [英] Creating a Stripe Customer Using Parse

查看:47
本文介绍了使用 Parse 创建 Stripe 客户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 parse 创建条带客户,但似乎无法从响应中获取 customer.id 值.

I'm trying to create a stripe customer using parse but can't seem to get the customer.id value from the response.

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){


 });

推荐答案

这里是一种使用解析条带模块 api 在解析云代码中创建新客户的方法.

Here is a way to create a new customer in parse cloud code using parse stripe module api.

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

请确保您已存储您的发布 API 密钥

Be sure you have stored your publish api key

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.");
        }
    });
});

这篇关于使用 Parse 创建 Stripe 客户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆