Search code examples
paypal-sandboxbraintree

Why I'm not geting token in res in braintree?


I'm using braintree for payment and I have done this.

gateway.customer.create({
    firstName: "Sachin",
    lastName: "Shah",
    company: "Qwerty",
    email: "Qwerty@example.com",
    phone: "114.555.1234",
    fax: "614.555.1234",
    website: "www.example.com",       
}, function (err, result) {
    if (err) {
        res.send({code:0, status:'Error', message:err});
    }else{
        res.send({code:1, status:'Success', data: result});
    }
});

I followed it's official doc and they show that when req is success I'll get token but I'm gtting result.customer.paymentMethods[]

Response

{
"code": 1,
"status": "Success",
"data": {
    "customer": {
        "id": "569549779",
        "merchantId": "XXXXXXXXXXXXXXXXX",
        "firstName": "Sachin",
        "lastName": "Shah",
        "company": "Qwerty",
        "email": "Qwerty@example.com",
        "phone": "114.555.1234",
        "fax": "614.555.1234",
        "website": "www.example.com",
        "createdAt": "2019-10-10T05:13:42Z",
        "updatedAt": "2019-10-10T05:13:42Z",
        "customFields": "",
        "globalId": "XXXXXXXXXXXXXXXXX",
        "creditCards": [],
        "addresses": [],
        "paymentMethods": []
    },
    "success": true
}
}

Expected Output

I need to get paymentMethodToken for further API calls.


Solution

  • Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support.

    You're currently creating a customer without a payment method. You'll need to create the customer with a payment method to retrieve a paymentMethodToken.