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

Obtiene un identificador de compra del cliente.  Este identificador recupera una clave de identificador de Microsoft Store que se puede usar para conceder derechos de productos gratuitos en nombre del usuario actual.  Esta API se usa en el flujo descrito en [Administración de productos desde sus servicios](https://learn.microsoft.com/gaming/gdk/docs/store/commerce/service-to-service/service-to-service-nav)

## Sintaxis

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

### Parámetros

*storeContextHandle*   \_In\_\
Tipo: XStoreContextHandle

El identificador del contexto de la tienda para el usuario devuelto por [XStoreCreateContext](/reference/system/xstore/functions/xstorecreatecontext).

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

El vale de servicio asociado a la compra.

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

Una cadena que contiene el identificador de usuario del editor.

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

Un [XAsyncBlock](/reference/system/xasync/structs/xasyncblock) que define el trabajo asincrónico que se está realizando. El [XAsyncBlock](/reference/system/xasync/structs/xasyncblock) se puede usar para sondear el estado de la llamada y recuperar los resultados de la llamada. Consulte [XAsyncBlock](/reference/system/xasync/structs/xasyncblock) para obtener más información.

### Valor devuelto

Tipo: HRESULT

HRESULT de operación correcta o código de error.

## Comentarios

Para recuperar el identificador de compra del cliente, así como el resultado de la ejecución de esta función, llame a [XStoreGetUserPurchaseIdResult](/reference/system/xstore/functions/xstoregetuserpurchaseidresult) después de llamar a esta función. Para recuperar el tamaño del identificador de compra del cliente, llame a [XStoreGetUSerPurchaseIdResultSize](/reference/system/xstore/functions/xstoregetuserpurchaseidresultsize) después de llamar a esta función. Conocer el tamaño del resultado le ayudará a leer el resultado de forma más eficiente.

El siguiente fragmento de código muestra un ejemplo de recuperación de un identificador de compra del 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

**Encabezado:** XStore.h (incluido en XGameRuntime.h)

**Biblioteca:** xgameruntime.lib

**Plataformas compatibles:** Windows, consolas de la familia XBOX One y consolas XBOX Series

## Documentación conceptual

* [Solicitud de un identificador de tienda de usuario para la autenticación de servicio a servicio](/publishing/xstore-commerce/xstore-requesting-userstoreid)

## Consulte también

[XStore](/reference/system/xstore/xstore_members)\
[XStoreGetUserPurchaseIdResult](/reference/system/xstore/functions/xstoregetuserpurchaseidresult)\
[XStoreGetUSerPurchaseIdResultSize](/reference/system/xstore/functions/xstoregetuserpurchaseidresultsize)\
[Administración de productos desde sus servicios](https://learn.microsoft.com/gaming/gdk/docs/store/commerce/service-to-service/service-to-service-nav)


## Related topics

- [XStoreGetUserPurchaseIdResult](/es/reference/system/xstore/functions/xstoregetuserpurchaseidresult.md)
- [XStoreGetUserPurchaseIdResultSize](/es/reference/system/xstore/functions/xstoregetuserpurchaseidresultsize.md)
- [Solicitud de un identificador de la Tienda del usuario para la autenticación de servicio a servicio](/es/publishing/xstore-commerce/xstore-requesting-userstoreid.md)
- [Información general sobre el comercio de XStore](/es/publishing/xstore-commerce/xstore-commerce-overview.md)
- [XStore](/es/reference/system/xstore/xstore_members.md)
