POST /in_app_subscriptions/{in-app-subscription-app-id}/import_receipt
Verifies an Apple App Store or Google Play Store in-app purchase receipt and imports subscriptions for all historical purchases made by the customer.
Tip
Anin_app_subscription is created for every unique original_transaction_id. Apple creates original_transaction_id for every create, upgrade, or downgrade of the subscription. A receipt hardly contains more than 100 original_transaction_ids. If a receipt contains more than 100 original_transaction_ids, Chargebee creates all subscription records but this endpoint returns the first 100 records in the response. CSV upload has a file size limitation that increases the processing time and the number of receipts. This API removes such limitations and allows you to import historical in-app subscription receipts.
Apple App Store
This section provides details of the Import Receipt operation performed for the Apple App Store. This API processes only the historical in-app transaction receipts.
- Integrate Chargebee with your Apple App Store account using your shared secret from Apple.
- It is strongly recommended to use this endpoint to import historical in-app subscriptions only.
- You must import Apple App Store products using Chargebee's user interface before importing receipts using this API.
Chargebee validates the receipt with Apple App Store and does the following once validation succeeds:
Subscriptions
Subscriptions are imported as follows:
- A subscription is imported for every unique value of the
original_transaction_idin the Apple receipt.Note: This is not done fororiginal_transaction_ids for which a subscription already exists in Chargebee. - Each subscription imported has the following attributes set:
idset tooriginal_transaction_id.start_dateset to the earliestpurchase_date_ms.current_term_startset to latestpurchase_date_ms.current_term_endset toexpires_date_msof the sameLatest_receipt_infoelement with the latestpurchase_date_ms.item_price_idset toproduct_id.statusset toin_trialif there is only one element ofLatest_receipt_infowith theoriginal_transaction_idand the fieldis_trial_periodistrue, then consider the subscription is currently in trial. No invoices are created for this subscription.
Invoices for the subscription
Invoices are imported as follows:
- An invoice is imported to Chargebee for every element of the array
Latest_receipt_infowhich hasis_trial_periodasfalse. - Each imported invoice has the
subscription_idset tooriginal_transaction_id.
Transactions for the invoices
A transaction is imported for each invoice with the following details:
reference_numberset to thetransaction_id.payment_methodset toapple_store.
Google Play Store
This section provides details of the Import Receipt operation performed for the Google Play Store. This API is used to process only the historical in-app purchase subscriptions.
- Integrate Chargebee with your Google Play Store account using your service account credentials JSON.
- It is strongly recommended to use this endpoint to import historical in-app subscriptions only.
- It is recommended to pass only the latest purchase
token. If any other purchasetokenis passed instead of the latest one, there is a possibility of returning incorrect transaction details. If an expired purchasetokenis passed, then it returns an error. - The Google purchase token is valid from subscription signup until 60 days after subscription expiration. After the
tokenexpires, an API request to Google Developers API returns an error.
Chargebee validates the purchase token with Google Play Store and does the following once validation succeeds:
Subscriptions
-
A subscription is imported for every unique purchase token if it is not linked to an existing purchase
token(linkedPurchaseTokenfield inSubscriptionsV2.getAPI Response). -
Each subscription imported has the following attributes set:
-
idset to a unique identifier generated by Chargebee and mapped to thetokenandlatestOrderIdof theSubscriptionPurchaseV2object from Google response. -
start_dateset to the earliestSubscriptionPurchaseV2.startTime. -
current_term_startset to latestSubscriptionPurchaseV2.startTime. -
current_term_endset toexpiryTimeof the sameSubscriptionPurchaseV2element with the latest purchase. -
item_price_idset to the concatenation ofproduct[id]andpriceCurrencyCodefrom Google. -
statusset toin_trialif the free trial configuration is enabled in Google and themonetization.subscriptions.basePlans.offers.StateisActivewith aSubscriptionOfferPhase.duration, then consider the subscription is currently in trial. No invoices are created for this subscription.
-
Invoices for the subscription
Invoices are imported as follows:
-
An invoice is imported to Chargebee for every new subscription and renewal of an existing subscription using
latestOrderId. -
Each imported invoice has the
subscription_idset to a unique identifier generated by Chargebee and mapped to thetokenandlatestOrderId.
Transactions for the invoices
A transaction is imported for each invoice with the following details:
-
transaction.reference_numberis set to thelatestOrderId. -
transaction.payment_methodis set toplay_store.
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 |
Apple App Store: The unique Google Play Store: The unique |
customer.email |
String | No |
Apple App Store: The email ID of the customer who made this purchase. Google Play Store: The email ID of the customer who made this purchase. |
product |
Object | No |
Parameters for product |
product.currency_code |
String | Yes |
Apple App Store : The currency code (ISO 4217 format) for the product. Google Play Store : This parameter is not applicable to the Google Play Store. If the value is passed, it will return a validation error. |
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.