# PayPal订阅流程与API请求完整指南 **Published by:** [nishi](https://paragraph.com/@nishi/) **Published on:** 2025-01-17 **URL:** https://paragraph.com/@nishi/paypal-api ## Content 1. PayPal后台创建产品与计划要在PayPal创建订阅计划,你可以选择正式环境或沙盒环境来进行设置:正式环境创建订阅计划地址:点击此处沙盒环境创建订阅计划地址:点击此处进入相应页面后,可以开始创建产品和计划。请注意,创建的产品和计划在沙盒环境中不可见。创建产品及计划流程你可以根据页面提供的流程创建产品和计划。 可按流程创建订阅产品和计划。 通过该界面填写详细的产品信息,并进行提交。2. 使用API创建产品与计划API 地址:点击此处1. 生成Access Token首先,你需要在PayPal账号中获取 clientId 和 Secret,然后通过以下请求获取 access_token。沙盒环境请求地址: https://api.sandbox.paypal.com/v1/oauth2/token正式环境请求地址: https://api.paypal.com/v1/oauth2/token2. 创建产品使用以下API调用来创建产品: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-18062025-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: 产品类型 (SERVICE、DIGITAL、PHYSICAL)category: 产品类别image_url: 产品图标home_url: 产品官方网站3. 创建订阅计划在创建产品后,你可以用以下API创建订阅计划: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 } }' product_id: 产品IDname: 计划名称description: 计划说明status: 计划状态 (ACTIVE)billing_cycles: 计费周期设置,包括计费频率和价格4. 创建订阅使用以下API创建订阅: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", "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" } }' 5. 获取订阅详情获取订阅详情信息: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" 6. 配置WebHook你还可以在PayPal中配置WebHook,以便监听事件更新。结语通过以上步骤,你可以方便地在PayPal中创建并管理订阅产品与计划。PayPal API的使用让开发者能够高效地进行订阅系统的集成。希望本篇指南能够帮助你快速掌握PayPal订阅的基本操作。☞ WildCard | 一分钟注册,轻松订阅海外线上服务 使用门槛极低,微信支付宝均可开通使用。支持开通各类海外平台:ChatGPT、Claude、Google Play、Apple Store、OpenAI、X、Patreon、MidJourney、Amazon、POE、Microsoft、Facebook、GitHub、Telegram、PayPal等各类海淘订阅平台。使用邀请码:ACCPAY,立享消费0手续费,减免开卡费用。 ## Publication Information - [nishi](https://paragraph.com/@nishi/): Publication homepage - [All Posts](https://paragraph.com/@nishi/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@nishi): Subscribe to updates