콘텐츠로 이동

1단계. 연동 환경 구성

Google Play 콘솔에서 준비한 인증 정보를 Hive 콘솔에 등록하고, 전용 플러그인으로 Google 결제를 구현할 환경을 구성합니다.

1. 스토어 설정 및 콘솔 설정

Google 결제를 사용하려면 Google Play 콘솔에서 결제 계정을 설정하고 라이센스 키를 발급받은 뒤, 해당 키를 Hive 콘솔에 등록해야 합니다.

1.1. Google Play 콘솔 라이센스 키 발급

Google Play 콘솔에서 결제에 필요한 라이센스 키와 마켓 계정 정보를 준비합니다. 자세한 내용은 사전 준비를 참조하세요.

1.2. Hive 콘솔 라이센스 키 입력

Google Play 콘솔에서 발급받은 라이센스 키와 마켓 계정 JSON 파일을 Hive 콘솔의 스토어 설정에 등록합니다. 자세한 내용은 Google Play 인증 정보를 참조하세요.

2. Hive Axyl Google 결제 플러그인 설치

Google Play 결제창 연동에 필요한 Google 결제 플러그인은 com.com2usplatform.hiveaxyl.payments.addon.google 패키지로 제공됩니다. SDK 설치에서 사용한 방법으로 이 패키지를 프로젝트 의존성에 추가합니다.

"dependencies": {
  "com.com2usplatform.hiveaxyl.core": "1.0.0",
  "com.com2usplatform.hiveaxyl.payments": "1.0.0",
  "com.com2usplatform.hiveaxyl.payments.addon.google": "1.0.0"
}

플러그인은 Android 전용이며, Google Play Billing Library 의존성을 함께 구성하므로 Billing Library를 별도로 설치할 필요가 없습니다.

플랫폼 요구 사항

Google 결제 플러그인은 Android API 29 이상에서 동작하며, 내부적으로 Google Play Billing Library 9의 BillingClient를 래핑합니다.

플러그인 등록 및 획득

Google 결제 플러그인을 사용하려면 Hive Axyl 초기화 시 builder.AddPlayBilling()으로 플러그인을 등록하고, 사용할 때 HiveCore.TryResolve<IGooglePlayBillingPlugin>()으로 플러그인 인스턴스를 가져옵니다.

using Hive.Axyl.Core;
using Hive.Axyl.Core.Unity;
using Hive.Axyl.Payments;
using Hive.Axyl.Payments.Addon.Google;

// Axyl 초기화 시 Google 결제 플러그인 등록
HiveBootstrap.Initialize(config, builder =>
{
    builder.AddPayments(sandbox: true);  // 결제 (IPaymentsService). 개발·테스트 환경. 실제 서비스 빌드는 AddPayments()
    builder.AddPlayBilling();            // Google 결제 플러그인 (IGooglePlayBillingPlugin)
});
// 사용 시점에 플러그인 획득
if (!HiveCore.TryResolve<IGooglePlayBillingPlugin>(out var googlePlugin))
{
    Debug.LogError("Google Play Billing 플러그인이 등록되지 않았습니다.");
    return;
}

BillingClient 연결

Google 결제 플러그인의 모든 결제 기능(QueryProductDetailsAsync, LaunchBillingFlowAsync, QueryPurchasesAsync, ConsumeAsync, AcknowledgePurchaseAsync)은 BillingClient가 연결된 상태에서만 동작합니다. 플러그인은 자동으로 BillingClient를 연결하지 않으므로, 결제 기능을 사용하기 전에 반드시 StartConnectionAsync()를 호출하세요.

StartConnectionAsync()의 결과를 분기할 때, 플러그인에 공통인 Failure와 HiveError, 메서드별 도메인 결과(Outcome)의 구분은 공통 오류 처리를 참조하세요.

using Hive.Axyl.Payments.Addon.Google;
using System.Threading;

// BillingClient 연결 (모든 결제 기능 호출 전 필수)
GooglePlayBillingServiceStartConnectionResult connResult =
    await googlePlugin.StartConnectionAsync(CancellationToken.None);

switch (connResult)
{
    case GooglePlayBillingServiceStartConnectionResult.Success:
        // 연결 성공. 결제 기능 사용 가능
        break;

    case GooglePlayBillingServiceStartConnectionResult.AlreadyConnected:
        // 이미 연결된 상태. 추가 작업 불필요
        break;

    case GooglePlayBillingServiceStartConnectionResult.UnknownOutcome:
        Debug.LogWarning("알 수 없는 연결 결과입니다.");
        break;

    case GooglePlayBillingServiceStartConnectionResult.Failure failure:
        Debug.LogError($"BillingClient 연결 실패: {failure}");
        break;

    default:
        Debug.LogWarning($"처리되지 않은 결과: {connResult.GetType().Name}");
        break;
}
연결 해제 이벤트 처리

Google Play BillingClient는 서비스 연결이 끊어지면 BillingServiceDisconnected 이벤트를 발생시킵니다. 플러그인은 자동으로 재연결하지 않으므로, 이 이벤트를 구독해 필요 시 StartConnectionAsync()를 다시 호출하세요.

googlePlugin.BillingServiceDisconnected += () =>
{
    Debug.LogWarning("BillingClient 연결이 해제되었습니다. 재연결이 필요합니다.");
    // 필요 시 StartConnectionAsync() 재호출
};

앱 종료 시 또는 결제 기능을 더 이상 사용하지 않을 때 EndConnectionAsync()를 호출해 BillingClient 연결을 해제합니다.

// BillingClient 연결 해제 (앱 종료 시 또는 결제 기능 미사용 시)
await googlePlugin.EndConnectionAsync(CancellationToken.None);

3. 선택: Hive 콘솔 상품별 가격 등급 설정

Google Play 결제에서는 실제 결제 가격이 Google Play 스토어에서 관리됩니다. Hive 콘솔에서 입력한 가격 정보는 Hive 콘솔에서 확인하는 용도로만 사용되므로 선택 사항입니다.

가격 등급을 설정하려면 가격 등급을 참조하세요.

4. Hive 콘솔 상품 등록

판매할 상품을 등록하는 방법은 상품 등록을 참조하세요.

Caution

Google Play에 등록한 상품과 Hive 콘솔에 등록한 상품의 Product ID는 서로 일치해야 합니다. Google Play 콘솔에 입력된 정보를 활용하는 것을 권장합니다.

다음 단계

Google Play에 등록된 상품 목록을 조회합니다.