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
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:
- No
onPurchaseRequest handler is registered on the native side
- The native SDK successfully completes a purchase
- 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
const unsubscribe = Encore.onPurchaseComplete(({ productId, transactionId }) => {
// Sync purchase state with your subscription manager
console.log(`Purchase complete: ${productId}`);
});
Clean up the listener when your component unmounts by calling the returned unsubscribe function.