php - PayPal Plus - Webhook - 更改数据库中的付款状态

标签 php curl paypal opencart paypal-webhooks

如果我的 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
                                )

                        )

                )

        )

)

最佳答案

获取所需数据非常简单。 您正在调用 PP,结果是一个 json_encoded 变量 ($json)。

现在您可以访问这些值,例如:

$webhooks[0]->id

但是为了获取您需要的数据(这里是 transaction_id 和新状态),您使用了错误的调用。

payment/payments/PAYMENT_ID

是您为此需要的服务。

关于php - PayPal Plus - Webhook - 更改数据库中的付款状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45990382/

相关文章:

javascript - 如何根据 `<option>` 更改链接表单操作 a?

PHP 多重 if/elseif 和错误消息/处理最佳实践

PHP Paypal 动态传递多个项目

php - 当我收到 PayPal IPN 时,我应该在哪里执行 UPDATE 查询?

button - paypal Payments Pro 托管解决方案集成重复支付

php - 从坐标数组构建谷歌地图 v3 多边形路径

php - 匹配字符串中空格后的位数

curl - cURL 和 libcurl 有什么区别?

javascript - 浏览器请求和 curl 请求有什么区别?

php - CURLOPT_TIMEOUT 的最大值