I'm attempting to follow the Orders Integration Guide as shown in this documentation: https://developer.paypal.com/docs/marketplaces/orders/integration-guide/
I was able to complete getting the access token and everything up to the Create Order section. However, when I try to make the Create Order call in my localhost, I am getting this as the ouput:
Notice: Undefined variable: data in C:\xampp\htdocs\ordersAPI.php on line 75 Notice: Undefined variable: data in C:\xampp\htdocs\ordersAPI.php on line 85
I have been racking my brain trying to figure this out why this is happening. I am have been looking through all sorts of stack questions but I can’t figure out what I’m missing. It seems like I did define the ‘data’ variable so I’m not sure where I’m going wrong and why I’m getting 1 returned.
I am also getting an error of 500 returned when trying to test my credentials on another test site I found. So I am not sure if it’s something wrong with the account, or with my code. I wouldn’t assume it’s an account issue since it’s giving an error about undefined variable.
<?php
$data = '{
"purchase_units": [
{
"reference_id": "item_bought",
"description": "item_description",
"amount": {
"currency": "USD",
"details": {
"subtotal": "100.00",
"shipping": "0.00",
"tax": "0.00"
},
"total": "100.00"
},
"payee": {
"email": "selleraccount@gmail.com"
},
"items": [
{
"name": "widget",
"sku": "sku03",
"price": "50.00",
"currency": "USD",
"quantity": "1",
"category": "PHYSICAL"
},
{
"name": "gadget",
"sku": "sku04",
"price": "50.00",
"currency": "USD",
"quantity": "1",
"category": "PHYSICAL"
}
],
"shipping_address": {
"recipient_name": "Billy Bob",
"line1": "123 Test Street",
"line2": "Building 17",
"city": "Lawrence",
"country_code": "US",
"postal_code": "66047",
"state": "KS",
"phone": "(123) 456-7890"
},
"shipping_method": "United Postal Service",
"partner_fee_details": {
"receiver": {
"email": "ordersapitest@gmail.com"
},
"amount": {
"value": "20.00",
"currency": "USD"
}
},
"payment_linked_group": 1,
"custom": "silk",
"invoice_number": "invoice_1234",
"payment_descriptor": "FakeShop"
}
],
"redirect_urls": {
"return_url": "https://marketplace.com/return",
"cancel_url": "https://marketplace.com/cancel"
}
}';
function marketplace(){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/checkout/orders");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Accept: application/json",
"Content-Type: application/json",
"Authorization: Bearer A21AAFA2Ty6rGJc74cTukhyCRz5pHU3vX736qtr4qSfhDmEzawiU8u91w69GxZtmYDalxaljYbeqi6ovZmOQCyTEETom8ZkFQ",
"PayPal-Request-Id: 5Qy7c8A1H8iQqyp",
"Content-length: ".strlen($data))
);
$httpResponse= curl_exec($ch);
if(!$httpResponse) {
$response = "API failed: ".curl_error($ch).'('.curl_errno($ch).')';
return $response;
}
$httpResponseAr = explode("&", $httpResponse);
return $httpResponseAr;
}
$result = marketplace();
echo $json = json_encode($result, JSON_PRETTY_PRINT);
//print_r($result);
?>
The $data variable is not being passed as a parameter in the marketplace function on line 71 and it is not being passed as a parameter in the function call on line 96. This is what is causing the error.
Also, while the 'CREATE ORDER' call will work, if you attempt the next step which is the 'PAY FOR ORDER' call, the error 500 will be generated because you are trying to use the MarketPlaces API for PayPal and are not yet approved for the MarketPlaces API.
Please see this article on PayPal’s site.
https://www.paypal-knowledge.com/infocenter/index?page=content&id=FAQ2138&expand=true&locale=en_US
You can also find more information on the PP4MP at:
https://developer.paypal.com/docs/marketplaces/pp4mp/