SubXDocs

SDK 연동

Coming Soon — SDK는 현재 개발 중입니다. 아래 코드는 예정된 API 형태이며, 정식 출시 전까지 변경될 수 있습니다.

SubX SDK를 사용하여 iOS 및 Android 앱에 구독 결제를 연동하는 방법을 설명합니다.

API 키

SDK와 서버 API 모두 동일한 API 키를 사용합니다. 대시보드의 API 키 메뉴에서 발급받을 수 있습니다.

주의: 주의: API 키는 생성 직후 한 번만 전체 값이 표시됩니다. 바로 복사해서 안전한 곳에 보관하세요. 서버 환경에서만 사용하고 클라이언트 코드에 직접 넣지 마세요.

iOS (Swift)

설치

Package.swift
dependencies: [
    .package(url: "https://github.com/mikusnuz/subx-ios.git", from: "1.0.0")
]

초기화

import SubX

// AppDelegate 또는 @main App에서
SubX.configure(apiKey: "your_api_key")

오퍼링 조회

let offerings = try await SubX.shared.getOfferings()

if let current = offerings.current {
    // 패키지 목록
    for package in current.availablePackages {
        print("\(package.identifier): \(package.localizedPriceString)")
    }
}

구매 처리

// 월간 패키지 구매
let package = offerings.current?.monthly

do {
    let result = try await SubX.shared.purchase(package: package!)

    if result.customerInfo.entitlements["pro"]?.isActive == true {
        // Pro 기능 활성화
        unlockProFeatures()
    }
} catch SubXError.purchaseCancelled {
    // 사용자가 취소
} catch {
    // 구매 실패
    print("Purchase failed: \(error)")
}

권한 확인

let customerInfo = try await SubX.shared.getCustomerInfo()

if customerInfo.entitlements["pro"]?.isActive == true {
    // Pro 기능 활성화됨
}

Android (Kotlin)

설치

build.gradle.kts
dependencies {
    implementation("dev.subx:subx-android:1.0.0")
}

초기화

// Application 클래스에서
class MyApp : Application() {
    override fun onCreate() {
        super.onCreate()
        SubX.configure(this, "your_api_key")
    }
}

오퍼링 조회

SubX.shared.getOfferings { offerings ->
    offerings.current?.let { current ->
        current.availablePackages.forEach { pkg ->
            Log.d("SubX", "${pkg.identifier}: ${pkg.product.price}")
        }
    }
}

구매 처리

val package = offerings.current?.monthly ?: return

SubX.shared.purchase(
    activity = this,
    package = package
) { result ->
    when (result) {
        is PurchaseResult.Success -> {
            if (result.customerInfo.entitlements["pro"]?.isActive == true) {
                unlockProFeatures()
            }
        }
        is PurchaseResult.Cancelled -> {
            // 사용자가 취소
        }
        is PurchaseResult.Error -> {
            Log.e("SubX", "Purchase failed: ${result.error}")
        }
    }
}

권한 확인

SubX.shared.getCustomerInfo { customerInfo ->
    if (customerInfo.entitlements["pro"]?.isActive == true) {
        // Pro 기능 활성화됨
    }
}

서버에서 구독 상태 확인하기

서버에서 API 키를 사용하여 고객의 구독 상태를 조회하거나 관리 작업을 수행할 수 있습니다.

// Node.js 예시
const response = await fetch(
  "https:1
  {
    headers: {
      "X-API-Key": "your_api_key"
    }
  }
);

const customer = await response.json();

2
const hasPro = customer.entitlements?.some(
  e => e.lookupKey === "pro" && e.isActive
);

AI 도구로 관리하기 (MCP)

SubX는 MCP(Model Context Protocol) 서버를 지원합니다. Claude, Cursor 등 AI 도구에서 SubX를 연결하면 대화만으로 상품 등록, 오퍼링 구성, 고객 조회 등 모든 관리 작업을 수행할 수 있습니다.

settings.json
{
  "mcpServers": {
    "subx-mcp": {
      "command": "npx",
      "args": ["-y", "subx-mcp"],
      "env": { "SUBX_API_KEY": "your_api_key" }
    }
  }
}

자세한 설정 방법은 MCP 연동를 참고하세요.


다음 단계

  • REST API — 전체 API 엔드포인트를 확인합니다.
  • 웹훅 — 서버에서 구독 이벤트를 수신합니다.
  • 스토어 연동 — App Store Connect / Google Play Console 설정 방법을 확인합니다.
SDK 연동 | SubX