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

# onPurchaseComplete()

> Callback invoked after a native purchase completes

Registers a listener invoked after a native purchase completes. This fires when the native SDK handles the purchase directly (i.e., no `onPurchaseRequest` handler is set on the native side).

## Signature

```tsx theme={null}
onPurchaseComplete(handler: (event: PurchaseCompleteEvent) => void): () => void
```

## Parameters

| Name      | Type                                     | Description                                    |
| --------- | ---------------------------------------- | ---------------------------------------------- |
| `handler` | `(event: PurchaseCompleteEvent) => void` | Callback receiving the purchase complete event |

### PurchaseCompleteEvent

| Field           | Type    | Description                         |
| --------------- | ------- | ----------------------------------- |
| `productId`     | string  | The product ID that was purchased   |
| `transactionId` | string? | iOS: StoreKit transaction ID        |
| `purchaseToken` | string? | Android: Google Play purchase token |
| `orderId`       | string? | Android: Google Play order ID       |

## Returns

An unsubscribe function. Call it to remove the listener.

## When It Fires

`onPurchaseComplete` fires **only** when:

1. No `onPurchaseRequest` handler is registered on the native side
2. The native SDK successfully completes a purchase
3. The transaction is verified and finished

It does **not** fire when:

* An `onPurchaseRequest` handler is set (the handler takes full responsibility)
* The user cancels the purchase
* The purchase fails or is pending

## Usage

```tsx theme={null}
const unsubscribe = Encore.onPurchaseComplete(({ productId, transactionId }) => {
  // Sync purchase state with your subscription manager
  console.log(`Purchase complete: ${productId}`);
});
```

<Tip>
  Clean up the listener when your component unmounts by calling the returned unsubscribe function.
</Tip>
