简体   繁体   中英

Creating a Stripe Customer Using Parse

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


 });

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

Parse Reference: http://parse.com/docs/js/symbols/Stripe.Customers.html

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM