user3255336
user3255336

Reputation: 25

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


 });

Upvotes: 2

Views: 1529

Answers (1)

james075
james075

Reputation: 1278

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

Upvotes: 6

Related Questions