> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XStoreGetUserPurchaseIdAsync

> XStoreGetUserPurchaseIdAsync

# XStoreGetUserPurchaseIdAsync

顧客購入 ID を取得します。この ID は、現在のユーザーの代わりに無料製品の権利を付与するために使用できる Microsoft Store ID キーを取得します。この API は、[サービスから製品を管理する](https://learn.microsoft.com/gaming/gdk/docs/store/commerce/service-to-service/service-to-service-nav)で説明されているフローで使用されます。

## 構文

```cpp theme={null}
HRESULT XStoreGetUserPurchaseIdAsync(  
         const XStoreContextHandle storeContextHandle,  
         const char* serviceTicket,  
         const char* publisherUserId,  
         XAsyncBlock* async  
)  
```

### パラメーター

*storeContextHandle*   \_In\_\
Type: XStoreContextHandle

[XStoreCreateContext](/reference/system/xstore/functions/xstorecreatecontext) から返される、ユーザーのストア コンテキスト ハンドル。

*serviceTicket*   \_In\_z\_\
Type: char\*

購入に関連付けられているサービス チケット。

*publisherUserId*   \_In\_z\_\
Type: char\*

パブリッシャーのユーザー ID を含む文字列。

*async*   \_Inout\_\
Type: [XAsyncBlock\*](/reference/system/xasync/structs/xasyncblock)

実行中の非同期処理を定義する [XAsyncBlock](/reference/system/xasync/structs/xasyncblock)。[XAsyncBlock](/reference/system/xasync/structs/xasyncblock) は、呼び出しの状態のポーリングと呼び出し結果の取得に使用できます。詳細については、[XAsyncBlock](/reference/system/xasync/structs/xasyncblock) を参照してください。

### 戻り値

Type: HRESULT

HRESULT の成功またはエラー コード。

## 解説

顧客の購入 ID とこの関数の実行結果を取得するには、この関数を呼び出した後に [XStoreGetUserPurchaseIdResult](/reference/system/xstore/functions/xstoregetuserpurchaseidresult) を呼び出します。顧客の購入 ID のサイズを取得するには、この関数を呼び出した後に [XStoreGetUSerPurchaseIdResultSize](/reference/system/xstore/functions/xstoregetuserpurchaseidresultsize) を呼び出します。結果のサイズを事前に知ることで、より効率的に結果を読み取ることができます。

次のコード スニペットは、顧客購入 ID を取得する例を示しています。

```cpp theme={null}
void CALLBACK GetUserPurchaseIdCallback(XAsyncBlock* asyncBlock)
{
    size_t size;
    HRESULT hr = XStoreGetUserPurchaseIdResultSize(
        asyncBlock,
        &size);

    if (FAILED(hr))
    {
        printf("Failed retrieve the user purchase ID size: 0x%x\r\n", hr);
        return;
    }

    char* result = new char[size];
    hr = XStoreGetUserPurchaseIdResult(
        asyncBlock,
        size,
        result);

    if (FAILED(hr))
    {
        printf("Failed retrieve the user purchase ID result: 0x%x\r\n", hr);
        delete[] result;
        return;
    }

    printf("result: %s\r\n", result);

    delete[] result;
}

void GetUserPurchaseId(XStoreContextHandle storeContextHandle, XTaskQueueHandle taskQueueHandle, const char* serviceTicket, const char* publisherUserId)
{
    auto asyncBlock = std::make_unique<XAsyncBlock>();
    ZeroMemory(asyncBlock.get(), sizeof(*asyncBlock));
    asyncBlock->queue = taskQueueHandle;

    asyncBlock->callback = GetUserPurchaseIdCallback;

    HRESULT hr = XStoreGetUserPurchaseIdAsync(
        storeContextHandle,
        serviceTicket,
        publisherUserId,
        asyncBlock.get());

    if (FAILED(hr))
    {
        printf("Failed to get user purchase ID: 0x%x\r\n", hr);
        return;
    }
}
```

## 要件

**ヘッダー:** XStore.h (XGameRuntime.h に含まれる)

**ライブラリ:** xgameruntime.lib

**サポートされているプラットフォーム:** Windows、XBOX One 本体および XBOX Series 本体

## 関連概念ドキュメント

* [サービス間認証用のユーザー ストア ID を要求する](https://learn.microsoft.com/gaming/gdk/docs/store/commerce/service-to-service/xstore-requesting-a-userstoreid)

## 関連項目

[XStore](/reference/system/xstore/xstore_members)\
[XStoreGetUserPurchaseIdResult](/reference/system/xstore/functions/xstoregetuserpurchaseidresult)\
[XStoreGetUSerPurchaseIdResultSize](/reference/system/xstore/functions/xstoregetuserpurchaseidresultsize)\
[サービスから製品を管理する](https://learn.microsoft.com/gaming/gdk/docs/store/commerce/service-to-service/service-to-service-nav)


## Related topics

- [XStoreGetUserPurchaseIdResult](/ja-jp/reference/system/xstore/functions/xstoregetuserpurchaseidresult.md)
- [XStoreGetUserPurchaseIdResultSize](/ja-jp/reference/system/xstore/functions/xstoregetuserpurchaseidresultsize.md)
- [サービス間認証用のユーザー Store ID を要求する](/ja-jp/publishing/xstore-commerce/xstore-requesting-userstoreid.md)
- [XStore コマースの概要](/ja-jp/publishing/xstore-commerce/xstore-commerce-overview.md)
- [XStore](/ja-jp/reference/system/xstore/xstore_members.md)
