在罗马教廷式Webhook侦听器中侦听并获取触发操作的信息

时间:2019-07-18 10:55:54

标签: php paypal paypal-sandbox paypal-webhooks

我已在仪表板中配置了PayPal Webhook侦听器,使其具有要侦听的必要事件,并且Webhook URL已成功触发,但是我无法在Webhook URL中获得所需的必要信息,例如订阅信息,订阅所有者等

我试图从webhook URL中获取信息,我得到的只是     {“名称”:“ INVALID_RESOURCE_ID”,“消息”:“未找到请求的资源ID”,“ debug_id”:“ ce4418e9be87”,“详细信息”:[],“链接”:[]}

<?php 

    //event test script
    //===============================
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 
    'https://api.sandbox.paypal.com/v1/oauth2/token');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_USERPWD, 'client_id' . ':' . 'secret');  

    $headers = array();
    $headers[] = 'Accept: application/json';
    $headers[] = 'Accept-Language: en_US';
    $headers[] = 'Content-Type: application/x-www-form-urlencoded';
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

    $result = json_decode(curl_exec($ch));
    $access_token = $result->access_token;
    if (curl_errno($ch)) {
        echo 'Error:' . curl_error($ch);
    }
    curl_close ($ch);


    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, 'https://api.sandbox.paypal.com/v1/notifications/simulate-event');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "{\n  \"url\": \"https://subscription.addisfortune.news/paypal/paypalEventListenerForADF.php\",\n  \"event_type\": \"BILLING.SUBSCRIPTION.CREATED\",\n  \"resource_version\": \"1.0\"\n}");
    curl_setopt($ch, CURLOPT_POST, 1);

    $headers = array();
    $headers[] = 'Content-Type: application/json';
    $headers[] = 'Authorization: Bearer '. $access_token;
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

    $result = curl_exec($ch);

    print_r($result);
    if (curl_errno($ch)) {
        echo 'Error:' . curl_error($ch);
    }
    curl_close ($ch);


    //Event listener
    //=====================================
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://api.sandbox.paypal.com/v1/oauth2/token');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_USERPWD, 'client_id' . ':' . 'secret');

    $headers = array();
    $headers[] = 'Accept: application/json';
    $headers[] = 'Accept-Language: en_US';
    $headers[] = 'Content-Type: application/x-www-form-urlencoded';
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

    $result = json_decode(curl_exec($ch));
    $access_token = $result->access_token;
    if (curl_errno($ch)) {
        echo 'Error:' . curl_error($ch);
    }
    curl_close ($ch);

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://api.sandbox.paypal.com/v1/notifications/webhooks-events-transmissions');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
    $headers = array();
    $headers[] = 'Content-Type: application/json';
    $headers[] = 'Authorization: Bearer '. $access_token;
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

    $result = curl_exec($ch);
    if (curl_errno($ch)) {
        echo 'Error:' . curl_error($ch);
    }
    curl_close ($ch);
    ?>

    <?php
    ini_set('sendmail_from', 'my-email');
    $mail  = mail("my-email","Paypal webhook result",$result);
    if($mail){
        echo "sent";
    }
?>

我希望结果是订户的完整信息,例如电子邮件,全名,订阅期

0 个答案:

没有答案