POST /customers/{customer-id}/assign_payment_role
Assign or unassign the primary or backup payment role for a payment source.
Set role when creating a payment source
You can also assign a payment source as primary when you create it using APIs such as:
- Create a payment source using payment intent
- Create a payment source using temporary token
- Create a payment source using permanent token
Payment collection precedence
Chargebee uses the following precedence to determine which payment source to use when it collects payments for a subscription:
- The payment source attached to the subscription, if available.
- The primary payment source of the customer.
- The backup payment source of the customer, if available.
Prerequisites & Constraints
- The payment source must belong to the customer and must not be
deleted. - The payment source must not be the current primary payment source of the customer.
- This operation doesn't validate the
statusof the payment source. Check thestatusof the payment source before you assign it to the primary or backup role.
Impacts
Payment collection
The roles that you set using this API apply to all payments collected for the customer, except for subscriptions that have a payment source attached to them. Chargebee continues to collect such payments using the payment source attached to the subscription.
Customer
- When you assign a payment source as primary, Chargebee unassigns the existing primary payment source and doesn't affect the backup payment source.
- When you assign a payment source as backup, Chargebee unassigns the existing backup payment source and doesn't affect the primary payment source.
- You can set the role of a
backuppayment source toprimaryornone. - You cannot set the role of a
primarypayment source to eitherbackupornone.
Implementation Notes
Before you call this API, ensure the following:
- The
payment_source.customer_idmatches theidof the customer. - The
payment_source_idisn't the same as thecustomer.primary_payment_source_id. - Since this API doesn't validate the
statusof the payment source, check thepayment_source.statusto ensure it isn'texpired,invalid, orpending_verification.
Servers
- {protocol}://{site}.{environment}:{port}/api/v2
- {protocol}://{site}-test.{environment}:{port}/api/v2
Path parameters
| Name | Type | Required | Description |
|---|---|---|---|
customer-id |
String | Yes |
Request headers
| Name | Type | Required | Description |
|---|---|---|---|
chargebee-request-origin-device |
String | No |
The device from which the customer has made the request |
Content-Type |
String | Yes |
The media type of the request body.
Default value: "application/x-www-form-urlencoded" |
chargebee-event-webhook |
String | No |
skip only webhooks Valid values:
|
chargebee-business-entity-id |
String | No |
If the site has multiple business entities, you can use this custom HTTP header to specify the business entity for which Chargebee should perform the operation. |
chargebee-event-actions |
String | No |
skip all actions to be done on the events Valid values:
|
chargebee-request-origin-user |
String | No |
The email address of your customer/user. Use this when the email address has only ASCII characters. |
chargebee-request-origin-ip |
String | No |
The IP address of the customer where the request originated |
chargebee-request-origin-user-encoded |
String | No |
The Base64-encoded email address of your customer/user. Use this if the email address has UTF-8 characters. When this header is provided, the header chargebee-request-origin-user is ignored. |
chargebee-event-email |
String | No |
skip only emails Valid values:
|
Request body fields
| Name | Type | Required | Description |
|---|---|---|---|
payment_source_id |
String | Yes |
Payment source id this role will be assigned to. |
role |
String | Yes |
Indicates whether the payment source is Primary, Backup, or neither. * backup - Backup * none - None * primary - Primary Valid values:
|
How to start integrating
- Add HTTP Task to your workflow definition.
- Search for the API you want to integrate with and click on the name.
- This loads the API reference documentation and prepares the Http request settings.
- Click Test request to test run your request to the API and see the API's response.