Paypal API
  1. Subscriptions
Paypal API
  • Authorization
    • Generate access_token
      POST
    • Terminate access_token
      POST
    • User Info
      GET
    • Generate client_token
      POST
  • Orders
    • Create order
      POST
    • Show order details
      GET
    • Update order
      PATCH
    • Authorize payment for order
      POST
    • Capture payment for order
      POST
  • Payments
    • Show details for authorized payment
      GET
    • Reauthorize authorized payment
      POST
    • Void authorized payment
      POST
    • Capture authorized payment
      POST
    • Show captured payment details
      GET
    • Refund captured payment
      POST
    • Show refund details
      GET
  • Invoices
    • Invoices
      • Generate invoice number
      • Create draft invoice
      • Show invoice details
      • List invoices
      • Generate QR code
      • Fully update invoice
      • Send invoice
      • Send invoice reminder
      • Cancel sent invoice
      • Delete invoice
      • Search for invoices
      • Record payment for invoice
      • Delete external payment
      • Record refund for invoice
      • Delete external refund
    • Templates
      • List templates
      • Create template
      • Show template details
      • Fully update template
      • Delete template
  • Subscriptions
    • Catalog Products
      • Create product
      • List products
      • Show product details
      • Update product
    • Plans
      • Create plan
      • List plans
      • Show plan details
      • Update plan
      • Deactivate plan
      • Activate plan
      • Update pricing
    • Subscriptions
      • Create subscription
        POST
      • Show subscription details
        GET
      • Update subscription
        PATCH
      • Revise plan or quantity of subscription
        POST
      • Suspend subscription
        POST
      • Activate subscription
        POST
      • Cancel subscription
        POST
      • Capture authorized payment on subscription
        POST
      • List transactions for subscription
        GET
  • Payouts
    • Create batch payout
    • Show payout batch details
    • Show payout item details
    • Cancel unclaimed payout item
  • Webhooks
    • List available events
    • Create webhook
    • List webhooks
    • Show webhook details
    • List event notifications
    • List event subscriptions for webhook
    • Show event notification details
    • Trigger a sample event
    • Verify webhook signature
    • Resend event notification
    • Simulate webhook event
    • Update webhook
    • Delete webhook
  • Shipment Tracking
    • Add tracking information for multiple PayPal transactions
    • Show tracking information
    • Update or cancel tracking information for PayPal transaction
  • Transaction Search
    • List transactions
    • List all balances
  • Disputes
    • List disputes
    • Show dispute details
    • Accept claim
    • Appeal dispute
    • Settle dispute
    • Update dispute status
    • Make offer to resolve dispute
    • Provide evidence
    • Acknowledge returned item
    • Provide supporting information for dispute
    • Escalate dispute to claim
    • Accept offer to resolve dispute
    • Send message about dispute to other party
    • Deny offer to resolve dispute
    • Partially update dispute
  • Onboarding (Limited Release)
    • Manage Accounts
      • Create managed account
      • Search managed account through external id
      • Search managed account by Seller Id
      • Partially updates information for a managed account
      • Shows collection of registered wallet domains
  1. Subscriptions

Create subscription

POST
/v1/billing/subscriptions
Creates a subscription.

请求参数

Authorization
在 Header 添加参数
Authorization
,其值为在 Basic 之后拼接空格,以及经过 Base64 编码的 username:password
示例:
Authorization: Basic *****************
Header 参数
Content-Type
string 
必需
The Content-Type header field is used to specify the nature of the data in the body of an entity. PayPal REST APIs support application/json.
示例值:
application/json
PayPal-Request-Id
string 
必需
The server stores keys for 72 hours.
示例值:
{{$guid}}
Prefer
string 
必需
The preferred server response upon successful completion of the request. Value is:
  • return=minimal. The server returns a minimal response to optimize communication between the API caller and the server. A minimal response includes the id, status and HATEOAS links.
  • return=representation. The server returns a complete resource representation, including the current state of the resource.
示例值:
{{prefer_representation_detailed}}
Body 参数application/json
plan_id
string 
必需
start_time
string 
必需
shipping_amount
object 
必需
currency_code
string 
必需
value
string 
必需
subscriber
object 
必需
name
object 
必需
email_address
string 
必需
shipping_address
object 
必需
application_context
object 
必需
brand_name
string 
必需
locale
string 
必需
shipping_preference
string 
必需
user_action
string 
必需
payment_method
object 
必需
return_url
string 
必需
cancel_url
string 
必需
示例
{
  "plan_id": "{{billing_plan_id}}",
  "start_time": "{{tomorrow}}",
  "shipping_amount": {
    "currency_code": "USD",
    "value": "10.00"
  },
  "subscriber": {
    "name": {
      "given_name": "FooBuyer",
      "surname": "Jones"
    },
    "email_address": "foobuyer@example.com",
    "shipping_address": {
      "name": {
        "full_name": "John Doe"
      },
      "address": {
        "address_line_1": "2211 N First Street",
        "address_line_2": "Building 17",
        "admin_area_2": "San Jose",
        "admin_area_1": "CA",
        "postal_code": "95131",
        "country_code": "US"
      }
    }
  },
  "application_context": {
    "brand_name": "Example Inc",
    "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/return",
    "cancel_url": "https://example.com/cancel"
  }
}

示例代码

Shell
JavaScript
Java
Swift
Go
PHP
Python
HTTP
C
C#
Objective-C
Ruby
OCaml
Dart
R
请求示例请求示例
Shell
JavaScript
Java
Swift
curl --location --request POST 'https://api-m.sandbox.paypal.com/v1/billing/subscriptions' \
--header 'PayPal-Request-Id: ' \
--header 'Prefer: ' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic Og==' \
--data-raw '{
    "plan_id": "{{billing_plan_id}}",
    "start_time": "{{tomorrow}}",
    "shipping_amount": {
        "currency_code": "USD",
        "value": "10.00"
    },
    "subscriber": {
        "name": {
            "given_name": "FooBuyer",
            "surname": "Jones"
        },
        "email_address": "foobuyer@example.com",
        "shipping_address": {
            "name": {
                "full_name": "John Doe"
            },
            "address": {
                "address_line_1": "2211 N First Street",
                "address_line_2": "Building 17",
                "admin_area_2": "San Jose",
                "admin_area_1": "CA",
                "postal_code": "95131",
                "country_code": "US"
            }
        }
    },
    "application_context": {
        "brand_name": "Example Inc",
        "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/return",
        "cancel_url": "https://example.com/cancel"
    }
}'

返回响应

🟢201201 - Create Subscription With Minimal Request
application/json
Body
status
string 
必需
status_update_time
string 
必需
id
string 
必需
plan_id
string 
必需
start_time
string 
必需
quantity
string 
必需
subscriber
object 
必需
create_time
string 
必需
plan_overridden
boolean 
必需
links
array [object {3}] 
必需
href
string 
必需
rel
string 
必需
method
string 
必需
示例
{
  "status": "APPROVAL_PENDING",
  "status_update_time": "2023-04-10T16:57:03Z",
  "id": "I-3K9N0AULDABT",
  "plan_id": "P-3U540844AX2546419MQYHLVQ",
  "start_time": "2023-04-10T16:57:03Z",
  "quantity": "1",
  "subscriber": {},
  "create_time": "2023-04-10T16:57:03Z",
  "plan_overridden": false,
  "links": [
    {
      "href": "https://www.sandbox.paypal.com/webapps/billing/subscriptions?ba_token=BA-6NS85567LW887234V",
      "rel": "approve",
      "method": "GET"
    },
    {
      "href": "https://api-m.sandbox.paypal.com/v1/billing/subscriptions/I-3K9N0AULDABT",
      "rel": "edit",
      "method": "PATCH"
    },
    {
      "href": "https://api-m.sandbox.paypal.com/v1/billing/subscriptions/I-3K9N0AULDABT",
      "rel": "self",
      "method": "GET"
    }
  ]
}
🟢201201 - Create Subscription With Detailed Request
🟠400400 Bad Request - Invalid Parameter Value
🟠401401 Unauthorized - Invalid Token
🟠404404 Not Found - Billing Plan Not Found
🟠422422 Unprocessable Entity - Subscription Can Not Have Quantity
修改于 2023-08-16 07:18:59
上一页
Update pricing
下一页
Show subscription details
Built with