我花了将近两天的时间来解决与PayPal相关的问题。我试图在用户批准后执行付款,但每次发送Curl请求时,我都会得到MALFORMED_REQUEST。
def execute
# Get the access_token
token = get_paypal_token(false)
payer_id = params[:PayerID]
payment_id = params[:paymentId]
# Creating the data object
stringJson = {:payer_id => "#{payer_id}"}
# You can see that I hard-coded the payer_id to ensure the JSON is correct
curlString = `curl -v -H "Authorization: Bearer #{token}" -H "Content-Type: application/json" -d '{"payer_id" : "QULQSFESGMCX2"}' https://api.sandbox.paypal.com/v1/payments/payment/#{payment_id}/execute/`
end答复是:
"{\"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\":\"6431589715660\"}"发布于 2016-01-27 08:30:01
看来你是从窗口运行的。我从我的窗口和我的测试服务器尝试了您的命令,以'{payer_id的形式接收json。这是因为你的单引号。
我已经把单引号改成了双引号,我在这里做得很好。
-d "{\"payer_id\" : \"QULQSFESGMCX2\"}"您可以从控制台运行curl命令并查看发生了什么,然后您可以将它推入您的ruby脚本代码中。
https://stackoverflow.com/questions/35016850
复制相似问题