Paypal REST API Bad Request -


trying test paypal payments via integration test in grails project using paypal sandbox. @ stage, i'm trying create paypal payment using rest api.

code snippet:

def jsonpaypalpayment =''' {   "intent": "sale",   "redirect_urls": [{     "return_url": "http://<return url here>",     "cancel_url": "http://<cancel url here>"   }],   "payer": {     "payment_method": "paypal"   },   "transactions": [{     "amount": {       "total": "0.10",       "currency": "usd",     },     "description": "this payment transaction description."   }] } '''  def client = new restclient("https://api.sandbox.paypal.com") client.contenttype = contenttype.json client.headers.'authorization' = "${tokentype} ${accesstoken}" def resp = client.post(path: "/v1/payments/payment", body: jsonpaypalpayment) 

tokentype , accesstoken retrieved in previous step.

the post method returns "400 bad request" response. took sample request documentation minor mods.

full debug output:

2013-05-14 12:31:08,276 <> [main] debug impl.conn.singleclientconnmanager  - connection route httproute[{s}->https://api.sandbox.paypal.com] 2013-05-14 12:31:08,461 <> [main] debug client.protocol.requestaddcookies  - cookiespec selected: best-match 2013-05-14 12:31:08,461 <> [main] debug impl.client.defaulthttpclient  - attempt 1 execute request 2013-05-14 12:31:08,461 <> [main] debug impl.conn.defaultclientconnection  - sending request: post /v1/payments/payment http/1.1 2013-05-14 12:31:08,461 <> [main] debug apache.http.wire  - >> "post /v1/payments/payment http/1.1[eol]" 2013-05-14 12:31:08,461 <> [main] debug apache.http.wire  - >> "accept: application/json, application/javascript, text/javascript[eol]" 2013-05-14 12:31:08,464 <> [main] debug apache.http.wire  - >> "authorization: bearer 6-ovyjz1vqepctkqa7k72dikwqy0kl2difiy6dskdoc[eol]" 2013-05-14 12:31:08,464 <> [main] debug apache.http.wire  - >> "content-length: 356[eol]" 2013-05-14 12:31:08,464 <> [main] debug apache.http.wire  - >> "content-type: application/json[eol]" 2013-05-14 12:31:08,464 <> [main] debug apache.http.wire  - >> "host: api.sandbox.paypal.com[eol]" 2013-05-14 12:31:08,464 <> [main] debug apache.http.wire  - >> "connection: keep-alive[eol]" 2013-05-14 12:31:08,464 <> [main] debug apache.http.wire  - >> "accept-encoding: gzip,deflate[eol]" 2013-05-14 12:31:08,464 <> [main] debug apache.http.wire  - >> "[eol]" 2013-05-14 12:31:08,464 <> [main] debug apache.http.headers  - >> post /v1/payments/payment http/1.1 2013-05-14 12:31:08,464 <> [main] debug apache.http.headers  - >> accept: application/json, application/javascript, text/javascript 2013-05-14 12:31:08,464 <> [main] debug apache.http.headers  - >> authorization: bearer 6-ovyjz1vqepctkqa7k72dikwqy0kl2difiy6dskdoc 2013-05-14 12:31:08,465 <> [main] debug apache.http.headers  - >> content-length: 356 2013-05-14 12:31:08,465 <> [main] debug apache.http.headers  - >> content-type: application/json 2013-05-14 12:31:08,465 <> [main] debug apache.http.headers  - >> host: api.sandbox.paypal.com 2013-05-14 12:31:08,465 <> [main] debug apache.http.headers  - >> connection: keep-alive 2013-05-14 12:31:08,465 <> [main] debug apache.http.headers  - >> accept-encoding: gzip,deflate 2013-05-14 12:31:08,466 <> [main] debug apache.http.wire  - >> "[\n]" 2013-05-14 12:31:08,466 <> [main] debug apache.http.wire  - >> "{[\n]" 2013-05-14 12:31:08,466 <> [main] debug apache.http.wire  - >> "  "intent": "sale",[\n]" 2013-05-14 12:31:08,466 <> [main] debug apache.http.wire  - >> "  "redirect_urls": [{[\n]" 2013-05-14 12:31:08,466 <> [main] debug apache.http.wire  - >> "    "return_url": "http://<return url here>",[\n]" 2013-05-14 12:31:08,466 <> [main] debug apache.http.wire  - >> "    "cancel_url": "http://<cancel url here>"[\n]" 2013-05-14 12:31:08,471 <> [main] debug apache.http.wire  - >> "  }],[\n]" 2013-05-14 12:31:08,471 <> [main] debug apache.http.wire  - >> "  "payer": {[\n]" 2013-05-14 12:31:08,471 <> [main] debug apache.http.wire  - >> "    "payment_method": "paypal"[\n]" 2013-05-14 12:31:08,471 <> [main] debug apache.http.wire  - >> "  },[\n]" 2013-05-14 12:31:08,471 <> [main] debug apache.http.wire  - >> "  "transactions": [{[\n]" 2013-05-14 12:31:08,471 <> [main] debug apache.http.wire  - >> "    "amount": {[\n]" 2013-05-14 12:31:08,471 <> [main] debug apache.http.wire  - >> "      "total": "0.10",[\n]" 2013-05-14 12:31:08,471 <> [main] debug apache.http.wire  - >> "      "currency": "usd",[\n]" 2013-05-14 12:31:08,471 <> [main] debug apache.http.wire  - >> "    },[\n]" 2013-05-14 12:31:08,471 <> [main] debug apache.http.wire  - >> "    "description": "this payment transaction description."[\n]" 2013-05-14 12:31:08,471 <> [main] debug apache.http.wire  - >> "  }][\n]" 2013-05-14 12:31:08,471 <> [main] debug apache.http.wire  - >> "}[\n]" 2013-05-14 12:31:08,661 <> [main] debug apache.http.wire  - << "http/1.1 400 bad request[eol]" 2013-05-14 12:31:08,662 <> [main] debug apache.http.wire  - << "server: apache-coyote/1.1[eol]" 2013-05-14 12:31:08,662 <> [main] debug apache.http.wire  - << "date: tue, 14 may 2013 16:31:08 gmt[eol]" 2013-05-14 12:31:08,662 <> [main] debug apache.http.wire  - << "connection: close[eol]" 2013-05-14 12:31:08,662 <> [main] debug apache.http.wire  - << "paypal-debug-id: 381936211a402[eol]" 2013-05-14 12:31:08,662 <> [main] debug apache.http.wire  - << "content-type: application/json[eol]" 2013-05-14 12:31:08,662 <> [main] debug apache.http.wire  - << "content-length: 195[eol]" 2013-05-14 12:31:08,662 <> [main] debug apache.http.wire  - << "connection: close[eol]" 2013-05-14 12:31:08,662 <> [main] debug apache.http.wire  - << "[eol]" 2013-05-14 12:31:08,662 <> [main] debug impl.conn.defaultclientconnection  - receiving response: http/1.1 400 bad request 2013-05-14 12:31:08,662 <> [main] debug apache.http.headers  - << http/1.1 400 bad request 2013-05-14 12:31:08,662 <> [main] debug apache.http.headers  - << server: apache-coyote/1.1 2013-05-14 12:31:08,662 <> [main] debug apache.http.headers  - << date: tue, 14 may 2013 16:31:08 gmt 2013-05-14 12:31:08,662 <> [main] debug apache.http.headers  - << connection: close 2013-05-14 12:31:08,662 <> [main] debug apache.http.headers  - << paypal-debug-id: 381936211a402 2013-05-14 12:31:08,662 <> [main] debug apache.http.headers  - << content-type: application/json 2013-05-14 12:31:08,662 <> [main] debug apache.http.headers  - << content-length: 195 2013-05-14 12:31:08,662 <> [main] debug apache.http.headers  - << connection: close 2013-05-14 12:31:08,664 <> [main] debug apache.http.wire  - << "{"name":"malformed_request","message":"incoming json request not map api request","information_link":"https://developer.paypal.com/docs/api/#malformed_request","debug_id":"381936211a402"}" 2013-05-14 12:31:08,664 <> [main] debug impl.conn.singleclientconnmanager  - releasing connection org.apache.http.impl.conn.singleclientconnmanager$connadapter@1e668b2 2013-05-14 12:31:08,664 <> [main] debug impl.conn.singleclientconnmanager  - released connection open not reusable. 2013-05-14 12:31:08,664 <> [main] debug impl.conn.defaultclientconnection  - connection shut down | failure:  testpaypalpayment(merch.storeapi.orderintegrationtests) |  groovyx.net.http.httpresponseexception: bad request 

i've noticed rest api in beta. documentation accurate? have endpoints been tested? when rest api scheduled release? insights regarding bad request? in advance.

the json passing not valid (malformed) since seems have comma after currency value.

here valid example directly documentation:

{    "intent":"sale",    "redirect_urls":{       "return_url":"http://<return url here>",       "cancel_url":"http://<cancel url here>"    },    "payer":{       "payment_method":"paypal"    },    "transactions":[       {          "amount":{             "total":"7.47",             "currency":"usd"          },          "description":"this payment transaction description."       }    ] } 

source


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -