> For AI agents: the complete documentation index is available at https://docs.somiri.dev/breeze-iap/ko/llms.txt, the full documentation bundle is available at https://docs.somiri.dev/breeze-iap/ko/llms-full.txt.

# 타입 정의

## InitializeDto

스토어에 등록할 상품 하나를 정의하는 구조체입니다.

```csharp
public readonly struct InitializeDto
{
    public string      ProductId   { get; init; }
    public ProductType ProductType { get; init; }
}
```

| 필드            | 타입            | 설명                                                                                               |
| ------------- | ------------- | ------------------------------------------------------------------------------------------------ |
| `ProductId`   | `string`      | App Store Connect / Google Play Console에 등록된 상품 ID와 정확히 일치해야 합니다.                                |
| `ProductType` | `ProductType` | `Consumable`(소모성), `NonConsumable`(비소모성), `Subscription`(구독) — `UnityEngine.Purchasing`에서 제공합니다. |

### 예시

```csharp
new InitializeDto { ProductId = "gold_100",  ProductType = ProductType.Consumable }
new InitializeDto { ProductId = "no_ads",    ProductType = ProductType.NonConsumable }
new InitializeDto { ProductId = "vip_month", ProductType = ProductType.Subscription }
```

***

## PurchaseResult

[`PurchaseAsync`](https://docs.somiri.dev/breeze-iap/ko/api/purchase.md) 반환값 또는 [`GetPendingList`](https://docs.somiri.dev/breeze-iap/ko/api/pending.md)의 항목입니다.

```csharp
public readonly struct PurchaseResult
{
    public PurchaseType Type          { get; init; }
    public Product      Product       { get; init; }
    public PendingOrder Order         { get; init; }
    public string       ErrorMessage  { get; init; }
    public string       Receipt       => Order?.Info?.Receipt;
    public string       TransactionId => Order?.Info?.TransactionID;
    public bool         IsSuccess     => string.IsNullOrEmpty(ErrorMessage);
}
```

| 필드              | 타입                              | 설명                                                                                                                               |
| --------------- | ------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| `Type`          | [`PurchaseType`](#purchasetype) | 구매가 어떤 경로로 도달했는지를 나타냅니다.                                                                                                         |
| `Product`       | `Product`                       | Unity IAP `Product` 객체. `Product.definition.id`로 상품 ID를 가져옵니다.                                                                   |
| `Order`         | `PendingOrder`                  | Unity IAP v5 주문. [`Confirm`](https://docs.somiri.dev/breeze-iap/ko/api/confirm.md)에 전달하여 구매를 확정합니다. 실패/Deferred 결과에서는 `null`입니다. |
| `ErrorMessage`  | `string`                        | `IsSuccess`가 `false`일 때 실패 이유가 담겨 있습니다.                                                                                          |
| `Receipt`       | `string`                        | `Order.Info.Receipt`에서 가져온 영수증 JSON. 서버 검증에 사용합니다.                                                                               |
| `TransactionId` | `string`                        | `Order.Info.TransactionID`에서 가져온 스토어 트랜잭션 ID.                                                                                    |
| `IsSuccess`     | `bool`                          | `ErrorMessage`가 비어있으면 `true`.                                                                                                    |

### 자주 사용하는 패턴

```csharp
var result = await BreezeIAP.PurchaseAsync("gold_100");

// 성공 여부 확인
if (!result.IsSuccess)
{
    Debug.LogWarning(result.ErrorMessage);
    return;
}

// 상품 ID 가져오기
string productId = result.Product.definition.id;

// 서버 검증용 데이터
string receipt       = result.Receipt;
string transactionId = result.TransactionId;
```

***

## PurchaseType

`PurchaseResult.Type`에 설정되는 열거형으로, 구매가 어떤 경로로 도달했는지를 나타냅니다.

```csharp
public enum PurchaseType
{
    Purchase,  // 정상 구매 흐름
    Pending,   // 이전 세션에서 재전달된 미확정 구매
    Deferred,  // 외부 승인 대기 중 (예: Ask to Buy)
    Restore,   // iOS 복원을 통해 도달
    Error      // 구매 실패
}
```

| 값          | 설명                                    | Confirm 필요 |
| ---------- | ------------------------------------- | ---------- |
| `Purchase` | 사용자가 직접 구매 완료                         | ✅          |
| `Pending`  | 이전 세션의 미확정 구매 (`GetPendingList`에서 도달) | ✅          |
| `Deferred` | Ask to Buy 등 외부 승인 대기 — 아직 결제되지 않음    | ❌          |
| `Restore`  | iOS 복원을 통해 도달                         | ✅          |
| `Error`    | 구매 실패                                 | ❌          |

`Deferred`와 `Error`는 `Order`가 `null`이므로 `Confirm`을 호출하지 않아야 합니다.
