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
An in_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_id
s. If a receipt contains more than 100 original_transaction_id
s, 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.
Note : This API verifies receipt or token through Apple or Google and then processes them via Chargebee. For bulk imports, limit API calls to 6 per minute (10 seconds apart) to ensure successful subscription imports.
Apple App Store {#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.
Important
- 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 {#ir_apple_app_store_pcv2}
Subscriptions are imported as follows:
- A subscription is imported for every unique value of the original_transaction_id in the Apple receipt.
Note : This is not done fororiginal_transaction_id
s for which a subscription already exists in Chargebee. - Each subscription imported has the following attributes set:
id
set tooriginal_transaction_id
.start_date
set to the earliest purchase_date_ms.current_term_start
set to latest purchase_date_ms.current_term_end
set to expires_date_ms of the sameLatest_receipt_info
element with the latestpurchase_date_ms
.item_price_id
set toproduct_id
.status
set toin_trial
if there is only one element of Latest_receipt_info with theoriginal_transaction_id
and the fieldis_trial_period
istrue
, 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_info which has is_trial_period as
false
. - Each imported invoice has the
subscription_id
set tooriginal_transaction_id
.
Transactions for the invoices
A transaction is imported for each invoice with the following details:
reference_number
set to thetransaction_id
.payment_method
set toapple_store
.
Google Play Store {#app_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.
Important
- 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 purchasetoken
is passed instead of the latest one, there is a possibility of returning incorrect transaction details. If an expired purchasetoken
is passed, then it returns an error. - The Google purchase token is valid from subscription signup until 60 days after subscription expiration. After the
token
expires, 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 {#ir_google_play_store_pcv2}
-
A subscription is imported for every unique purchase token if it is not linked to an existing purchase
token
(linkedPurchaseToken
field inSubscriptionsV2.get
API Response). -
Each subscription imported has the following attributes set:
-
id
set to a unique identifier generated by Chargebee and mapped to thetoken
andlatestOrderId
of theSubscriptionPurchaseV2
object from Google response. -
start_date
set to the earliestSubscriptionPurchaseV2.startTime
. -
current_term_start
set to latestSubscriptionPurchaseV2.startTime
. -
current_term_end
set toexpiryTime
of the sameSubscriptionPurchaseV2
element with the latest purchase. -
item_price_id
set to the concatenation ofproduct[id]
andpriceCurrencyCode
from Google. -
status
set toin_trial
if the free trial configuration is enabled in Google and the monetization.subscriptions.basePlans.offers.State isActive
with a SubscriptionOfferPhase.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_id
set to a unique identifier generated by Chargebee and mapped to thetoken
andlatestOrderId
.
Transactions for the invoices
A transaction is imported for each invoice with the following details:
-
transaction.reference_number
is set to thelatestOrderId
. -
transaction.payment_method
is set toplay_store
.
Path Parameter {#path_param}
{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 |
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.