Getting Started에서 계속
설치 단계와 이 플러그인의 전체 마크다운 가이드를 포함한 설정 프롬프트를 복사하세요.
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.만약 Manual Setup을 선호한다면, 다음 명령어를 실행하고 아래의 플랫폼별 지침을 따르시오:
-
패키지 설치
터미널 창 bun add @capgo/native-purchases -
자연 프로젝트와 동기화
터미널 창 bunx cap sync -
청구 지원 확인
import { NativePurchases } from '@capgo/native-purchases';const { isBillingSupported } = await NativePurchases.isBillingSupported();if (!isBillingSupported) {throw new Error('Billing is not available on this device');} -
스토어에서 직접 제품을 로드
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);}); -
구매 및 복원 흐름 구현
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를 진행하세요.
- 매니페스트 편집이 필요하지 않습니다. 제품이 승인되도록 확인하세요.
- 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 | SKU/Product ID configured in App Store Connect / Google Play Console. |
productType | 안드로이드 전용 | PURCHASE_TYPE.INAPP 또는 PURCHASE_TYPE.SUBS또는 INAPP. 기본값 SUBS . 항상 설정 |
planIdentifier | 구독을 위한 | 안드로이드 구독 |
billingPlanType | iOS 구독 | StoreKit 결제 플랜을 구입하기 위해 사용합니다. 'monthly' 월별 결제 옵션을 노출할 때 12개월의 의무 계약이 있습니다. product.pricingTerms iOS |
quantity | iOS에서만 사용할 수 있는 인앱 구매에 한정되어 있으며 기본적으로 | 는 사용되지 않습니다. Android는 항상 하나의 아이템을 구매합니다. 1iOS + Android |
appAccountToken | iOS | 구매와 관련된 사용자 ID입니다. iOS에서는 UUID가 필요하지만 Android는 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 Developer API에 서버 수신 영수증 검증을 호출하세요.purchaseToken권위적인 상태를 위해.purchaseState해야 합니다.PURCHASED그리고isAcknowledged해야 합니다.true.
API 빠른 참조
API 빠른 참조 섹션isBillingSupported()– 스토어 키트 / 구글 플레이 사용 가능성을 확인하세요.getProduct()/getProducts()– 가격, 지역화된 제목, 설명, 소개 제안 및 iOS 가격 조건을 가져옵니다.purchaseProduct()– 스토어 키트 2 또는 Billing 클라이언트 구매 흐름을 시작하세요. 이에는 iOS 월간 약속 결제 계획이 포함됩니다.restorePurchases()– 역사적 구매를 재생하고 현재 기기와 동기화하세요.getPurchases()– iOS 거래 또는 Play Billing 구매 목록을 표시하세요.manageSubscriptions()– 네이티브 구독 관리 UI를 열어주세요.addListener('transactionUpdated')– iOS 앱이 시작될 때 StoreKit 2 거래를 처리하세요 (iOS 전용).
Best practices
Best practices- 스토어 가격 표시 – 애플은 표시해야 하는 것을 요구합니다.
product.title그리고product.priceString; 절대 하드 코딩하지 마세요. - 사용
appAccountToken– 사용자 ID에서 UUID (v5)를 결정적으로 생성하여 구매를 계정에 연결하세요. - 서버 측에서 유효성 검사 – (iOS) /
receiptiOSpurchaseTokenAndroid에서 사용자 인증을 위해 백엔드에 전송합니다. - 오류를 잘 처리하세요. – 사용자 취소, 네트워크 오류 및 비지원 결제 환경을 확인하세요.
- 잘 테스트하세요. – iOS 샌드박스 가이드 및 Android 샌드박스 가이드.
- 복원 및 관리를 제안하세요. –
restorePurchases()다음 단계manageSubscriptions().
구매 흐름이 작동하면 수입 플레이북 첫 번째 유료 채널을 계획하는 데 도움이 됩니다: 제품 범위, ASO, 가격, 결제 벽의 위치, 분석 및 churn feedback.
문제 해결
- 제품이 로드되지 않음
- bundle ID / 애플리케이션 ID가 저장소 구성과 일치하는지 확인하십시오.
- 제품 ID가 활성화되고 승인된 상태인지 (App Store) 또는 활성화된 상태인지 (Google Play) 확인하십시오.
제품을 생성한 후 몇 시간 기다리십시오; 저장소 전파는 즉시 이루어지지 않습니다.
- 구매가 취소되거나 멈춤
try/catch그리고 사용자 친화적인 오류 메시지를 표시합니다. - 안드로이드의 경우, 테스트 계정은 내부 트랙으로 앱을 Play Store에서 설치하여 Billing이 작동하도록 하세요.
- 디바이스에서 실행 중인 경우 Billing 오류를 확인하기 위해 logcat/Xcode를 확인하세요.
구독 상태가 올바르지 않습니다.
- 사용하여
getPurchases()스토어 데이터와 로컬 권한 캐시를 비교하기 위해 사용하세요. - 안드로이드의 경우, 항상 Google Play Developer API에
purchaseToken을 사용하여 만료 날짜 또는 환불 상태를 얻으세요. - iOS의 경우,
isActive/expirationDate을 확인하고 영수증을 검증하여 환불 또는 취소가 감지되도록 하세요.
Getting Started에서 계속하세요.
Getting Started에서 계속하세요.이 기능을 사용하는 경우 시작하기 스토어 승인 및 배포를 계획하고 있습니다. 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 native market 기능을 사용하는 @capgo/capacitor-native-market 에 대해.