user3661571
user3661571

Reputation: 11

Getting HTTP 400 error when trying to make Paypal payment

I was getting this error when building my little toy payment gateway form, but now I realized I can't even properly run the sample code after cloning the repository here.

I have entered my client ID and secret into configure.js. I'm in sandbox mode.

The file I'm running:

    var create_payment_json = {
    "intent": "sale",
    "payer": {
        "payment_method": "credit_card",
        "funding_instruments": [{
            "credit_card": {
                "type": "visa",
                "number": "4417119669820331",
                "expire_month": "11",
                "expire_year": "2018",
                "cvv2": "874",
                "first_name": "Joe",
                "last_name": "Shopper",
                "billing_address": {
                    "line1": "52 N Main ST",
                    "city": "Johnstown",
                    "state": "OH",
                    "postal_code": "43210",
                    "country_code": "US"
                }
            }
        }]
    },
    "transactions": [{
        "amount": {
            "total": "7.00",
            "currency": "USD",
            "details": {
                "subtotal": "5.00",
                "tax": "1.00",
                "shipping": "1.00"
            }
        },
        "description": "This is the payment transaction description."
    }]
};

paypal.payment.create(create_payment_json, function (error, payment) {
    if (error) {
        console.log(error);
        throw error;
    } else {
        console.log("Create Payment Response");
        console.log(payment);
    }
});

When running, I get

> node create_with_credit_card.js
{ [Error: Response Status : 400]
  response:
   { name: 'UNKNOWN_ERROR',
     message: 'An unknown error has occurred',
     information_link: 'https://developer.paypal.com/webapps/developer/docs/api/#UNKNOWN_ERROR',
     debug_id: '599dd3222e6fb',
     httpStatusCode: 400 },
  httpStatusCode: 400 }

C:\cygwin64\home\Ryan\PayPal-node-SDK\samples\payment\create_with_credit_card.js:47
        throw error;
              ^
Error: Response Status : 400
    at IncomingMessage.<anonymous> (C:\cygwin64\home\Ryan\PayPal-node-SDK\lib\client.js:136:23)
    at IncomingMessage.emit (events.js:117:20)
    at _stream_readable.js:944:16
    at process._tickCallback (node.js:442:13)

I'm desperate to find out where I am going wrong here.

Upvotes: 1

Views: 647

Answers (1)

Athrun Zara
Athrun Zara

Reputation: 873

The card you use (4417119669820331) is not unique. When testing a payment in REST API especially for Credit Card number, try not to use the default credit card number such 4417119669820331. Try with some other number like example 4532371704016199.

Alternatively, use this site (http://www.fakenamegenerator.com/) to generate the fake credit card for testing.

Upvotes: 1

Related Questions