
Research
/Security News
CanisterWorm: npm Publisher Compromise Deploys Backdoor Across 29+ Packages
The worm-enabled campaign hit @emilgroup and @teale.io, then used an ICP canister to deliver follow-on payloads.
capacitor-plugin-purchase
Advanced tools
A Capacitor plugin for handling in-app purchases (both consumable and non-consumable products) on iOS and Android.
restorePurchases and getActivePurchases methodsrestoreCompletedTransactions(withApplicationUsername:) when userId is providedrestorePurchases to return list of restored purchasesproductType parameter to distinguish between consumable and non-consumable productsfinishTransaction method for iOS to manually finish consumable transactionsnpm install capacitor-plugin-purchase
npx cap sync
Minimum iOS Version: Ensure your app's minimum deployment target is set to iOS 15.0 or later in Xcode.
Capabilities: Enable the "In-App Purchase" capability in your app's Xcode project:
StoreKit Configuration (for testing):
Add the following to your app's build.gradle:
dependencies {
// ... other dependencies
implementation 'com.android.billingclient:billing:5.0.0'
}
import { InAppPurchase } from 'capacitor-plugin-purchase';
import { Capacitor } from '@capacitor/core';
const checkPurchases = async () => {
const { allowed } = await InAppPurchase.canMakePurchases();
if (allowed) {
console.log('In-app purchases are allowed');
} else {
console.log('In-app purchases are not allowed');
}
};
const getProducts = async () => {
try {
const result = await InAppPurchase.getProducts({
productIds: ['product_id_1', 'product_id_2'],
productType: 'consumable' // optional: 'consumable' or 'non-consumable'
});
console.log('Products:', result.products);
// Products will contain details like title, description, price, etc.
} catch (error) {
console.error('Error fetching products:', error);
}
};
const purchaseConsumable = async (productId: string, userId?: string) => {
try {
const result = await InAppPurchase.purchaseProduct({
productId: productId,
productType: 'consumable',
userId: userId // optional: associate purchase with user
});
if (result.transactionId) {
console.log('Purchase successful!');
console.log('Transaction details:', result);
// On iOS, you need to finish the transaction after consuming the item
if (Capacitor.getPlatform() === 'ios') {
// Consume your item here (update game state, add coins, etc.)
// Then finish the transaction
await InAppPurchase.finishTransaction({
transactionId: result.transactionId
});
}
// On Android, consumable products are automatically consumed
}
} catch (error) {
console.error('Error during purchase:', error);
}
};
const purchaseNonConsumable = async (productId: string, userId?: string) => {
try {
const result = await InAppPurchase.purchaseProduct({
productId: productId,
productType: 'non-consumable',
userId: userId // optional: associate purchase with user
});
if (result.transactionId) {
console.log('Purchase successful!');
console.log('Transaction details:', result);
// Non-consumable products are automatically finished/acknowledged
// Just update your app state to reflect the purchase
}
} catch (error) {
console.error('Error during purchase:', error);
}
};
const restoreUserPurchases = async (userId: string) => {
try {
const result = await InAppPurchase.restorePurchases({ userId });
console.log('Restored purchases:', result.purchases);
// Note: On iOS, this will only return purchases associated with the userId
// On Android, this returns all purchases for the Google account
} catch (error) {
console.error('Error restoring purchases:', error);
}
};
const getActiveUserPurchases = async (userId: string) => {
try {
const result = await InAppPurchase.getActivePurchases({ userId });
console.log('Active purchases:', result.purchases);
// Note: On iOS, this will only return purchases associated with the userId
// On Android, this returns all purchases for the Google account
} catch (error) {
console.error('Error getting active purchases:', error);
}
};
The web implementation provides mock responses as in-app purchases are not supported in web environments. This allows you to develop and test your app in a web browser without errors, but actual purchases will only work on iOS and Android devices.
canMakePurchases()Check if the user/device can make purchases.
Returns: Promise<{ allowed: boolean }>
getProducts(options: { productIds: string[]; productType?: 'consumable' | 'non-consumable' })Get product information from the app store.
Parameters:
options.productIds: Array of product identifiersoptions.productType (optional): Product type filter - 'consumable' or 'non-consumable'Returns: Promise<{ products: Product[] }>
Where Product has the following properties:
productId: stringtitle: stringdescription: stringprice: string (formatted price with currency symbol)priceAsDecimal: number (price as a decimal number)currency: string (currency code)productType: string (optional) - 'consumable' or 'non-consumable'purchaseProduct(options: { productId: string; userId?: string; productType?: 'consumable' | 'non-consumable' })Initiate a purchase for a specific product.
Parameters:
options.productId: Product identifier to purchaseoptions.userId (optional): User identifier to associate with the purchaseoptions.productType (optional): Product type - 'consumable' or 'non-consumable'Returns: Promise
Where TransactionDetails has the following properties:
transactionId: string (transaction identifier)productId: string (purchased product identifier)receipt: string (purchase receipt - base64 encoded on iOS, JSON string on Android)date: string (ISO 8601 formatted date)userId: string (optional) - user identifier if providedrestorePurchases(options?: { userId?: string })Restore previously purchased products.
Parameters:
options.userId (optional): User identifier to filter restored purchases (iOS only, Android returns all purchases for the account)Returns: Promise<{ purchases: TransactionDetails[] }>
getActivePurchases(options?: { userId?: string })Get list of active purchases (owned items).
Parameters:
options.userId (optional): User identifier to filter active purchases (iOS only, Android returns all purchases for the account)Returns: Promise<{ purchases: TransactionDetails[] }>
finishTransaction(options: { transactionId: string }) (iOS only)Finish a transaction for consumable products on iOS. This should be called after the consumable item has been delivered to the user.
Parameters:
options.transactionId: Transaction identifier to finishReturns: Promise
When using this plugin in a web application, all methods will return mock responses:
canMakePurchases() will return { allowed: false }getProducts() will return an empty array of productspurchaseProduct() will throw an errorThis allows you to develop and test your app in a web browser without errors, but actual purchases will only work on iOS and Android devices.
For iOS, you can use the Sandbox environment to test purchases without actual charges. Make sure to:
For Android, you can use test accounts and test cards:
MIT
FAQs
consumable products purchase
The npm package capacitor-plugin-purchase receives a total of 97 weekly downloads. As such, capacitor-plugin-purchase popularity was classified as not popular.
We found that capacitor-plugin-purchase demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
/Security News
The worm-enabled campaign hit @emilgroup and @teale.io, then used an ICP canister to deliver follow-on payloads.

Research
/Security News
Attackers compromised Trivy GitHub Actions by force-updating tags to deliver malware, exposing CI/CD secrets across affected pipelines.

Security News
ENISA’s new package manager advisory outlines the dependency security practices companies will need to demonstrate as the EU’s Cyber Resilience Act begins enforcing software supply chain requirements.