메인 콘텐츠로 건너뛰기
플러그인으로 돌아가기
@capgo/native-purchases
튜토리얼
@capgo/native-purchases

Native Purchases

iOS StoreKit 약속 결제 플랜과 간단한 API을 사용하여 원시 앱 내 구매, 구독 및 결제를 implement하세요.

가이드

자연스러운 구매에 대한 튜토리얼

장치에서 테스트

다운로드 Capgo 앱, 그리고 QR code를 스캔하세요.

네이티브 구매 플러그인 미리보기 QR code

Using @capgo/native-purchases

앱 내 구독을 쉽게 관리하세요.

설치

bun add @capgo/native-purchases
bunx cap sync

이 플러그인이 제공하는 것

  • restorePurchases - 사용자가 이전에 사용한 구매 정보를 복원하고 앱 사용자 ID를 사용자 ID와 연결합니다.
  • getAppTransaction - 앱 거래 정보를 가져옵니다. 이 정보는 사용자가 앱을 처음 다운로드하거나 구매한 날짜에 대한 세부 정보를 제공합니다.
  • isEntitledToOldBusinessModel - 원래 앱 버전과 목표 버전을 비교하여 사용자가 이전 사업 모델에서 특정 기능에 대한 권한이 있는지 결정합니다.
  • getProducts - iOS 구독 가격 조건을 포함하여 지원되는 iOS 구독 가격 정보를 불러옵니다.
  • purchaseProduct - 선택한 제품과 청구 계획에 대한 구매 프로세스를 시작합니다.

예제 사용법

restorePurchases

사용자의 이전 기록을 복원하고 사용자 ID를 연결합니다.

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

await NativePurchases.restorePurchases();

getAppTransaction

앱의 거래 정보를 가져옵니다. 이 정보는 사용자가 앱을 처음 다운로드하거나 구매한 날짜에 대한 세부 정보를 제공합니다.

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

원래 앱 버전과 목표 버전을 비교하여 사용자가 이전 사업 모델에서 특정 기능에 대한 권한이 있는지 결정합니다.

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 기본 플랜 ID를 전달하세요. planIdentifieriOS 구독을 지원하는 경우 12개월의 약속과 함께 월간 청구를 제공하는 구독을 전달하세요. 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);
}

Full Reference

Using @capgo/native-purchases에서 계속

Capacitor를 사용 중이라면 Using @capgo/native-purchases 결제와 구매를 계획하고 싶다면 @capgo/native-purchases Capacitor의 구현 세부 사항은 @capgo/native-purchases에서 확인할 수 있습니다. Getting Started Getting Started의 구현 세부 사항은 Capgo Pricing Capacitor의 제품 워크플로우는 Capgo Pricing에서 확인할 수 있습니다. 결제 시스템 Payment 시스템 구현 세부 사항과 Revenue Playbook Revenue Playbook 구현 세부 사항과