SubXDocs

SDK Integration

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

Learn how to integrate subscription payments into iOS and Android apps using the SubX SDK.

API Key

Both the SDK and server API use the same API key. You can generate one from the API Keys menu in the dashboard.

주의: Warning: API keys are only shown in full immediately after creation. Copy it right away and store it somewhere safe. Only use it in server environments — do not embed it directly in client code.

iOS (Swift)

Installation

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

Initialization

import SubX

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

Get Offerings

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

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

Handle Purchase

// 월간 패키지 구매
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)")
}

Check Entitlement

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

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

Android (Kotlin)

Installation

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

Initialization

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

Get Offerings

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

Handle Purchase

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}")
        }
    }
}

Check Entitlement

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

Check Subscription Status on Server

Use an API key on the server to query a customer's subscription status or perform management tasks.

// 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
);

Manage with AI Tools (MCP)

SubX supports an MCP (Model Context Protocol) server. Connect SubX to AI tools like Claude or Cursor to perform all management tasks — product registration, offering configuration, customer lookup — through conversation alone.

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

See the MCP Integration guide for detailed configuration steps.MCP Integration를 참고하세요.


Next Steps

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