본문 바로가기
@capgo/native-purchases 커머스 오픈 소스

Capgo Native Purchases Capacitor 플러그인

간단한 API 하나로 네이티브 인앱 결제, 구독, iOS StoreKit 약정 결제 플랜을 구현하세요

설치

bun add @capgo/native-purchases bunx cap sync
npm, pnpm 또는 yarn
  • npm install @capgo/native-purchases
  • pnpm add @capgo/native-purchases
  • yarn add @capgo/native-purchases

가이드

Capacitor에서 Native Purchases 사용법

@capgo/native-purchases 사용하기

간편한 인앱 구독 구현

설치

bun add @capgo/native-purchases
bunx cap sync

플러그인이 제공하는 기능

  • restorePurchases - 사용자의 이전 구매 내역을 복원하고, 해당 appUserID를 동일한 정보를 사용하는 다른 사용자와 연결합니다.
  • getAppTransaction - 사용자가 앱을 처음 다운로드하거나 구매한 시점에 대한 상세 정보를 제공하는 App Transaction 정보를 가져옵니다.
  • isEntitledToOldBusinessModel - App Transaction의 원본 앱 버전과 대상 버전을 비교하여, 사용자가 이전 비즈니스 모델의 기능을 사용할 권한이 있는지 확인합니다.
  • getProducts - 지원되는 iOS 구독 가격 정책을 포함하여 스토어 제품 메타데이터를 로드합니다.
  • purchaseProduct - 선택한 제품 및 결제 플랜에 대한 구매 프로세스를 시작합니다.

사용 예시

restorePurchases

사용자의 이전 구매 내역을 복원하고, 해당 appUserID를 동일한 정보를 사용하는 다른 사용자와 연결합니다.

import { NativePurchases } from '@capgo/native-purchases';

await NativePurchases.restorePurchases();

getAppTransaction

사용자가 앱을 처음 다운로드하거나 구매한 시점에 대한 상세 정보를 제공하는 App Transaction 정보를 가져옵니다.

import { NativePurchases } from '@capgo/native-purchases';

const { appTransaction } = await NativePurchases.getAppTransaction();

// Check if user downloaded before version 2.0.0 (when subscription was added)
if (compareVersions(appTransaction.originalAppVersion, '2.0.0') < 0) {
  // User gets free access - they downloaded before subscriptions
  grantFreeAccess();
}

isEntitledToOldBusinessModel

App Transaction의 원본 앱 버전과 대상 버전을 비교하여, 사용자가 이전 비즈니스 모델의 기능을 사용할 권한이 있는지 확인합니다.

import { NativePurchases } from '@capgo/native-purchases';

// Check if user downloaded before version 2.0.0/build 42 (when subscription was added)
const result = await NativePurchases.isEntitledToOldBusinessModel({
  targetVersion: '2.0.0',
  targetBuildNumber: '42'
});

if (result.isOlderVersion) {
  console.log(`User downloaded v${result.originalAppVersion}, granting free access`);
  grantFreeAccess();
}

purchaseProduct

지정된 제품에 대한 구매 프로세스를 시작합니다. Android 구독의 경우 Google Play base plan ID를 planIdentifier전달하세요. 12개월 약정 월간 결제를 제공하는 지원 대상 iOS 구독의 경우 billingPlanType: 'monthly'.

import { NativePurchases, PURCHASE_TYPE } from '@capgo/native-purchases';

await NativePurchases.purchaseProduct({
  productIdentifier: 'com.example.premium.monthly',
  planIdentifier: 'monthly-plan',
  productType: PURCHASE_TYPE.SUBS,
});

iOS 월간 약정 구독

지원되는 iOS 버전에서 StoreKit을 통해 12개월 약정 조건의 월간 결제 플랜을 제공할 수 있습니다. pricingTerms구매 전 페이월에 다음 약관을 표시하세요:

import { NativePurchases, PURCHASE_TYPE } from '@capgo/native-purchases';

const { products } = await NativePurchases.getProducts({
  productIdentifiers: ['com.example.premium.yearly'],
  productType: PURCHASE_TYPE.SUBS,
});

const yearlyProduct = products.find(
  (product) => product.identifier === 'com.example.premium.yearly',
);
const monthlyCommitment = yearlyProduct?.pricingTerms?.find(
  (term) => term.billingPlanType === 'monthly',
);

if (yearlyProduct && monthlyCommitment) {
  console.log('Monthly price:', monthlyCommitment.billingDisplayPrice);
  console.log('Total commitment:', monthlyCommitment.commitmentInfo?.priceString);

  const transaction = await NativePurchases.purchaseProduct({
    productIdentifier: yearlyProduct.identifier,
    productType: PURCHASE_TYPE.SUBS,
    billingPlanType: 'monthly',
  });

  console.log('Billing plan:', transaction.billingPlanType);
  console.log('Commitment ends:', transaction.commitmentInfo?.expirationDate);
}

전체 레퍼런스

@capgo/native-purchases 사용하기부터 계속하기

사용 중이라면 @capgo/native-purchases 사용하기 결제와 구매를 계획하려면 다음을 연결하세요 @capgo/native-purchases @capgo/native-purchases의 구현 상세 내용은 시작하기 Getting Started의 구현 상세 내용은 Capgo 가격 Capgo 가격 페이지의 제품 워크플로우, 결제 시스템 결제 시스템의 구현 상세 내용은, 수익화 플레이북 Revenue Playbook의 구현 상세 내용은

자주 묻는 질문

Native Purchases 플러그인 FAQ

Capacitor 앱에 Native Purchases 플러그인을 어떻게 설치하나요?

"bun add @capgo/native-purchases"(또는 "npm install @capgo/native-purchases")를 실행한 다음 "bunx cap sync"를 실행해 iOS와 Android 프로젝트에 네이티브 code가 반영되게 하세요. 그런 다음 앱 code에서 "@capgo/native-purchases"를 import 하세요.

@capgo/native-purchases가 React, Vue, Angular와 호환되나요?

네. Native Purchases는 Capacitor 패키지이므로 Ionic, React, Vue, Angular, Svelte 및 일반 JavaScript를 포함해 Capacitor에서 실행되는 모든 웹 프레임워크와 호환됩니다.

@capgo/native-purchases는 어떤 Capacitor 버전을 지원하나요?

Capgo 플러그인은 Capacitor의 메이저 버전을 따릅니다. 사용 중인 Capacitor 메이저 버전과 일치하는 플러그인 메이저 버전을 사용하세요 (예: Capacitor 8에는 플러그인 v8). 유지 관리되는 버전은 GitHub README의 호환성 표에서 확인할 수 있습니다.

@capgo/native-purchases는 무료 오픈 소스인가요?

네. code 소스 코드는 GitHub의 https://github.com/Cap-go/capacitor-native-purchases/에서 공개되어 있으며, npm에서 무료로 설치할 수 있습니다. 버그 리포트와 pull request는 언제나 환영합니다.

App Store 심사 없이 Native Purchases를 사용하는 code를 업데이트할 수 있나요?

플러그인을 설치하거나 업그레이드하면 네이티브 code가 변경되므로 새로운 스토어 빌드가 필요합니다. 그 이후에는 플러그인을 호출하는 JavaScript, HTML, CSS 변경 사항을 Capgo live updates로 즉시 배포할 수 있습니다.

앱 심사 없이 Native Purchases 변경 사항을 배포하세요

스토어 빌드에 플러그인이 포함되면, Capgo live updates로 JavaScript, HTML, CSS 변경 사항을 몇 분 만에 사용자에게 푸시할 수 있습니다.

Capgo로 시작하기