POST /in_app_subscriptions/{in-app-subscription-app-id}/process_purchase_command
Verifies an in-app purchase made by your customer and creates a subscription in Chargebee.
If App Store or Play Store products have not been imported to Chargebee and this API is invoked, Chargebee will automatically create plans that correspond to the store product IDs. However, if historical subscriptions are to be imported using the import receipt API, importing products is mandatory. Learn more.
Apple App Store
This section provides details of the Process Purchase Command operation when performed for the Apple App Store. This API processes only the latest in-app transaction on the receipt. Sync historical subscriptions into Chargebee using bulk import of In-App Purchase receipts.
- Integrate Chargebee with your Apple App Store account using your shared secret from Apple.
- It is strongly recommended to use this endpoint to notify Chargebee of new purchases only.
- For updates to existing subscriptions, we recommend that you configure Apple App Store to send server notifications to Chargebee.
Chargebee validates the receipt with Apple App Store and does the following once validation succeeds:
- Look for
item_family.idthat matches the value Apple-App-Store, and create such a product family if not found. - Look for
item.idthat matchesproduct[id]and if not found, create such a plan-item under the item family described in the previous step. - Look for
item_price.idthat matches the concatenation ofproduct[id]andproduct[currency_code], and if not found, create such an item price under the item described in the previous step. - Create/update a subscription:
- If the receipt is for a new purchase, a new subscription is created for the plan-item price described in the previous step. The subscription has the following details:
idset tooriginal_transaction_idstart_dateset toresponseBody.Latest_receipt_info.purchase_date_mscurrent_term_endset toresponseBody.Latest_receipt_info.expires_date_ms
- Instead, if the receipt belongs to an existing subscription in Chargebee, it is updated to reflect the current state of the subscription at Apple.
- The payment is recorded against the subscription invoice. The associated transaction is updated with the following details:
- The
transaction.reference_numberis set to thetransaction_idof the payment. - The
transaction.payment_methodis set toapple_pay.
- The
Google Play Store
This section provides details of the Process Purchase Command operation when performed for the Google Play Store. This API processes only the latest in-app transaction using the purchase token.
- Integrate Chargebee with your Google Play Store account using the service account credentials JSON.
- It is strongly recommended to use this endpoint to notify Chargebee of new purchases only.
- For updates to existing subscriptions, we recommend that you configure Chargebee to receive Google’s server notifications through pub/sub topic. Learn more.
Chargebee validates the purchase token with Google Play Store and does the following once validation succeeds:
- Look for
item_family.idthat matches the valueGoogle-Play-Store, and create such a product family if not found. - Look for
item.idthat matchesproduct[id]and if not found, create such a plan-item under the item family described in the previous step. - Look for
item_price.idthat matches the concatenation ofproduct[id]andpriceCurrencyCode, and if not found, create such an item price under the item described in the previous step. - Create/update a subscription:
- If this token is for a new purchase, a new subscription is created for the plan-item price described in the previous step. The subscription has the following details:
idset to unique identifier generated by Chargebee and mapped to token of theSubscriptionPurchaseobject from Google response.start_dateset toSubscriptionPurchase.startTimeMillis.current_term_endset toSubscriptionPurchase.expiryTimeMillis.
- Instead, if the token belongs to an existing subscription in Chargebee, it is updated to reflect the current state of the subscription at Google.
- The payment is recorded against the subscription invoice. The associated transaction is updated with the following details:
- The
transaction.reference_numberis set to theorderIdof the payment. - The
transaction.payment_methodis set toplay_store.
- The
Path Parameter
{in_app_subscription_app_id}: The handle created by Chargebee for your Apple App Store or Google Play Store app. It can be obtained from the Chargebee web app.
The following are instructions to obtain the value of the path parameter for the Apple App Store and Google Play Store.
- Apple App Store: To obtain the value for
{in_app_subscription_app_id}, click View Keys within the Sync Overview page of the web app and use the value of generated App ID for this parameter. See detailed steps here. - Google Play Store: To obtain the value for
{in_app_subscription_app_id}, click Set up notifications within the Sync Overview page of the web app and use the value of generated App ID for this parameter. See detailed steps here.
Servers
- {protocol}://{site}.{environment}:{port}/api/v2
- {protocol}://{site}-test.{environment}:{port}/api/v2
Path parameters
| Name | Type | Required | Description |
|---|---|---|---|
in-app-subscription-app-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 |
|---|---|---|---|
customer |
Object | No |
Parameters for customer |
customer.id |
String | No |
Google Play Store: The unique Apple App Store: The unique |
customer.email |
String | No |
The email address of the customer who made the purchase. |
customer.last_name |
String | No |
The last name of the customer who made the purchase. |
customer.first_name |
String | No |
The first name of the customer who made the purchase. |
product |
Object | No |
Parameters for product |
product.id |
String | Yes |
Google Play Store: The unique identifier of the product purchased. The value of this parameter is the Note: The Apple App Store: The unique identifier (created in App Store Connect) of the product purchased.
max chars limit is 95 for Google Play Store. |
product.price_in_decimal |
String | No |
Google Play Store: This parameter is not applicable to the Google Play Store. If the value is passed, it will return a validation error. Apple App Store: The price paid by the customer for the product. The value is in decimal and in major units of the currency. Provide either this or |
product.price |
Integer | Yes |
Google Play Store: This parameter is not applicable to the Google Play Store. If the value is passed, it will return a validation error. Apple App Store: The price paid by the customer for this product. The unit depends on the type of currency. Provide either this or Note:
|
product.period_unit |
String | No |
Google Play Store: This parameter is not applicable to the Google Play Store. If the value is passed, it will return a validation error. Apple App Store: This is the unit of the renewal period. For example, Note Since the Apple App Store receipt does not have the subscription renewal period information for trial subscriptions, |
product.name |
String | No |
Google Play Store: The name (created in Play Store Console) of the product purchased. If not passed then the Apple App Store: The name (created in App Store Connect) of the product purchased. |
product.currency_code |
String | Yes |
Google Play Store : This parameter is not applicable to the Google Play Store. If the value is passed, it will return a validation error. Apple App Store: The currency code (ISO 4217 format) for the product. |
product.period |
String | No |
Google Play Store: This parameter is not applicable to the Google Play Store. If the value is passed, it will return a validation error. Apple App Store: This is the renewal period of the subscription. For example, 1, 2, 3, and so on. This is an |
receipt |
String | Yes |
Apple App Store: The Base64 encoded App Store in-app purchase receipt taken from the Apple device after successful creation of the in-app purchase subscription. Google Play Store: The purchase |
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.