- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
{"intent":"CAPTURE","purchase_units":{"amount":{"currency_code":"GBP","value":"3.5"}}}
is myjson
It is returning
{"name":"INVALID_REQUEST","message":"Request is not well-formed, syntactically incorrect, or violates schema.","debug_id":"71ab5a6cf35d3","details":[{"field":"/purchase_units","location":"body","issue":"MALFORMED_REQUEST_JSON","description":"The request JSON is not well formed."}],"links":[{"href":"https://developer.paypal.com/docs/api/orders/v2/#error-MALFORMED_REQUEST_JSON","rel":"information_link","encType":"application/json"}]}
This is my create function
function create_order($access_token, $Total, $Currency)
{
$ch = false;
$http_header = array
(
"Content-Type: application/json",
"Authorization: Bearer " . $access_token,
);
$post_fields = array ("intent" => "CAPTURE",
"purchase_units" =>
array (
"amount" =>
array (
"currency_code" => $Currency,
"value" => $Total
)
)
);
$jsonData = json_encode($post_fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api-m.sandbox.paypal.com/v2/checkout/orders");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $http_header);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
$result = curl_exec($ch);
$json = json_encode($result);
print_r($jsonData);
echo $result;
curl_close($ch);
return $json;
}
Solved! Go to Solution.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks so I gather - oops. A case of seeing what you think is on the screen and not what is actually there. Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Good day @knutsford,
Thank you for posting to the PayPal community.
Yes, this is an issue with your Create Order API request JSON which is not well formed.
"purchase_units": field is not well formed and it is an Array of Objects.
https://developer.paypal.com/docs/api/orders/v2/#orders_create!path=purchase_units&t=request
I see that your passing "{ }" instead of "[ ]" for the "purchase_units" in Create Order API request JSON which is the reason why your facing this error.
Please refer the below sample :
"intent": "CAPTURE",
"purchase_units": [
{
"reference_id": "**************",
"amount": {
"currency_code": "USD",
"value": "100.00"
}
}
],
https://developer.paypal.com/docs/api/orders/v2/#orders_create
Sincerely,
Chiranjeevi
PayPal/Braintree MTS
If this post or any other was helpful, please enrich the community by giving kudos or accepting it as a solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks so I gather - oops. A case of seeing what you think is on the screen and not what is actually there. Thanks
Haven't Found your Answer?
It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.
- link my PayPal business account with my WordPress website , but it's not work ?! in PayPal Payments Standard
- PayPal Express Checkout charging incorrect values? in Sandbox Environment
- I met the 422 response, and tries a lot solutions in the community but still not work in REST APIs
- [UNPROCESSABLE_ENTITY], but payment went through in PayPal Payments Standard
- Getting this error from paypal , popup closing automatically itself when it opens in SDKs