> ## 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

Obtém uma ID de compra do cliente. Essa ID recupera uma chave de ID da Microsoft Store que pode ser usada para conceder direitos a produtos gratuitos em nome do usuário atual. Esta API é usada no fluxo descrito em [Gerenciar produtos de seus serviços](https://learn.microsoft.com/gaming/gdk/docs/store/commerce/service-to-service/service-to-service-nav)

## Sintaxe

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

### Parâmetros

*storeContextHandle*   \_In\_\
Tipo: XStoreContextHandle

O identificador de contexto da loja do usuário retornado por [XStoreCreateContext](/pt-BR/reference/system/xstore/functions/xstorecreatecontext).

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

O tíquete de serviço associado à compra.

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

Uma cadeia de caracteres que contém a ID de usuário do editor.

*async*   \_Inout\_\
Tipo: [XAsyncBlock\*](/pt-BR/reference/system/xasync/structs/xasyncblock)

Um [XAsyncBlock](/pt-BR/reference/system/xasync/structs/xasyncblock) que define o trabalho assíncrono que está sendo feito. O [XAsyncBlock](/pt-BR/reference/system/xasync/structs/xasyncblock) pode ser usado para sondar o status da chamada e recuperar os resultados da chamada. Consulte [XAsyncBlock](/pt-BR/reference/system/xasync/structs/xasyncblock) para obter mais informações.

### Valor retornado

Tipo: HRESULT

Código de êxito ou de erro HRESULT.

## Comentários

Para recuperar a ID de compra do cliente, bem como o resultado da execução desta função, chame [XStoreGetUserPurchaseIdResult](/pt-BR/reference/system/xstore/functions/xstoregetuserpurchaseidresult) após chamar esta função. Para recuperar o tamanho da ID de compra do cliente, chame [XStoreGetUSerPurchaseIdResultSize](/pt-BR/reference/system/xstore/functions/xstoregetuserpurchaseidresultsize) após chamar esta função. Saber o tamanho do resultado ajudará você a lê-lo com mais eficiência.

O snippet de código a seguir mostra um exemplo de recuperação de uma ID de compra do cliente.

```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;
    }
}
```

## Requisitos

**Cabeçalho:** XStore.h (incluído em XGameRuntime.h)

**Biblioteca:** xgameruntime.lib

**Plataformas com suporte:** Windows, consoles da família XBOX One e consoles XBOX Series

## Documentação conceitual

* [Solicitando uma ID da Loja do Usuário para autenticação serviço a serviço](/pt-BR/publishing/xstore-commerce/xstore-requesting-userstoreid)

## Confira também

[XStore](/pt-BR/reference/system/xstore/xstore_members)\
[XStoreGetUserPurchaseIdResult](/pt-BR/reference/system/xstore/functions/xstoregetuserpurchaseidresult)\
[XStoreGetUSerPurchaseIdResultSize](/pt-BR/reference/system/xstore/functions/xstoregetuserpurchaseidresultsize)\
[Gerenciar produtos de seus serviços](https://learn.microsoft.com/gaming/gdk/docs/store/commerce/service-to-service/service-to-service-nav)


## Related topics

- [XStoreGetUserPurchaseIdAsync](/es/reference/system/xstore/functions/xstoregetuserpurchaseidasync.md)
- [XStoreGetUserPurchaseIdResult](/reference/system/xstore/functions/xstoregetuserpurchaseidresult.md)
