Search code examples
javascriptnode.jspaypalsandboxpaypal-rest-sdk

Node.js Paypal sdk: visa card is not working


I am attempting to process credit cards with PayPal in node.js
With master card, the below code is working with sandbox account with 201 status code.
But, not working with 'visa', 'amex'.
With 'visa', 'amex' card, I am getting 500 status code, and I cannot find error details. Who has seen this case ?

var paypal = require('paypal-rest-sdk');

paypal.configure({
    'mode': 'sandbox',
    'client_id': 'CLIENT_ID',
    'client_secret': 'CLIENT_SECRET_KEY'
});

var payment = {
    "intent": "authorize",
    "payer": {
        "payment_method": "credit_card",
        "funding_instruments": [{
            "credit_card": {
                "type": "visa",//visa//mastercard//amex
                "expire_month": 1,
                "expire_year": 2022,
                "cvv2": "VISA_CCV2",
                "number": "VISA_NUMBER"
            }
        }]
    },
    "redirect_urls": {
        "return_url": "http://127.0.0.1:3000/success",
        "cancel_url": "http://127.0.0.1:3000/err"
    },
    "transactions": [{
        "item_list": {
            "items": [{
                "name": "media dvd",
                "sku": "001",
                "price": "1.00",
                "currency": "USD",
                "quantity": 1
            }]
        },
        "amount": {
            "total": 1.00,
            "currency": "USD"
        },
        "description": " a book on mean stack "
    }]
}

paypal.payment.create(payment, { timeout: 10000 }, function (err, payment) {
    if (err) {
        console.log(err, payment);


    }
    else {
        console.log(payment);
    }
}); 

Solution

  • From: https://developer.paypal.com/docs/api/payments/v1/

    Important: The use of the PayPal REST /payments APIs to accept credit card payments is restricted. Instead, you can accept credit card payments with Braintree Direct.

    (Braintree direct would be a full gateway account, which requires account approval and is only available for businesses in certain countries.)

    Since you were attempting to integrate something old, with an old SDK, and that cannot be used in the live environment -- here is the best PayPal alternative: