IAP Purchases integration for iOS and Android
npm install capacitor-native-purchasesIAP Purchases integration for iOS and Android
``bash`
npm install capacitor-purchases
npx cap sync
* echo(...)
* getProductDetails(...)
* purchaseProduct(...)
* getCurrentEntitlements()
* getLatestTransaction(...)
* manageSubscriptions()
* setGoogleVerificationDetails(...)
* addListener('ANDROID-PURCHASE-RESPONSE', ...)
* restorePurchases()
* Interfaces
* Type Aliases
`typescript`
echo(options: { value: string; }) => Promise<{ value: string; }>
A test method which just returns what is passed in
| Param | Type |
| ------------- | ------------------------------- |
| options | { value: string; } |
Returns: Promise<{ value: string; }>
--------------------
`typescript`
getProductDetails(options: { productIdentifier: string; }) => Promise
Receives a product ID and returns the product details
| Param | Type |
| ------------- | ------------------------------------------- |
| options | { productIdentifier: string; } |
Returns: Promise<ProductDetailsResponse>
--------------------
`typescript`
purchaseProduct(options: { productIdentifier: string; accountToken?: string; }) => Promise
Receives the product ID which the user wants to purchase and returns the transaction ID
| Param | Type |
| ------------- | ------------------------------------------------------------------ |
| options | { productIdentifier: string; accountToken?: string; } |
Returns: Promise<PurchaseProductResponse>
--------------------
`typescript`
getCurrentEntitlements() => Promise
Returns: Promise<CurrentEntitlementsResponse>
--------------------
`typescript`
getLatestTransaction(options: { productIdentifier: string; }) => Promise
| Param | Type |
| ------------- | ------------------------------------------- |
| options | { productIdentifier: string; } |
Returns: Promise<LatestTransactionResponse>
--------------------
`typescript`
manageSubscriptions() => any
Returns: any
--------------------
`typescript`
setGoogleVerificationDetails(options: { googleVerifyEndpoint: string; bid: string; }) => void
| Param | Type |
| ------------- | ----------------------------------------------------------- |
| options | { googleVerifyEndpoint: string; bid: string; } |
--------------------
`typescript`
addListener(eventName: 'ANDROID-PURCHASE-RESPONSE', listenerFunc: (response: AndroidPurchasedTrigger) => void) => Promise
| Param | Type |
| ------------------ | -------------------------------------------------------------------------------------------------- |
| eventName | 'ANDROID-PURCHASE-RESPONSE' |
| listenerFunc | (response: AndroidPurchasedTrigger) => void |
Returns: Promise<PluginListenerHandle>
--------------------
`typescript`
restorePurchases() => Promise
Returns: Promise<RestorePurchasesResponse>
--------------------
#### ProductDetailsResponse
| Prop | Type |
| --------------------- | --------------------------------------------------------------------------------------- |
| responseCode | ProductDetailsResponseCode |
| responseMessage | ProductDetailsResponseMessage |
| data | Product |
#### Product
| Prop | Type |
| ----------------------- | ------------------- |
| productIdentifier | string |
| price | string |
| displayName | string |
| description | string |
#### PurchaseProductResponse
| Prop | Type |
| --------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| responseCode | 0 \| 1 \| 2 \| 5 \| 4 \| 3 \| -1 |
| responseMessage | 'Incompatible with web' \| 'Could not find a product matching the given productIdentifier' \| 'Successfully purchased product' \| 'Product seems to have been purchased but the transaction failed verification' \| 'User closed the native popover before purchasing' \| 'Product request made but is currently pending - likely due to parental restrictions' \| 'An unknown error occurred whilst in the purchasing process' \| 'Successfully opened native popover' \| 'Failed to open native popover' |
#### CurrentEntitlementsResponse
| Prop | Type |
| --------------------- | ------------------------------------------------------------------------------------------------- |
| responseCode | CurrentEntitlementsResponseCode |
| responseMessage | CurrentEntitlementsResponseMessage |
| data | Transaction[] |
#### Transaction
| Prop | Type |
| ----------------------- | -------------------- |
| productIdentifier | string |
| expiryDate | string |
| originalId | string |
| transactionId | string |
| originalStartDate | string |
| isTrial | boolean |
| purchaseToken | string |
#### LatestTransactionResponse
| Prop | Type |
| --------------------- | --------------------------------------------------------------------------------------------- |
| responseCode | LatestTransactionResponseCode |
| responseMessage | LatestTransactionResponseMessage |
| data | Transaction |
#### PluginListenerHandle
| Prop | Type |
| ------------ | ----------------------------------------- |
| remove | () => Promise<void> |
#### AndroidPurchasedTrigger
| Prop | Type |
| ----------- | -------------------- |
| fired | boolean |
#### RestorePurchasesResponse
| Prop | Type |
| --------------- | -------------------- |
| completed` | boolean |
#### ProductDetailsResponseCode
-1 | 0 | 1
#### ProductDetailsResponseMessage
'Incompatible with web' | 'Successfully found the product details for given productIdentifier' | 'Could not find a product matching the given productIdentifier'
#### PurchaseProductIOSResponseCode
-1 | 0 | 1 | 2 | 3 | 4 | 5
#### PurchaseProductAndroidResponseCode
-1 | 0 | 1
#### PurchaseProductIOSResponseMessage
'Incompatible with web' | 'Successfully purchased product' | 'Could not find a product matching the given productIdentifier' | 'Product seems to have been purchased but the transaction failed verification' | 'User closed the native popover before purchasing' | 'Product request made but is currently pending - likely due to parental restrictions' | 'An unknown error occurred whilst in the purchasing process'
#### PurchaseProductAndroidResponseMessage
'Incompatible with web' | 'Successfully opened native popover' | 'Failed to open native popover'
#### CurrentEntitlementsResponseCode
-1 | 0 | 1 | 2
#### CurrentEntitlementsResponseMessage
'Incompatible with web' | 'Successfully found all entitlements across all product types' | 'No entitlements were found' | 'Unknown problem trying to retrieve entitlements'
#### LatestTransactionResponseCode
-1 | 0 | 1 | 2 | 3
#### LatestTransactionResponseMessage
'Incompatible with web' | 'Successfully found the latest transaction matching given productIdentifier' | 'Could not find a product matching the given productIdentifier' | 'No transaction for given productIdentifier, or it could not be verified' | 'Unknown problem trying to retrieve latest transaction'