所以我目前正在使用 Go 并且我正在尝试为 Paypal 创建付款我一直在尝试此代码
payer := &Payer{"paypal"}
amount := &Amount{"EUR", "12"}
trans := &Transactions{amount, "A super test"}
uris := &Redirect_urls{"http://localhost", "http://localhost"}
p := &Payment{"sale", payer, trans, uris}
response, err := json.Marshal(p)
if err != nil {
log.Println("Error at PaypalPayment - buy controller")
log.Fatal(err)
}
log.Println(string(response))
client := &http.Client{}
buf := bytes.NewBuffer(response)
req, err := http.NewRequest("POST", "https://api.sandbox.paypal.com/v1/payments/payment", buf)
if err != nil {
log.Println("Error at PaypalPayment - buy controller - 2")
log.Fatal(err)
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer " + token.Access_token)
resp, err := client.Do(req)
if err != nil {
log.Println("Error at PaypalPayment - buy controller - 3")
log.Fatal(err)
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Println("Error at PaypalPayment - buy controller - 4")
log.Fatal(err)
}
log.Println(string(body))
我已经获得了访问令牌,问题是我在响应正文中收到此错误(最后一行)
MALFORMED_REQUEST
我使用的请求是这个(从 println 开始)
{
"Intent":"sale",
"Payer":{
"Payment_method":"paypal"
},
"Transactions":{
"Amount":{
"Currency":"EUR",
"Total":"12"
},
"Description":"Super test"
},
"Redirect_urls":{
"Return_url":"http://localhost",
"Cancel_url":"http://localhost"
}
}
在我看来似乎是一个很好的要求......不知道我错过了什么
汪汪一只猫
小唯快跑啊
相关分类