Reputation: 1108
I'm reading the docs about creating a customer. I need to create one with a credit card, a cvc number but I get an error and I don't know how I must create it.
I show my code
if(user.local.subscription == undefined){
//creamos cliente
gateway.customer.create({
creditCard : {
number : cardnumber,
expirationDate : "12/15"
}
}, function (err, result) {
if(err){
//return res.status(500).json({ error : "Error creating customer"});
console.log(err);
}
console.log(result);
/*user.subscription = result;
userId = result.customer.id;*/
});
}
Upvotes: 0
Views: 637
Reputation: 2719
var braintree = require("braintree");
var gateway = braintree.connect({
environment: braintree.Environment.Sandbox,
merchantId: "your sanboxmerchant",
publicKey: "your sandbox public key",
privateKey: "sandbox privatekey"
});
gateway.customer.create({
creditCard : {
cardholder_name : 'james bliz',
number : "4111111111111111",
cvv : '123',
expirationDate : "12/17"
}
}, function (err, result) {
if(err){
//return res.status(500).json({ error : "Error creating customer"});
console.log(err);
}
console.log(result);
/*user.subscription = result;
userId = result.customer.id;*/
});
the answer should be somthing like this
{ customer:
{ id: '29931379',
merchantId: 'qn5442rvm794nc6q',
firstName: null,
lastName: null,
company: null,
email: null,
phone: null,
fax: null,
website: null,
createdAt: '2015-05-12T10:33:41Z',
updatedAt: '2015-05-12T10:33:42Z',
customFields: '',
creditCards: [ [Object] ],
addresses: [],
paymentMethods: [ [Object] ] },
success: true }
take the required field from it i think you will need only the customer id from tha result object.
Upvotes: 3