If a customer in my opencart shop pays with paypal I need a webhook to control a payment change like pending, refund, etc.
So, if the customer pays with paypal the method below is called from paypal plus over the webhook URL:
public function webhook(){
$token = $this->getToken();
$mode = ".sandbox";
$ch = curl_init();
$header = array('Content-Type: application/json', 'Authorization:Bearer'.$token);
curl_setopt($ch, CURLOPT_HTTHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, "https://api".$mode."paypal.com/v1/notification/webhooks/");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERYFYPEER, false);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$json = json_decode($result);
}
What I need at this point is the current transaction_id and the new payment status to update the values in my database.
Could someone tell me how I can get these parameters within the method "webhook"?
Edit:
The result is:
json stdClass Object
(
[webhooks] => Array
(
[0] => stdClass Object
(
[id] => 5EB94006KU40xxxxx
[url] => https://shopexample.de/index.php?route=payment/pp_plus/webhook
[event_types] => Array
(
[0] => stdClass Object
(
[name] => *
[description] => ALL
[status] => ENABLED
)
)
[links] => Array
(
[0] => stdClass Object
(
[href] => https://api.sandbox.paypal.com/v1/notifications/webhooks/5EB94006KU40xxxxx
[rel] => self
[method] => GET
)
[1] => stdClass Object
(
[href] => https://api.sandbox.paypal.com/v1/notifications/webhooks/5EB94006KU40xxxxx
[rel] => update
[method] => PATCH
)
[2] => stdClass Object
(
[href] => https://api.sandbox.paypal.com/v1/notifications/webhooks/5EB94006KU40xxxxx
[rel] => delete
[method] => DELETE
)
)
)
)
)
Getting the data you need, is easy. You are calling PP and a json_encoded variable ($json) is the result.
Now you have access to these value like:
But to get the data you need (here transaction_id and new status), you use the wrong call.
is the service you need for this.