paypal订阅地址:
https://www.paypal.com/merchantapps/appcenter/acceptpayments/subscriptions

点击进去之后可创建产品及计划(此处创建的产品及计划为正式环境计划,沙箱的计划在此处不会显示)

可根据流程可创建产品及计划




也可根据api创建产品及计划
API 地址: https://developer.paypal.com/api/rest/
首先在你的paypal账号里获取你的clientId和Secret,然后再来获取access_token
请求地址:
沙盒: https://api.sandbox.paypal.com/v1/oauth2/token
正式: https://api.paypal.com/v1/oauth2/token
请求例子:
- curl -v -X POST "https://api-m.sandbox.paypal.com/v1/oauth2/token" \
- -u "
:" \ - -H "Content-Type: application/x-www-form-urlencoded" \
- -d "grant_type=client_credentials"
返回结果:
- {
- "scope": "https://uri.paypal.com/services/invoicing https://uri.paypal.com/services/disputes/read-buyer https://uri.paypal.com/services/payments/realtimepayment https://uri.paypal.com/services/disputes/update-seller https://uri.paypal.com/services/payments/payment/authcapture openid https://uri.paypal.com/services/disputes/read-seller https://uri.paypal.com/services/payments/refund https://api-m.paypal.com/v1/vault/credit-card https://api-m.paypal.com/v1/payments/.* https://uri.paypal.com/payments/payouts https://api-m.paypal.com/v1/vault/credit-card/.* https://uri.paypal.com/services/subscriptions https://uri.paypal.com/services/applications/webhooks",
- "access_token": "A21AAFEpH4PsADK7qSS7pSRsgzfENtu-Q1ysgEDVDESseMHBYXVJYE8ovjj68elIDy8nF26AwPhfXTIeWAZHSLIsQkSYz9ifg",
- "token_type": "Bearer",
- "app_id": "APP-80W284485P519543T",
- "expires_in": 31668,
- "nonce": "2020-04-03T15:35:36ZaYZlGvEkV4yVSz8g6bAKFoGSEzuy3CQcz3ljhibkOHg"
- }
请求例子:
- 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: 产品logo
home_url: 产品主站地址 https://www.baidu.com
返回结果:
- {
- "id": "PROD-XYAB12ABSB7868434", ## 产品id 后边会用到
- "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",
- "create_time": "2020-01-10T21:20:49Z",
- "update_time": "2020-01-10T21:20:49Z",
- "links": [
- {
- "href": "https://api-m.paypal.com/v1/catalogs/products/72255d4849af8ed6e0df1173",
- "rel": "self",
- "method": "GET"
- },
- {
- "href": "https://api-m.paypal.com/v1/catalogs/products/72255d4849af8ed6e0df1173",
- "rel": "edit",
- "method": "PATCH"
- }
- ]
- }
请求地址:
- 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:产品id
name: 计划名称
description:计划说明
status:计划状态
billing_cycles:用于试用计费和定期计费的一系列计费周期。一个计划最多可以有两个试用周期和一个常规周期。
frequency:频率
interval_unit:对订阅收费或计费的时间间隔,DAY/WEEK/MONTH/YEAR
interval_count:向订阅者收费的间隔数,1-365
tenure_type:计费周期的任期类型。REGULAR. 定期计费周期。TRIAL. 试用计费周期。
sequence:计费周期顺序(必填)
total_cycles:计费周期执行的次数。试用计费周期(TRIAL)只能执行有限次数,范围1-999;定期计费周期(REGULAR)可以执行无限次,0-999
pricing_scheme:计费周期的主动定价方案。免费试用计费周期不需要定价方案
fixed_price:订阅收取的固定金额
value:金额
currency_code:货币代码
payment_preferences: 订阅的付款首选项
auto_bill_outstanding:是否在下一个计费周期自动计费未结金额
setup_fee:服务的初始设置费
value:金额
currency_code:货币代码
setup_fee_failure_action:如果设置的初始付款失败,则对订阅采取的操作;CONTINUE:如果设置的初始付款失败,则继续订阅。CANCEL:如果设置的初始付款失败,则取消订阅。
payment_failure_threshold:连续x次付款失败,订阅会自动更新到暂停状态
taxes:税
percentage:税百分比,不含税填0
inclusive:税款是否已包含在帐单金额中
返回结果:
- {
- "id": "P-2DN49707R1221304MMLL5H7A",
- "product_id": "PROD-36834256SL5660309",
- "name": "Video Streaming Service Plan",
- "status": "ACTIVE",
- "description": "Video Streaming Service basic plan",
- "usage_type": "LICENSED",
- "billing_cycles": [
- {
- "pricing_scheme": {
- "version": 1,
- "fixed_price": {
- "currency_code": "USD",
- "value": "6.0"
- },
- "create_time": "2022-07-20T10:07:56Z",
- "update_time": "2022-07-20T10:07:56Z"
- },
- "frequency": {
- "interval_unit": "MONTH",
- "interval_count": 1
- },
- "tenure_type": "REGULAR",
- "sequence": 1,
- "total_cycles": 12
- }
- ],
- "payment_preferences": {
- "service_type": "PREPAID",
- "auto_bill_outstanding": true,
- "setup_fee": {
- "currency_code": "USD",
- "value": "6.0"
- },
- "setup_fee_failure_action": "CONTINUE",
- "payment_failure_threshold": 3
- },
- "taxes": {
- "percentage": "0.0",
- "inclusive": false
- },
- "quantity_supported": false,
- "create_time": "2022-07-20T10:07:56Z",
- "update_time": "2022-07-20T10:07:56Z",
- "links": [
- {
- "href": "https://api.sandbox.paypal.com/v1/billing/plans/P-2DN49707R1221304MMLL5H7A",
- "rel": "self",
- "method": "GET",
- "encType": "application/json"
- },
- {
- "href": "https://api.sandbox.paypal.com/v1/billing/plans/P-2DN49707R1221304MMLL5H7A",
- "rel": "edit",
- "method": "PATCH",
- "encType": "application/json"
- },
- {
- "href": "https://api.sandbox.paypal.com/v1/billing/plans/P-2DN49707R1221304MMLL5H7A/deactivate",
- "rel": "self",
- "method": "POST",
- "encType": "application/json"
- }
- ]
- }
请求地址:
- curl -v -X GET https://api-m.sandbox.paypal.com/v1/billing/plans/P-5ML4271244454362WXNWU5NQ \
- -H "Content-Type: application/json" \
- -H "Authorization: Bearer Access-Token"
请求地址:
- 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": "2022-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"
- }
- }'
plan_id: 计划id
start_time: 该值实际上设置的是第二次扣款时间 ISO8601时间
quantity: 订阅中的产品数量
shipping_amount: 交易的货币和金额
currency_code: 货币代码
value: 金额
application_context:
brand_name:
locale:
shipping_preference:
user_action: CONTINUE. 将客户重定向到 PayPal 订阅同意页面后,会出现一个继续按钮。如果您想控制订阅的激活并且不希望 PayPal 激活订阅,请使用此选项;SUBSCRIBE_NOW. 在您将客户重定向到 PayPal 订阅同意页面后,会出现立即订阅按钮。如果您希望 PayPal 激活订阅,请使用此选项。
payment_method: 付款方式
payer_selected: 商家网站上客户选择的付款方式
payee_preferred: UNRESTRICTED. 接受客户的任何类型的付款;IMMEDIATE_PAYMENT_REQUIRED. 只接受客户的即时付款。例如,信用卡、PayPal 余额或即时 ACH。确保在捕获时,付款不处于“待处理”状态。
return_url: 支付成功地址
cancel_url: 支付取消地址
返回结果:
- {
- "status": "APPROVAL_PENDING",
- "id": "I-BW452GLLEP1G",
- "create_time": "2022-07-20T12:04:00Z",
- "links": [
- {
- "href": "https://www.paypal.com/webapps/billing/subscriptions?ba_token=BA-2M539689T3856352J",
- "rel": "approve",
- "method": "GET"
- },
- {
- "href": "https://api.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G",
- "rel": "edit",
- "method": "PATCH"
- },
- {
- "href": "https://api.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G",
- "rel": "self",
- "method": "GET"
- }
- ]
- }
根据获取的结果选择"links"下第一个"href"去支付订阅
请求地址:
- 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"
https://developer.paypal.com/developer/applications
此处选择的为,仅为个人选择
事件说明:https://developer.paypal.com/api/rest/webhooks/event-names/#subscriptions
PAYMENT SALE COMPLETED: 对订阅进行付款
BILLING SUBSCRIPTION EXPIRED:订阅到期。
BILLING SUBSCRIPTION CANCELLED: 订阅被取消
BILLING SUBSCRIPTION SUSPENDED : 订阅被暂停
BILLING SUBSCRIPTION ACTIVATED: 订阅已激活