# PayPal 订阅流程及 API 请求教程 **Published by:** [fengbao](https://paragraph.com/@fengbao/) **Published on:** 2025-01-15 **URL:** https://paragraph.com/@fengbao/paypal-api ## Content 1. PayPal 后台创建产品及计划正式与沙盒环境入口正式环境创建订阅计划沙盒环境创建订阅计划在以上页面中,您可以创建产品和计划,正式环境和沙盒环境的数据相互独立。操作步骤进入对应环境的链接。根据流程逐步填写产品和订阅计划信息。保存设置后,您的订阅计划即可在正式环境中使用。您也可以通过 API 的方式完成产品及计划的创建,以下为详细 API 请求说明。2. 使用 API 创建产品及计划API 文档参考:PayPal REST API 文档2.1 生成 Token通过以下请求获取 Access Token:沙盒环境https://api.sandbox.paypal.com/v1/oauth2/token正式环境https://api.paypal.com/v1/oauth2/token所需的 clientId 和 Secret 可从您的 PayPal 账号中获取。2.2 创建产品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": "https://example.com/streaming.jpg", "home_url": "https://example.com/home" }' 参数说明:name:产品名称description:产品描述type:产品类型(PHYSICAL、DIGITAL 或 SERVICE)category:产品分类image_url:产品图片地址home_url:产品主页地址2.3 创建订阅计划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": "Basic plan for video streaming", "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 } }' 参数说明:product_id:产品 IDname:订阅计划名称status:计划状态(ACTIVE 激活)billing_cycles:计费周期配置,支持试用与常规周期interval_unit:计费周期单位(DAY、WEEK、MONTH、YEAR)interval_count:每个周期的时间间隔pricing_scheme:定价配置payment_preferences:付款偏好配置setup_fee:设置费用payment_failure_threshold:付款失败后暂停订阅的阈值2.4 创建订阅curl -v -X POST https://api-m.sandbox.paypal.com/v1/billing/subscriptions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer <Access-Token>" \ -H "PayPal-Request-Id: SUBSCRIPTION-21092019-001" \ -d '{ "plan_id": "P-5ML4271244454362WXNWU5NQ", "start_time": "2025-07-21T00:00:00Z", "quantity": "20", "application_context": { "brand_name": "Your Brand", "locale": "en-US", "shipping_preference": "SET_PROVIDED_ADDRESS", "user_action": "SUBSCRIBE_NOW", "return_url": "https://example.com/returnUrl", "cancel_url": "https://example.com/cancelUrl" } }' 参数说明:plan_id:订阅计划 IDstart_time:订阅开始时间(ISO8601 格式)quantity:订阅商品数量application_context:用户体验配置return_url:支付成功回调地址cancel_url:支付取消回调地址完成后,通过响应结果中的 links.href,即可跳转到支付订阅页面。3. 配置 WebHook使用 WebHook 接收订阅事件通知:登录 PayPal 开发者后台。创建新的 WebHook,并设置监听的事件类型。确保回调地址可以处理事件响应。通过以上流程,您可以轻松完成 PayPal 产品和订阅计划的配置,并通过 API 实现自动化操作。如果您需要订阅海外服务,推荐使用虚拟信用卡 WildCard,操作简单,支付便捷。 ☞ WildCard | 一分钟注册,轻松订阅海外线上服务 使用邀请码:ACCPAY,立享 0 手续费优惠,支持支付宝充值,随时提现! ## Publication Information - [fengbao](https://paragraph.com/@fengbao/): Publication homepage - [All Posts](https://paragraph.com/@fengbao/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@fengbao): Subscribe to updates