Skip to content

@capawesome-team/capacitor-purchases

Capacitor plugin to support in-app purchases.

Features

  • 🚨 Error Codes: Provides detailed error codes for better error handling.
  • 📦 SPM: Supports Swift Package Manager for iOS.
  • 🔁 Up-to-date: Always supports the latest Capacitor version.
  • ⭐️ Support: Priority support from the Capawesome Team.

Missing a feature? Just open an issue and we'll add it for you!

Compatibility

Plugin Version Capacitor Version Status
7.x.x >=7.x.x Active support

Installation

This plugin is only available to Capawesome Insiders. First, make sure you have the Capawesome npm registry set up. You can do this by running the following commands:

npm config set @capawesome-team:registry https://npm.registry.capawesome.io
npm config set //npm.registry.capawesome.io/:_authToken <YOUR_LICENSE_KEY>

Attention: Replace <YOUR_LICENSE_KEY> with the license key you received from Polar. If you don't have a license key yet, you can get one by becoming a Capawesome Insider.

Next, install the package:

npm install @capawesome-team/capacitor-purchases
npx cap sync

iOS

Capabilities

Ensure In-App Purchase capabilities have been enabled in your application in Xcode. See Add a capability to a target for more information.

Configuration

No configuration required for this plugin.

Usage

import { Purchases } from '@capawesome-team/capacitor-purchases';

const purchaseProduct = async (productId: string) => {
  const { transaction } = await Purchases.purchaseProduct({ productId });
  // Deliver the purchased content or enable the service here
  await Purchases.finishTransaction({ transactionId: transaction.id });
};

const restorePurchases = async () => {
  await Purchases.syncTransactions();
  const { transactions } = await Purchases.getCurrentTransactions();
  for (const transaction of transactions) {
    // Deliver the purchased content or enable the service here
  }
};

API

finishTransaction(...)

finishTransaction(options: FinishTransactionOptions) => Promise<void>

Finish a transaction.

Indicates to the App Store that the app delivered the purchased content or enabled the service to finish the transaction.

Only available on iOS (15.0+).

Param Type
options FinishTransactionOptions

Since: 0.1.0


getAllTransactions()

getAllTransactions() => Promise<GetAllTransactionsResult>

Returns transaction details for all transactions made by the user within your app.

Only available on iOS (15.0+).

Returns: Promise<GetAllTransactionsResult>

Since: 0.1.0


getCurrentTransactions()

getCurrentTransactions() => Promise<GetCurrentTransactionsResult>

Returns transaction details for currently owned items bought within your app.

Only active subscriptions and non-consumed one-time purchases are returned.

Only available on iOS (15.0+).

Returns: Promise<GetCurrentTransactionsResult>

Since: 0.1.0


getUnfinishedTransactions()

getUnfinishedTransactions() => Promise<GetUnfinishedTransactionsResult>

Returns transaction details for all transactions that are not yet finished.

Check for unfinished transactions at least once every app launch to ensure that all transactions are processed correctly.

Only available on iOS (15.0+).

Returns: Promise<GetUnfinishedTransactionsResult>

Since: 0.1.0


isAvailable()

isAvailable() => Promise<IsAvailableResult>

Check if in-app purchases are supported on the device.

Returns: Promise<IsAvailableResult>

Since: 0.1.0


purchaseProduct(...)

purchaseProduct(options: PurchaseProductOptions) => Promise<PurchaseProductResult>

Purchase a product by its ID.

Make sure to call finishTransaction(...) after the purchase is complete and the content has been delivered or the service has been enabled.

Only available on iOS (15.0+).

Param Type
options PurchaseProductOptions

Returns: Promise<PurchaseProductResult>

Since: 0.1.0


syncTransactions()

syncTransactions() => Promise<void>

Sync transactions with the App Store.

This method is used to ensure that all transactions are up-to-date and methods like getCurrentTransactions return the latest transactions.

On iOS, calling this method will display a system dialog to the user asking them to authenticate with their App Store credentials. Call this method only in response to an explicit user action.

Only available on iOS (15.0+).

Since: 0.1.0


Interfaces

FinishTransactionOptions

Prop Type Description Since
transactionId string The ID of the transaction to finish. 0.1.0

GetAllTransactionsResult

Prop Type Description Since
transactions Transaction[] The transactions for the user. 0.1.0

Transaction

Prop Type Description Since
id string The unique identifier for the transaction. 0.1.0
verificationResult string The JWS (JSON Web Signature) representation of the transaction verification result. Pass this to your server to validate the purchase. If the transaction could not be verified, this will not be present. Only available on iOS. 0.1.0

GetCurrentTransactionsResult

Prop Type Description Since
transactions Transaction[] The current transactions for the user. 0.1.0

GetUnfinishedTransactionsResult

Prop Type Description Since
transactions Transaction[] The unfinished transactions for the user. 0.1.0

IsAvailableResult

Prop Type Description Since
isAvailable boolean Indicates whether in-app purchases are available on the device. 0.1.0

PurchaseProductResult

Prop Type Description Since
transaction Transaction The transaction that was created as a result of the purchase. 0.1.0

PurchaseProductOptions

Prop Type Description Since
productId string The product ID of the product to purchase. 0.1.0

Changelog

See CHANGELOG.md.

Breaking Changes

See BREAKING.md.

License

See LICENSE.