【问题标题】:PayPal Plus - Webhook - to change payment status in databasePayPal Plus - Webhook - 更改数据库中的付款状态
【发布时间】:2018-02-09 22:29:16
【问题描述】:

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

                        )

                )

        )

)

【问题讨论】:

  • `print_r($result)` 中有什么?
  • 嗨,我在文本中添加了结果。我不知道如何从上次付款中获取transaction_id和付款状态。

标签: php curl paypal opencart paypal-webhooks


【解决方案1】:

别打电话!等待呼叫并处理。

public function webhook() {
    $body = file_get_contents('php: //input');

    $data = json_decode($body, true);

    //Validate and verify webhook here.

    if ($data['event_type'] == 'PAYMENT.AUTHORIZATION.CREATED') {
        //Payment authorization created.
    } else if ($data['event_type'] == 'PAYMENT.AUTHORIZATION.VOIDED') {
        //Payment authorization voided.
    } else if ($data['event_type'] == 'PAYMENT.CAPTURE.COMPLETED') {
        //Payment capture completed.
    } else if ($data['event_type'] == 'PAYMENT.CAPTURE.DENIED') {
        //Payment capture denied.
    } else if ($data['event_type'] == 'PAYMENT.CAPTURE.PENDING') {
        //Payment capture pending.
    } else if ($data['event_type'] == 'PAYMENT.CAPTURE.REFUNDED') {
        //Payment capture refunded.
    } else if ($data['event_type'] == 'PAYMENT.CAPTURE.REVERSED') {
        //Payment capture reversed.
    } else {
        //Handle other webhooks
    }
}

【讨论】:

    【解决方案2】:

    获取您需要的数据很容易。 您正在调用 PP,结果是一个 json_encoded 变量 ($json)。

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

    $webhooks[0]->id
    

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

    payment/payments/PAYMENT_ID
    

    是您为此需要的服务。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-01-21
      • 2019-08-07
      • 2015-01-07
      • 1970-01-01
      • 2013-08-14
      • 2016-07-18
      • 2020-11-07
      相关资源
      最近更新 更多