简体   繁体   中英

paypal express checkout - 400 bad request

I'm using this instruction https://developer.paypal.com/docs/integration/direct/express-checkout/integration-jsv4/advanced-integration/ to set up paypal. The only different is that I need to send data to CREATE_PAYMENT_URL endpoint, so I transfer it as second parameter

paypal.request.post(
                CREATE_PAYMENT_URL,
                JSON.stringify([{"name": "test", "price": 10}]),
                { headers: { 'Content-Type': 'application/json' } }

            )

after that I'm getting 400 error

{"success":false,"errors":{"statuscode":400,"message":"Invalid json message received"}}

Backend doesn't matter, cause it's never reached. Also I'm almost sure it worked fine few days ago Any ideas?

Fiddler screen 在此处输入图片说明

Try setting the second param to null, and send an options object as the third param with an object named json in the third with a plain JS object inside.

paypal.request.post(PAYMENT_URL, null, {
    json : {
        name:'test',
        price:10
      }
  })

It's not in the documentation, I was having similar issues but dug around in the source code to get it to work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM