__CAPGO_KEEP_0__
설치 단계와 이 플러그인에 대한 전체 마크다운 가이드를 포함한 설정 프롬프트를 복사하십시오.
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/native-purchases`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/native-purchases/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
설치
설치설치 플러그인을 사용하기 위해 AI-Assisted Setup을 사용할 수 있습니다. AI 도구에 Capgo 스킬을 추가하려면 다음 명령어를 사용하세요.
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins그런 다음 다음 프롬프트를 사용하세요:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/native-purchases` plugin in my project.__CAPGO_KEEP_1__
-
__CAPGO_KEEP_2__
__CAPGO_KEEP_3__ bun add @capgo/native-purchases -
__CAPGO_KEEP_4__
__CAPGO_KEEP_3__ bunx cap sync -
__CAPGO_KEEP_5__
import { NativePurchases } from '@capgo/native-purchases';const { isBillingSupported } = await NativePurchases.isBillingSupported();if (!isBillingSupported) {throw new Error('Billing is not available on this device');} -
__CAPGO_KEEP_6__
import { NativePurchases, PURCHASE_TYPE } from '@capgo/native-purchases';const { products } = await NativePurchases.getProducts({productIdentifiers: ['com.example.premium.monthly','com.example.premium.yearly','com.example.one_time_unlock'],productType: PURCHASE_TYPE.SUBS, // Use PURCHASE_TYPE.INAPP for one‑time products});products.forEach((product) => {console.log(product.title, product.priceString);}); -
구매 및 복원 흐름을 implement하세요
import { NativePurchases, PURCHASE_TYPE } from '@capgo/native-purchases';const monthlyPlanId = 'monthly-plan'; // Base Plan ID from Google Play Consoleconst transaction = await NativePurchases.purchaseProduct({productIdentifier: 'com.example.premium.monthly',planIdentifier: monthlyPlanId, // REQUIRED for Android subscriptions, ignored on iOSproductType: PURCHASE_TYPE.SUBS,quantity: 1,});console.log('Transaction ID', transaction.transactionId);await NativePurchases.restorePurchases();- App Store Connect에서 내 앱 제품 및 구독을 만들 수 있습니다.
- StoreKit Local Testing 또는 Sandbox 테스터를 사용하여 QA를 진행하세요.
- manifest 편집이 필요하지 않습니다. 제품이 승인되도록 확인하세요.
- Google Play Console에서 내 앱 제품 및 구독을 만들 수 있습니다.
- 내부 테스트 빌드를 업로드하고 라이선스 테스터를 추가하세요.
- Billing 권한을 추가하세요.
AndroidManifest.xml:
<uses-permission android:name="com.android.vending.BILLING" /> - App Store Connect에서 내 앱 제품 및 구독을 만들 수 있습니다.
구매 서비스 예제
구매 서비스 예제import { NativePurchases, PURCHASE_TYPE, Transaction } from '@capgo/native-purchases';import { Capacitor } from '@capacitor/core';
class PurchaseService { private premiumProduct = 'com.example.premium.unlock'; private monthlySubId = 'com.example.premium.monthly'; private monthlyPlanId = 'monthly-plan'; // Base Plan ID (Android only)
async initialize() { const { isBillingSupported } = await NativePurchases.isBillingSupported(); if (!isBillingSupported) throw new Error('Billing unavailable');
const { products } = await NativePurchases.getProducts({ productIdentifiers: [this.premiumProduct, this.monthlySubId], productType: PURCHASE_TYPE.SUBS, });
console.log('Loaded products', products);
if (Capacitor.getPlatform() === 'ios') { NativePurchases.addListener('transactionUpdated', (transaction) => { this.handleTransaction(transaction); }); } }
async buyPremium(appAccountToken?: string) { const transaction = await NativePurchases.purchaseProduct({ productIdentifier: this.premiumProduct, productType: PURCHASE_TYPE.INAPP, appAccountToken, });
await this.processTransaction(transaction); }
async buyMonthly(appAccountToken?: string) { const transaction = await NativePurchases.purchaseProduct({ productIdentifier: this.monthlySubId, planIdentifier: this.monthlyPlanId, // REQUIRED for Android subscriptions productType: PURCHASE_TYPE.SUBS, appAccountToken, });
await this.processTransaction(transaction); }
async restore() { await NativePurchases.restorePurchases(); await this.refreshEntitlements(); }
async openManageSubscriptions() { await NativePurchases.manageSubscriptions(); }
private async processTransaction(transaction: Transaction) { this.unlockContent(transaction.productIdentifier); this.validateOnServer(transaction).catch(console.error); }
private unlockContent(productIdentifier: string) { // persist entitlement locally console.log('Unlocked', productIdentifier); }
private async refreshEntitlements() { const { purchases } = await NativePurchases.getPurchases({ productType: PURCHASE_TYPE.SUBS, }); console.log('Current purchases', purchases); }
private async handleTransaction(transaction: Transaction) { console.log('StoreKit transaction update:', transaction); await this.processTransaction(transaction); }
private async validateOnServer(transaction: Transaction) { await fetch('/api/validate-purchase', { method: 'POST', body: JSON.stringify({ transactionId: transaction.transactionId, receipt: transaction.receipt, purchaseToken: transaction.purchaseToken, }), }); }}필수 구매 옵션
필수 구매 옵션| 옵션 | 플랫폼 | 설명 |
|---|---|---|
productIdentifier | iOS + Android | App Store Connect / Google Play Console 에서 SKU / 제품 ID가 구성됩니다. |
productType | Android만 | PURCHASE_TYPE.INAPP 또는 PURCHASE_TYPE.SUBS. 기본값은 INAPP. 항상 SUBS 구독에 대해 |
planIdentifier | Android 구독 | Google Play Console 에서 기본 플랜 ID입니다. 구독에 필수적이며 iOS 및 인앱 구매에서는 무시됩니다. |
billingPlanType | iOS 구독 | StoreKit 결제 플랜을 구입하기 위해 사용합니다. 'monthly' 월별 결제와 12개월의 약속을 사용할 때 product.pricingTerms 노출합니다. |
quantity | iOS | 인앱 구매에만 사용하며 기본값은 1. 안드로이드는 항상 1개의 아이템을 구매합니다. |
appAccountToken | iOS + Android | 구매를 사용자와 연결하는 UUID/문자열입니다. iOS에서는 UUID가 필요하며, 안드로이드에서는 64자 이하의 암호화된 문자열을 허용합니다. |
isConsumable | Android | 자동으로 토큰을 소비하기 위해 사용자에게 권한을 부여한 후에 설정합니다. 기본값은 true . false. |
인증 상태 확인
인증 상태 확인 섹션사용 getPurchases() 다양한 매장에서 보고되는 모든 거래를 한 번에跨 플랫폼으로 확인할 수 있습니다.
import { NativePurchases, PURCHASE_TYPE } from '@capgo/native-purchases';
const { purchases } = await NativePurchases.getPurchases({ productType: PURCHASE_TYPE.SUBS,});
purchases.forEach((purchase) => { if (purchase.isActive && purchase.expirationDate) { console.log('iOS sub active until', purchase.expirationDate); }
const isAndroidIapValid = ['PURCHASED', '1'].includes(purchase.purchaseState ?? '') && purchase.isAcknowledged;
if (isAndroidIapValid) { console.log('Grant in-app entitlement for', purchase.productIdentifier); }});플랫폼 동작
플랫폼 동작 섹션- iOS구독에는
isActive,expirationDate,willCancel, 및 StoreKit 2 리스너 지원이 포함됩니다. 앱 내 구매는 서버 수신 영수증 검증이 필요합니다. - Android:
isActive/expirationDate은 채워지지 않습니다. Google Play 개발자 API를 호출하여purchaseToken권위적인 상태를 위해.purchaseState해야 합니다.PURCHASED및isAcknowledged해야 합니다.true.
API 빠른 참조
제목이 'API 빠른 참조'인 섹션isBillingSupported()– StoreKit / Google Play 사용 가능성을 확인하십시오.getProduct()/getProducts()– 가격, 지역화된 제목, 설명, 소개 제안, 및 iOS 가격 조건을 지원하십시오.purchaseProduct()– StoreKit 2 또는 Billing 클라이언트 구매 흐름을 시작하십시오. iOS 월간 약속 청구 계획도 포함합니다.restorePurchases()– 역사적인 구매를 재생하고 현재 기기와 동기화하십시오.getPurchases()– iOS 거래 또는 Play Billing 구매 목록을 표시하십시오.manageSubscriptions()– 네이티브 구독 관리 UI를 열으십시오.addListener('transactionUpdated')– 시작할 때 StoreKit 2 거래를 처리하세요 (iOS 전용).
Best practices
Best practices- 판매 가격 표시 – Apple은 표시해야 하는 것을 요구합니다.
product.title및product.priceString; 절대 하드 코딩하지 마십시오. - 사용
appAccountToken– 사용자 ID에서 UUID (v5)를 결정적으로 생성하여 구매를 계정에 연결하세요. - 서버에서 유효성 검사 – (iOS) /
receipt– iOSpurchaseToken(Android) __CAPGO_KEEP_0__ __CAPGO_KEEP_1__ - 오류를 잘 처리하세요 – 사용자 취소, 네트워크 오류 및 비지원 결제 환경을 확인하세요.
- 적극적으로 테스트하세요 – 사용자 취소, 네트워크 오류 및 비지원 결제 환경을 확인하세요. iOS 샌드박스 가이드 및 Android 샌드박스 가이드.
- 복원 및 관리를 제공하세요 – UI 버튼을 추가하여
restorePurchases()및manageSubscriptions().
수익 다음 단계
판매 수익 다음 단계구매 흐름이 작동하는 후에 판매 플레이북 첫 번째 유료 채널을 계획하세요: 제품 범위, ASO, 가격, 벽돌 배치, 분석, 그리고 churn feedback.
제품이 로드되지 않음
- 앱 스토어 구성과 일치하는 번들 ID / 애플리케이션 ID를 확인하세요.
- 제품 ID가 활성화되고 승인된 상태인지 (App Store) 또는 활성화된 상태인지 (Google Play) 확인하세요.
- 제품을 생성한 후 몇 시간 기다리세요; 스토어 전파는 즉시 이루어지지 않습니다.
구매가 취소되거나 멈춤
- 사용자는 중간에 취소할 수 있습니다; 호출을 wrapping하세요.
try/catch__CAPGO_KEEP_0__ - 안드로이드에서 테스트 계정은 내부 트랙으로 Play Store에서 앱을 설치하여 빌링이 작동하도록 하세요.
- 디바이스에서 빌링 오류를 찾기 위해 logcat/Xcode를 확인하세요.
구독 상태가 잘못되었습니다.
- Use
getPurchases()를 사용하여 스토어 데이터를 로컬 권한 캐시와 비교하세요. - 안드로이드에서는 항상 Google Play Developer API와
purchaseToken를 사용하여 만료 날짜 또는 환불 상태를 얻으세요. - iOS에서
isActive/expirationDate를 확인하고 환불 또는 취소가 감지되는지 확인하세요.
Getting Started에서 계속하기
Getting Started에서 계속하기If you are using Getting Started to plan store approval and distribution, connect it with Using @capgo/native-purchases for the native capability in Using @capgo/native-purchases, @capgo/capacitor-in-app-review for the implementation detail in @capgo/capacitor-in-app-review, Using @capgo/capacitor-in-app-review for the native capability in Using @capgo/capacitor-in-app-review, @capgo/capacitor-native-market for the implementation detail in @capgo/capacitor-native-market, and Using @capgo/capacitor-native-market capgo/capacitor-native-market에 대한 원시 기능을위한.