本文将详细介绍如何在 PayPal 后台创建订阅产品及计划,并通过 API 实现相关操作。无论是正式环境还是沙盒环境,本文都将为您提供清晰的步骤和代码示例。
访问以下地址创建订阅计划:
https://www.paypal.com/merchantapps/appcenter/acceptpayments/subscriptions
沙盒环境创建订阅计划地址:
https://www.sandbox.paypal.com/billing/plans
进入页面后,您可以根据流程创建产品及计划。请注意,沙盒环境中的计划不会在正式环境中显示。
访问 PayPal 开发者中心获取 API 文档:
https://developer.paypal.com/api/rest/
首先,在 PayPal 账号中获取 clientId 和 Secret,然后通过以下地址获取 access_token:
使用以下代码示例创建产品:
bash
curl -v -X POST https://api-m.sandbox.paypal.com/v1/catalogs/products
-H "Content-Type: application/json"
-H "Authorization: Bearer Access-Token"
-H "PayPal-Request-Id: PRODUCT-18062020-001"
-d '{
"name": "Video Streaming Service",
"description": "Video streaming service",
"type": "SERVICE",
"category": "SOFTWARE",
"image_url": "",
"home_url": "https://example.com/home"
}'
使用以下代码示例创建计划:
bash
curl -v -X POST https://api-m.sandbox.paypal.com/v1/billing/plans
-H "Content-Type: application/json"
-H "Authorization: Bearer Access-Token"
-H "PayPal-Request-Id: PLAN-18062019-001"
-d '{
"product_id": "PROD-XXCD1234QWER65782",
"name": "Video Streaming Service Plan",
"description": "Video Streaming Service basic plan",
"status": "ACTIVE",
"billing_cycles": [
{
"frequency": {
"interval_unit": "MONTH",
"interval_count": 1
},
"tenure_type": "REGULAR",
"sequence": 1,
"total_cycles": 12,
"pricing_scheme": {
"fixed_price": {
"value": "6",
"currency_code": "USD"
}
}
}
],
"payment_preferences": {
"auto_bill_outstanding": true,
"setup_fee": {
"value": "6",
"currency_code": "USD"
},
"setup_fee_failure_action": "CONTINUE",
"payment_failure_threshold": 3
},
"taxes": {
"percentage": "0",
"inclusive": false
}
}'
使用以下代码示例创建订阅:
bash
curl -v -X POST https://api-m.sandbox.paypal.com/v1/billing/subscriptions
-H "Content-Type: application/json"
-H "Authorization: Bearer "
-H "PayPal-Request-Id: SUBSCRIPTION-21092019-001"
-d '{
"plan_id": "P-5ML4271244454362WXNWU5NQ",
"start_time": "2025-07-21T00:00:00Z",
"quantity": "20",
"shipping_amount": {
"currency_code": "USD",
"value": "10.00"
},
"application_context": {
"brand_name": "walmart",
"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://example.com/returnUrl",
"cancel_url": "https://example.com/cancelUrl"
}
}'
使用以下代码获取订阅详情:
bash
curl -v -X GET https://api-m.sandbox.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G
-H "Content-Type: application/json"
-H "Authorization: Bearer Access-Token"
在 PayPal 后台配置 WebHook,以接收订阅相关的事件通知。具体配置步骤请参考 PayPal 官方文档。
👉 野卡 WildCard | 一分钟注册,轻松订阅海外线上服务
通过以上步骤,您可以轻松地在 PayPal 后台创建订阅产品及计划,并通过 API 实现自动化操作。希望本文对您有所帮助!