Skip to main content
POST
Attach Plan
Attaches a plan to a customer. Handles new subscriptions, upgrades, downgrades, and add-on products.

Authentication

Requires a valid API secret key in the Authorization header:

Request Body

string
required
The ID of the customer.
string
required
The ID of the plan/product to attach to the customer.
string
The ID of the entity, if attaching the plan to a specific entity.
boolean
If true, creates an invoice for the subscription. Use this for deferred payment flows.
boolean
If true, enables the product immediately even if an invoice is pending payment.
boolean
If true, finalizes the invoice immediately. Only applicable when invoice is true.
string
default:"always"
Controls when to redirect the customer to a checkout page. Options:
  • always: Always redirect to checkout
  • if_required: Only redirect if payment action is required
  • never: Never redirect, handle payment programmatically
string
URL to redirect the customer to after successful payment. Used with redirect_mode.
boolean
If true, creates a new billing subscription even if the customer has an existing one.
object
Schedule when the plan should become active.
number
Timestamp (in milliseconds) when the plan should start.
array
Array of discount objects to apply to the subscription.
string
Stripe coupon ID to apply.
string
Stripe promotion code to apply.
string
Controls billing behavior for plan transitions:
  • prorate_immediately (default): Invoice line items are charged immediately
  • next_cycle_only: Do not create any charges due to the attach
array
Array of feature quantity overrides.
string
The feature ID to configure.
number
The quantity for this feature.
object
Free trial configuration for the subscription.
number
Length of the trial period.
string
Unit of the trial period: day, week, or month.
object
Rules for how to transition between plans.
string
Specific subscription ID to attach the plan to.
array
Array of custom line items to add to the invoice.

Response

string
The ID of the customer.
string
The ID of the entity, if the plan was attached to an entity.
object
Invoice details if an invoice was created. Only present when a charge was made.
string
The status of the invoice (e.g., ‘paid’, ‘open’, ‘draft’).
string
The Stripe invoice ID.
number
The total amount of the invoice in cents.
string
The three-letter ISO currency code (e.g., ‘usd’).
string
URL to the hosted invoice page where the customer can view and pay the invoice.
string
URL to redirect the customer to complete payment. Null if no payment action is required.
object
Details about any action required to complete the payment. Present when the payment could not be processed automatically.
string
The type of action required to complete the payment. One of:
  • 3ds_required: 3D Secure authentication is needed
  • payment_method_required: Customer needs to add a payment method
  • payment_failed: Payment was declined
string
A human-readable explanation of why this action is required.

Example Request

Example Response

Error Responses

object
string
Human-readable error message.
string
Machine-readable error code. Common codes:
  • customer_not_found: The specified customer doesn’t exist
  • product_not_found: The specified product doesn’t exist
  • invalid_inputs: Request validation failed
  • stripe_error: Payment provider error occurred
  • customer_has_no_payment_method: Customer needs to add a payment method

Example Error Response