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.
Note:
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 {#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.
Important
- 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.id that matches the value Apple-App-Store, and create such a product family if not found.
- Look for item.id that matches
product[id]
and if not found, create such a plan-item under the item family described in the previous step. - Look for item_price.id that matches the concatenation of
product[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:
id
set to original_transaction_idstart_date
set to responseBody.Latest_receipt_info.purchase_date_mscurrent_term_end
set 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.
- 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:
- The payment is recorded against the subscription invoice. The associated transaction is updated with the following details:
- The transaction.reference_number is set to the transaction_id of the payment.
- The transaction.payment_method is set to
apple_pay
.
Google Play Store {#app_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.
Important
- 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.id that matches the value
Google-Play-Store
, and create such a product family if not found. - Look for item.id that matches
product[id]
and if not found, create such a plan-item under the item family described in the previous step. - Look for item_price.id that matches the concatenation of
product[id]
and priceCurrencyCode, 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:
id
set to unique identifier generated by Chargebee and mapped to token of the SubscriptionPurchase object from Google response.start_date
set toSubscriptionPurchase.startTimeMillis
.current_term_end
set 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.
- 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:
- The payment is recorded against the subscription invoice. The associated transaction is updated with the following details:
- The transaction.reference_number is set to the orderId of the payment.
- The transaction.payment_method is set to
play_store
.
Path Parameter {#path_param_pcv2}
{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 Possible 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 Possible 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-event-email |
String | No |
skip only emails Possible values:
|
Request body fields
Name | Type | Required | Description |
---|---|---|---|
customer |
Object | No |
Parameters for customer |
customer.id |
String | No |
Google Play Store : The unique id in Chargebee for the customer who made this purchase via Google Play Store. If not provided, Apple App Store : The unique id in Chargebee for the customer who made this purchase. If not provided, the value is considered to be original_transaction_id (the transaction identifier at Apple, of the original purchase). If the customer record is not found in Chargebee, it is created. |
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 |
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
|
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, 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.