如果我的 opencart 商店中的客户使用 paypal 付款,我需要一个 webhook 来控制付款更改,例如待处理、退款等。
因此,如果客户使用 paypal 付款,则通过 webhook URL 从 paypal plus 调用以下方法:
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);
}
此时我需要的是当前的 transaction_id 和新的付款状态来更新我的数据库中的值。
有人可以告诉我如何在“webhook”方法中获取这些参数吗?
编辑:
结果是:
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
)
)
)
)
)