转到Paypal REST API请求

So Im currently using Go and Im trying to create a payment for Paypal I been trying this code

    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))

I already got the access token, the problem is Im getting this error on the response body (last line)

MALFORMED_REQUEST

The request Im using is this (as of the 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"
   }
}

At my eyes seems a good request... no idea what im missing Error image

查看全部
dsgnsdjk26586
dsgnsdjk26586
2015/10/19 22:31
  • paypal
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

2个回复