npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

scgs-capacitor-subscribe

v1.0.12

Published

Capacitor plugin for handling subscriptions on Android and iOS using Google Play Billing v7 and StoreKit 2

Readme

SCGS Capacitor Subscribe

A Capacitor plugin for handling in-app subscriptions on iOS and Android.

Features

  • iOS: Built with StoreKit 2 for modern subscription handling
  • Android: Uses Google Play Billing Library v7
  • TypeScript: Full type definitions for type-safe development
  • Web: Placeholder implementation for development/testing

Requirements

  • Capacitor 7.0.0 or higher
  • Node.js 20.0.0 or higher
  • For iOS development: Xcode 16.0 or higher
  • For Android development: Android Studio

Installation

npm install scgs-capacitor-subscribe
npx cap sync

iOS Setup

  1. Configure your app's in-app purchases in App Store Connect
  2. Add In-App Purchase capability to your app in Xcode
  3. Ensure your app's minimum iOS version is 15.0 or higher
  4. Requires Xcode 16.0 or higher

Android Setup

  1. Configure your app's in-app purchases in Google Play Console
  2. Add the billing permission (automatically included by the plugin)
  3. Ensure your app's minimum SDK version is 23 (Android 6.0) or higher

Usage

import { Subscribe } from 'scgs-capacitor-subscribe';

// Initialize the plugin
await Subscribe.initialize({
  enablePendingPurchases: true,
  enableLogging: true
});

// Get available products
const { products, invalidProductIds } = await Subscribe.getProducts({
  productIds: ['monthly_subscription', 'yearly_subscription']
});

// Purchase a product
try {
  const { purchase } = await Subscribe.purchaseProduct({
    productId: 'monthly_subscription'
  });
  console.log('Purchase successful:', purchase);
} catch (error) {
  console.error('Purchase failed:', error);
}

// Restore purchases
const { purchases } = await Subscribe.restorePurchases({
  userId: 'user123' // optional
});

// Get active purchases
const { purchases: activePurchases } = await Subscribe.getActivePurchases({
  userId: 'user123' // optional
});

// Check eligibility for introductory price
const { eligible, introductoryPriceEligible } = await Subscribe.checkEligibility({
  productId: 'monthly_subscription'
});

// Present code redemption sheet (iOS only)
await Subscribe.presentCodeRedemptionSheet();

API

initialize(options: InitializeOptions)

Initialize the plugin. Should be called once when your app starts.

Options:

  • enablePendingPurchases (boolean): Enable pending purchases (default: true)
  • enableLogging (boolean): Enable debug logging (default: false)

getProducts(options: GetProductsOptions)

Fetch product details from the store.

Options:

  • productIds (string[]): Array of product IDs to fetch

Returns:

  • products (Product[]): Array of available products
  • invalidProductIds (string[]): Array of product IDs that weren't found

purchaseProduct(options: PurchaseOptions)

Initiate a purchase.

Options:

  • productId (string): Product ID to purchase
  • quantity (number): Quantity to purchase (optional, default: 1)
  • userId (string): User ID (In Android it is set to obfuscatedAccountId) (In iOS it is set to appAccountToken)
  • obfuscatedProfileId (string): Obfuscated profile ID (Android only, optional)
  • offerToken (string): Offer token for the purchase (Android only, optional)

Returns:

  • purchase (Purchase): The completed purchase details

restorePurchases(options?: { userId?: string })

Restore previously made purchases.

Options:

  • userId (string): User ID for filtering purchases (optional)

Returns:

  • purchases (Purchase[]): Array of restored purchases

getActivePurchases(options?: { userId?: string })

Get currently active (non-expired) purchases.

Options:

  • userId (string): User ID for filtering purchases (optional)

Returns:

  • purchases (Purchase[]): Array of active purchases

acknowledgePurchase(options: AcknowledgeOptions)

Acknowledge a purchase (Android only, automatically handled on iOS).

Options:

  • purchaseToken (string): The purchase token to acknowledge
  • developerPayload (string): Developer payload (optional)

consumePurchase(options: ConsumeOptions)

Consume a purchase (Android only).

Options:

  • purchaseToken (string): The purchase token to consume

checkEligibility(options: CheckEligibilityOptions)

Check if user is eligible for introductory price or discounts.

Options:

  • productId (string): Product ID to check

Returns:

  • eligible (boolean): Whether user is eligible to purchase
  • introductoryPriceEligible (boolean): Whether user is eligible for intro price
  • discountEligible (boolean): Whether user is eligible for discounts

presentCodeRedemptionSheet()

Present the code redemption sheet (iOS only).

Type Definitions

Product

interface Product {
  productId: string;
  title: string;
  description: string;
  price: string;
  priceAmount: number;
  priceCurrencyCode: string;
  priceLocale: string;
  subscriptionPeriod?: SubscriptionPeriod;
  introductoryPrice?: IntroductoryPrice;
  discounts?: Discount[];
}

Purchase

interface Purchase {
  productId: string;
  purchaseToken: string;
  transactionId: string;
  purchaseTime: number;
  purchaseState: PurchaseState;
  autoRenewing?: boolean;
  acknowledged: boolean;
  orderId?: string;
  packageName?: string;
  developerPayload?: string;
  userId?: string;
  price?: string;           // Formatted display price (e.g., "$9.99")
  priceAmount?: number;     // Numeric price amount (e.g., 9.99)
  priceCurrencyCode?: string; // Currency code (e.g., "USD")
}

SubscriptionPeriod

interface SubscriptionPeriod {
  value: number;
  unit: PeriodUnit; // 'DAY' | 'WEEK' | 'MONTH' | 'YEAR'
}

PurchaseState

enum PurchaseState {
  UNSPECIFIED = 0,
  PURCHASED = 1,
  PENDING = 2
}

Error Handling

The plugin will reject promises with descriptive error messages when operations fail. Common errors include:

  • Product not found
  • Purchase cancelled by user
  • Network errors
  • Store not available
  • Invalid product configuration

Platform Differences

iOS

  • Uses StoreKit 2 for modern subscription handling
  • Transactions are automatically finished
  • Code redemption sheet available
  • Eligibility checks for introductory prices

Android

  • Uses Google Play Billing Library v7
  • Requires explicit acknowledgment of purchases
  • Supports consumption of purchases
  • Offers obfuscated account/profile IDs

Web

  • Placeholder implementation for development
  • All methods return empty results or throw "Not implemented on web"

License

MIT