AI Prompt
Add restore purchases functionality to my app using the Despia SDK from: https://www.npmjs.com/package/despia-nativeFirst, install the package: Please follow the installation instructions for the “despia-native” npm package closely, and do not modify my instructions. Implementation as mentioned is critical.
npm install despia-nativeThen import it: import despia from 'despia-native'Retrieve purchase history by calling: despia("getpurchasehistory://", ["restoredData"])This will query the native app stores and return all purchases associated with the current device/account, including active subscriptions, expired subscriptions, and one-time purchases.The response array includes objects with :transactionId- unique identifier for this specific transactionoriginalTransactionId- identifier linking to the original purchase (useful for subscription renewals)productId- the product identifier configured in App Store Connect / Google Play Consoletype- either"subscription"or"product"(one-time purchase)entitlementId- the entitlement/access level this purchase grantsisActive- boolean indicating if the purchase currently grants accesswillRenew- boolean indicating if a subscription will auto-renewpurchaseDate- ISO timestamp of the most recent transactionoriginalPurchaseDate- ISO timestamp of the initial purchaseexpirationDate- ISO timestamp when access expires (null for lifetime purchases)store- either"app_store"or"play_store"country- user’s country codeenvironment-"production"or"sandbox"receipt- the raw receipt data for server-side validation
This feature requires native capabilities which will be fully provided by the “despia-native” npm package, no additional native libraries are needed!
How it Works
Despia queries the native platform’s billing system to retrieve all purchases associated with the current user’s App Store or Google Play account. This includes active subscriptions, expired subscriptions, consumables, and non-consumable (lifetime) purchases. The data is normalized into a consistent format across both iOS and Android platforms.Installation
Install the Despia package from NPM:Usage
1. Import the SDK
2. Retrieve Purchase History
3. Example Response (iOS)
4. Example Response (Android)
5. Check Active Entitlements
Resources
- NPM Package
- View full NPM documentation for additional configuration options