PAYPAL ERROR 400 NODEJS

0

I followed the Paypal documentation on how to make an order, this is the object:

var payReq= JSON.stringify({

        "0intent": "sale",
        "payer": {
            "payment_method": "paypal"
        },
        "redirect_urls": {
            "return_url": "http://localhost:3000/process",
            "cancel_url": "http://localhost:3000/cancel",
        },
        "transactions": [{
            "item_list": {
                "items": [{
                    "name": "tacos",
                    "sku": "001",
                    "price": "1.00",
                    "currency": "USD",
                    "quantity": 1
                }]
            },
            "amount": {
                "currency": "USD",
                "total": "1.00"
            },
            "description": "This is the payment description."
        }]
    });

And this is the function to make the order:

paypal.payment.create(payReq, function(error, payment){
        var links = {};

        if(error){
          console.error(JSON.stringify(error));
        } else {
          // Capture HATEOAS links
          payment.links.forEach(function(linkObj){
            links[linkObj.rel] = {
              href: linkObj.href,
              method: linkObj.method
            };
          })

          // If the redirect URL is present, redirect the customer to that URL
          if (links.hasOwnProperty('approval_url')){
            // Redirect the customer to links['approval_url'].href
          } else {
            console.error('no redirect URI present');
          }
        }
      });

And this is what I get when executing the function:

{"response":{"name":"MALFORMED_REQUEST","message":"Incoming JSON request does not map to API request","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST","debug_id":"ee13a7fe92652","httpStatusCode":400},"httpStatusCode":400}

According to the Paypal documentation the error 400 means: Bad Request: The server could not understand the request, probably due to syntax error.

    
asked by RereRoro1 30.10.2018 в 00:04
source

1 answer

0
try {
        $payment->create($apiContext);
    } catch (PayPal\Exception\PPConnectionException $ex) {
        var_dump(json_decode($ex->getData()));
        exit(1);
    }

but remove that 0intent may be why

When I received the error (PHP SDK), I detected the exception and $ ex- > getData () returned a json that contains the details about the incorrect request, in my case The currency code I gave was incorrect. A syntax error occurred.

    
answered by 30.10.2018 в 00:11