尝试cURL Paypal API,收到“MALFORMED_REQUEST”错误

时间:2013-06-30 02:35:58

标签: curl paypal

我正在尝试为客户实施支付系统,但我遇到了障碍。

当我尝试卷曲Paypal沙箱时,我正在遵循此处的文档:https://developer.paypal.com/webapps/developer/docs/integration/direct/accept-credit-cards/

这是我正在使用的确切命令:

curl -v -k https://api.sandbox.paypal.com/v1/payments/payment -H "Content-Type:application/json" -H "Authorization:Bearer DdtHNNeMmv9Jb5K9fXLC50vxUkIrF6MihT.IJUefGlo" --connect-timeout 30 -d {"intent":"sale","payer":{"payment_method":"credit_card","funding_instruments":[{"credit_card":{"number":"4417119669820331","type":"visa","expire_month":11,"expire_year":2018,"cvv2":"874","first_name":"Joe","last_name":"Shopper","billing_address":{"line1":"52 N Main ST","city":"Johnstown","country_code":"US","postal_code":"43210","state":"OH"}}}]},"transactions":[{"amount":{"total":"7.47","currency":"USD","details":{"subtotal":"7.41","tax":"0.03","shipping":"0.03"}},"description":"This is the payment transaction description."}]}

(显然,我正在根据我之前获得的访问令牌更改访问令牌,这也验证了我能够卷曲Paypal)

当我这样做时,我收到一个MALFORMED_REQUEST错误,指出“请求JSON格式不正确”。这是我的详细调试信息:

c:\>curl -v -k https://api.sandbox.paypal.com/v1/payments/payment -H "Content-Type:application/json" -H "Authorization:Bearer DdtHNNeMmv9Jb5K9fXLC50vxUkIrF6MihT.IJUefGlo" --connect-timeout 30 -d {"intent":"sale","payer":{"payment_method":"credit_card","funding_instruments":[{"credit_card":{"number":"4417119669820331","type":"visa","expire_month":11,"expire_year":2018,"cvv2":"874","first_name":"Joe","last_name":"Shopper","billing_address":{"line1":"52 N Main ST","city":"Johnstown","country_code":"US","postal_code":"43210","state":"OH"}}}]},"transactions":[{"amount":{"total":"7.47","currency":"USD","details":{"subtotal":"7.41","tax":"0.03","shipping":"0.03"}},"description":"This is the payment transaction description."}]}
    * Adding handle: send: 0
    * Adding handle: recv: 0
    * Curl_addHandleToPipeline: length: 1
    * - Conn 0 (0x1d6d2f0) send_pipe: 1, recv_pipe: 0
    * About to connect() to api.sandbox.paypal.com port 443 (#0)
    * Trying 173.0.82.78...
    * Connected to api.sandbox.paypal.com (173.0.82.78) port 443 (#0)
    * SSLv3, TLS handshake, Client hello (1):
    * SSLv3, TLS handshake, Server hello (2):
    * SSLv3, TLS handshake, CERT (11):
    * SSLv3, TLS handshake, Request CERT (13):
    * SSLv3, TLS handshake, Server finished (14):
    * SSLv3, TLS handshake, CERT (11):
    * SSLv3, TLS handshake, Client key exchange (16):
    * SSLv3, TLS change cipher, Client hello (1):
    * SSLv3, TLS handshake, Finished (20):
    * SSLv3, TLS change cipher, Client hello (1):
    * SSLv3, TLS handshake, Finished (20):
    * SSL connection using DES-CBC3-SHA
    * Server certificate:
    * subject: C=US; ST=California; L=San Jose; O=PayPal, Inc.; OU=PayPal Production; CN=api.sandbox.paypal.com
    * start date: 2012-12-06 00:00:00 GMT
    * expire date: 2016-12-06 23:59:59 GMT
    * issuer: C=US; O=VeriSign, Inc.; OU=VeriSign Trust Network; OU=Terms of use at https://www.verisign.com/rpa (c)10; CN=VeriSign Class 3 Secure Server CA- G3
    * SSL certificate verify result: self signed certificate in certificate chain (19), continuing anyway.
> POST /v1/payments/payment HTTP/1.1
> User-Agent: curl/7.31.0
> Host: api.sandbox.paypal.com
> Accept: */*
> Content-Type:application/json
> Authorization:Bearer DdtHNNeMmv9Jb5K9fXLC50vxUkIrF6MihT.IJUefGlo
> Content-Length: 444
>
* upload completely sent off: 444 out of 444 bytes
< HTTP/1.1 400 Bad Request
* Server Apache-Coyote/1.1 is not blacklisted
< Server: Apache-Coyote/1.1
< Date: Sun, 23 Jun 2013 18:07:54 GMT
< Connection: close
< PayPal-Debug-Id: 2f3f584e8050e
< Content-Type: application/json
< Content-Length: 200
< Connection: close
<
{"name":"MALFORMED_REQUEST","message":"The request JSON is not well formed.","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST","debug_id":"2f3f584e8050e"}* Closing connection 0* SSLv3, TLS alert, Client hello (1):

我已经多次验证JSON是否正确形成,甚至通过JSON Lint(http://jsonlint.com/)运行它。而且,当然,Paypal的JSON响应中提供的链接无处可去,过去一周我一直试图让Paypal的人向我解释这一点。

任何输入都将非常受欢迎。

1 个答案:

答案 0 :(得分:0)

似乎你传入的JSON对象周围没有单引号。尝试更换你自己的访问令牌:

curl -v -k https://api.sandbox.paypal.com/v1/payments/payment -H "Content-Type:application/json" -H "Authorization:Bearer 5osWcO-OBwV2Vbdvdu2H8P50EHwx8pNqTQxpVnJlc38" --connect-timeout 30 -d '{"intent":"sale","payer":{"payment_method":"credit_card","funding_instruments":[{"credit_card":{"number":"4417119669820331","type":"visa","expire_month":11,"expire_year":2018,"cvv2":"874","first_name":"Joe","last_name":"Shopper","billing_address":{"line1":"52 N Main ST","city":"Johnstown","country_code":"US","postal_code":"43210","state":"OH"}}}]},"transactions":[{"amount":{"total":"7.47","currency":"USD","details":{"subtotal":"7.41","tax":"0.03","shipping":"0.03"}},"description":"This is the payment transaction description."}]}'