Skip to main content

SDK Reference - addEventListener

React native
Flutter
Swift
Kotlin

The addEventListener method lets you listen to the events triggered by the IAPHUB SDK.

Available Events:

onUserUpdate

This event is triggered whenever there's an update to the user's products, whether it's a subscription cancellation, expiration, renewal, or changes to products for sale. When this event is triggered, you can seamlessly refresh both your data and user interface by utilizing the getProducts method.

var listener = Iaphub.addEventListener('onUserUpdate', () => {
  // Refresh your data and UI here
});
React Native
Flutter
Swift
Kotlin

onDeferredPurchase

Triggered when a purchase has been processed outside of the buy method. This may occur in scenarios such as:

  • Making a purchase outside the app (e.g., by redeeming a promo code on the store)
  • Experiencing a deferred payment (when the error code deferred_payment is returned by the buy method)
  • Encountering a payment failure due to validation issues by IAPHUB, which may succeed at a later time.
var listener = Iaphub.addEventListener('onDeferredPurchase', (transaction) => {
  // Process deferred transaction
});
React Native
Flutter
Swift
Kotlin

onBuyRequest

Triggered when a purchase intent is made from outside the app, like a promoted In-App purchase (iOS only).
You should call the buy method if you'd like to process the purchase.

var listener = Iaphub.addEventListener('onBuyRequest', (sku) => {
  // Call the buy method if you'd like to process the purchase
});
React Native
Flutter
Swift
Kotlin

onReceipt

Triggered after a receipt has been processed.

var listener = Iaphub.addEventListener('onReceipt', (data) => {
  console.log("Receipt err: ", data.err);
  console.log("Receipt data: ", err.receipt);
});
React Native
Flutter
Swift
Kotlin

onError

Triggered when IAPHUB detects an error.

var listener = Iaphub.addEventListener('onError', (err) => {
  // You'll be able to catch any errors here, including those thrown by IAPHUB methods.
  console.log("Error: ", err.message);
});
React Native
Flutter
Swift
Kotlin

Parameters

StringEvent name
FunctionEvent callback

Response

ObjectEvent listener