我正在使用以下资源为订阅创建https://developer.paypal.com/docs/subscriptions/integrate/#4-create-a-subscription的智能按钮。我正在使用PHP curl请求获取访问令牌,并在其后跟随另一个PHP curl请求来创建产品。然后,我获取产品ID,并使用它通过PHP curl请求创建订阅计划。当请求成功后,响应状态为200,并且缺少帐单周期,文档说我应该得到202响应。 (我对产品ID的请求虽然成功,但也会返回200状态而不是201)。
$ch = curl_init('https://api.sandbox.paypal.com/v1/billing/plans');
$dataPlan = '{
"product_id": "'.$product.'",
"name": "Monthly Donation",
"description": "'.$amount.$currency.' Monthly Donation",
"billing_cycles": [
{
"frequency": {
"interval_unit": "MONTH",
"interval_count": 1
},
"tenure_type": "REGULAR",
"sequence": 1,
"total_cycles": 12,
"pricing_scheme": {
"fixed_price": {
"value": "'.$amount.'",
"currency_code": "'.$currency.'"
}
}
}
],
"payment_preferences": {
"auto_bill_outstanding": false
}
}';
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','accept: application/json','PayPal-Request-Id: '.$int_donationId,'authorization: Bearer '.$access_token));
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataPlan);
curl_setopt($ch, CURLOPT_SSLCERT, $filepathtocert);
$resultPlan = curl_exec($ch);
$errPlan = curl_error($ch);
curl_close($ch);
if ($errPlan) {
echo 'URL Plan Error #:' . $errPlan;
}else{
// return subscription plan
$jsonPlan = json_decode($resultPlan);
$plan = $jsonPlan->id;
return $plan;
}
json响应缺少帐单周期
{
"id": "P-XXXXXXXXXXXXXXXXXXXXXXXX",
"product_id": "PROD-XXXXXXXXXXXXXXXXX",
"name": "Monthly Donation",
"status": "ACTIVE",
"description": "44EUR Monthly Donation",
"create_time": "2019-07-31T16:11:26Z",
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/billing/plans/P-XXXXXXXXXXXXXXXXXXXXXXXX",
"rel": "self",
"method": "GET"
},
{
"href": "https://api.sandbox.paypal.com/v1/billing/plans/P-XXXXXXXXXXXXXXXXXXXXXXXX",
"rel": "edit",
"method": "PATCH"
},
{
"href": "https://api.sandbox.paypal.com/v1/billing/plans/P-XXXXXXXXXXXXXXXXXXXXXXXX/deactivate",
"rel": "self",
"method": "POST"
}]
}