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_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.

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.

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

Subscriptions are imported as follows:

  1. A subscription is imported for every unique value of the original_transaction_id in the Apple receipt.Note: This is not done for original_transaction_ids for which a subscription already exists in Chargebee.
  2. Each subscription imported has the following attributes set:
    • id set to original_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 same Latest_receipt_info element with the latest purchase_date_ms.
    • item_price_id set to product_id.
    • status set to in_trial if there is only one element of Latest_receipt_info with the original_transaction_id and the field is_trial_period is true, then consider the subscription is currently in trial. No invoices are created for this subscription.

Invoices for the subscription

Invoices are imported as follows:

  1. An invoice is imported to Chargebee for every element of the array Latest_receipt_info which has is_trial_period as false.
  2. Each imported invoice has the subscription_id set to original_transaction_id.

Transactions for the invoices

A transaction is imported for each invoice with the following details:

  1. reference_number set to the transaction_id.
  2. payment_method set to apple_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 purchase token is passed instead of the latest one, there is a possibility of returning incorrect transaction details. If an expired purchase token 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

  • A subscription is imported for every unique purchase token if it is not linked to an existing purchase token( linkedPurchaseToken field in SubscriptionsV2.get API Response).

  • Each subscription imported has the following attributes set:

    • id set to a unique identifier generated by Chargebee and mapped to the token and latestOrderId of the SubscriptionPurchaseV2 object from Google response.

    • start_date set to the earliest SubscriptionPurchaseV2.startTime.

    • current_term_start set to latest SubscriptionPurchaseV2.startTime.

    • current_term_end set to expiryTime of the same SubscriptionPurchaseV2 element with the latest purchase.

    • item_price_id set to the concatenation of product[id] and priceCurrencyCode from Google.

    • status set to in_trial if the free trial configuration is enabled in Google and the monetization.subscriptions.basePlans.offers.State is Active 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 the token and latestOrderId.

Transactions for the invoices

A transaction is imported for each invoice with the following details:

  • transaction.reference_number is set to the latestOrderId.

  • transaction.payment_method is set to play_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.

Servers

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:

  • "all-disabled"
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:

  • "all-disabled"
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:

  • "all-disabled"

Request body fields

Name Type Required Description
customer Object No

Parameters for customer

customer.id String No

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.

Google Play Store: The unique id of the customer who made this purchase via Google Play Store. This unique id will be used as customer ID within Chargebee. If not provided, subscription_id (random unique id) will be the customer ID. If the customer ID already exists in Chargebee then subscription will be associated with this customer ID.

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 token taken from the Android device after the successful creation of an in-app purchase subscription.

How to start integrating

  1. Add HTTP Task to your workflow definition.
  2. 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.
  3. Click Test request to test run your request to the API and see the API's response.