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"
}
}