Paypal webhook 不包含 custom_id

Paypal webhook not contain custom_id

我的代码可以为订阅生成一个 link,它工作正常,但是当它向我的 webhook 发送数据时,数据中包含的所有字段除了 custom_id。

请告知我该如何解决这个问题?

$ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, 'https://api-m.sandbox.paypal.com/v1/billing/subscriptions');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, '{
  "plan_id": "P-97A61885CU957844JMFV",
  "start_time": "2021-10-19T00:00:00Z",
   "shipping_amount": {
"currency_code": "USD",
   "custom_id": "xxxxdxxx",
   "value": "10.00"
  },
  "subscriber": {
"name": {
  "given_name": "John",
  "surname": "Doe"
},
"email_address": "customer@example.com",
"shipping_address": {
  "name": {
    "full_name": "John Doe"
  },
  "address": {
    "address_line_1": "2211 N First Street",
    "address_line_2": "Building 17",
    "admin_area_2": "San Jose",
    "admin_area_1": "CA",
    "postal_code": "95131",
    "country_code": "US"
  }
}
  },
  "application_context": {
"brand_name": "SAMPLEBRAND",
"locale": "en-US",
"shipping_preference": "SET_PROVIDED_ADDRESS",
"user_action": "SUBSCRIBE_NOW",
"payment_method": {
  "payer_selected": "PAYPAL",
  "payee_preferred": "IMMEDIATE_PAYMENT_REQUIRED"
},
"return_url": "https://sample.com/webhook_paypal.php",
"cancel_url": "https://sample.com/webhook_paypal.php"
  }
}');

    $headers = array();
    $headers[] = 'Content-Type: application/json';
    $headers[] = 'Authorization: Bearer '.$token;
    $headers[] = 'Paypal-Request-Id: SUBSCRIPTION-21092019-001';
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

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

这是网络钩子

{"id":"WH-82854424W5814533A-78W64324N5754181T","event_version":"1.0","create_time":"2021-10-20T03:35:20.009Z","resource_type":"subscription","resource_version":"2.0","event_type":"BILLING.SUBSCRIPTION.CREATED","summary":"Subscription created","resource":{"shipping_amount":{"currency_code":"USD","value":"10.0"},"start_time":"2021-10-21T00:00:00Z","quantity":"1","subscriber":{"email_address":"customer@example.com","name":{"given_name":"John","surname":"Doe"},"shipping_address":{"name":{"full_name":"John Doe"},"address":{"address_line_1":"2211 N First Street","address_line_2":"Building 17","admin_area_2":"TELEGRAM123","admin_area_1":"CA","postal_code":"95131","country_code":"US"}}},"create_time":"2021-10-20T03:35:19Z","links":[{"href":"https://www.sandbox.paypal.com/webapps/billing/subscriptions?ba_token=BA-91B88793MP435642P","rel":"approve","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/billing/subscriptions/I-SYPXUU0207HG","rel":"edit","method":"PATCH"},{"href":"https://api.sandbox.paypal.com/v1/billing/subscriptions/I-SYPXUU0207HG","rel":"self","method":"GET"}],"id":"I-SYPXUU0207HG","plan_overridden":false,"plan_id":"P-1EC1893707675350SMFWSTEI","status":"APPROVAL_PENDING"},"links":[{"href":"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-82854424W5814533A-78W64324N5754181T","rel":"self","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-82854424W5814533A-78W64324N5754181T/resend","rel":"resend","method":"POST"}]}

要批准订阅,付款人帐户需要订阅。

传统的集成方法是将 href 与从 API 调用返回的 rel:approve 一起使用。

正确的现代集成方法是使用 JS SDK 按钮,如 Subscriptions Integration Guide 中所述。

订阅创建可以直接在 JS 中完成(如指南文档所示),或者 JS createSubscription 函数可以调用服务器上的路由,returns 订阅 ID 来自 API创作。 (在这种情况下不使用 approve href;从您的站点重定向是错误的)。