porton
porton

Reputation: 5825

Why posting to PayPal sandbox API not working for me?

I POST (with suitable Authorization: header) to https://api.sandbox.paypal.com/v1/payments/payment

{"intent": "sale", "payer": {"payment_method": "paypal"}, "transactions": [{"amount": 10.0, "currency": "USD", "details": {"subtotal": 10.0, "shipping": 0.0, "tax": 0.0}, "description": "Item 1"}], "redirect_urls": {"return_url": "https://example.com", "cancel_url": "https://example.com"}}

and receive in return

{"name":"MALFORMED_REQUEST","message":"Incoming JSON request does not map to API request","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST","debug_id":"815ed32bcd78e"}

Why the error? What is my error?

Upvotes: 0

Views: 83

Answers (2)

The question was edited and this answer is no longer relevant.

Upvotes: 0

Evil_skunk
Evil_skunk

Reputation: 3392

Please check out the paypal documentation

See the example on the right side. amount should be an object - currency and details need to be attributes of amount, also you are missing the required total attribute

Reworked JSON

{
   "intent":"sale",
   "payer":{
      "payment_method":"paypal"
   },
   "transactions":[
      {
         "amount":{
            "total":"10.00",
            "currency":"USD",
            "details":{
               "subtotal":"10.00",
               "shipping":"0.00",
               "tax":"0.00"
            }
         },
         "description":"Item 1"
      }
   ],
   "redirect_urls":{
      "return_url":"https://example.com",
      "cancel_url":"https://example.com"
   }
}

Please be careful when specifying "price-numbers" (total, subtotal, ...) they must be strings and follow rules about decimal digits

Upvotes: 1

Related Questions