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

Chargebee validates the receipt with Apple App Store and does the following once validation succeeds:

  1. Look for item_family.id that matches the value Apple-App-Store, and create such a product family if not found.
  2. 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.
  3. Look for item_price.id that matches the concatenation of product[id] and product[currency_code], and if not found, create such an item price under the item described in the previous step.
  4. 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_id
      • start_date set to responseBody.Latest_receipt_info.purchase_date_ms
      • current_term_end set to responseBody.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.
  5. 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.

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

Chargebee validates the purchase token with Google Play Store and does the following once validation succeeds:

  1. Look for item_family.id that matches the value Google-Play-Store, and create such a product family if not found.
  2. 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.
  3. 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.
  4. 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 to SubscriptionPurchase.startTimeMillis.
      • current_term_end set to SubscriptionPurchase.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.
  5. 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.

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

Possible 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

Possible 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

Possible values:

  • "all-disabled"

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, subscription_id (random unique id) will be the customer[id]. If the customer record is not found in Chargebee, it is created.
optional, string, max chars=50

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 productId/subscriptionId or sku received from the Google Play Store.
Note: The max chars limit is 95 for Google Play Store. Apple App Store : The unique identifier (created in App Store Connect) of the product purchased.

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

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[price_in_decimal].
Note :

  • When the value of product[price] is passed through this API then it will override the product price configured in Chargebee while creating a subscription.
  • When no product[price] is passed and the product[id] does not exist in Chargebee then this API will return an error.
  • During the reactivation of a subscription, the old price of the subscription will be considered irrespective of the value of the product[price] passed through this API.
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, 0 represents the day,1 represents the week, 2 represents the month, and 3 represents the year. This is an optional parameter. The parameter value is required if the product(s) are not imported to Chargebee from Apple App Store.
Note

Since the Apple App Store receipt does not have the subscription renewal period information for trial subscriptions, product[period] and product[period_unit] are needed, to create a subscription in Chargebee with the trial period. If these parameters are not passed and the receipt has trial information then Chargebee will return a validation error.

product.name String No

Google Play Store : The name (created in Play Store Console) of the product purchased. If not passed then the product[id] will be considered as the value of product[name].
optional, string, max chars=46

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 optional parameter. The parameter value is required if the product(s) are not imported to Chargebee from Apple App Store.

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.