Attach Plan
Core Endpoints
Attach Plan
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 theAuthorization 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 checkoutif_required: Only redirect if payment action is requirednever: 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
string
Controls billing behavior for plan transitions:
prorate_immediately(default): Invoice line items are charged immediatelynext_cycle_only: Do not create any charges due to the attach
array
object
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 neededpayment_method_required: Customer needs to add a payment methodpayment_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 existproduct_not_found: The specified product doesn’t existinvalid_inputs: Request validation failedstripe_error: Payment provider error occurredcustomer_has_no_payment_method: Customer needs to add a payment method