diff --git a/android/build.gradle b/android/build.gradle index 5f408e2..191f716 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -43,7 +43,7 @@ android { } dependencies { - implementation "com.superwall.sdk:superwall-android:2.6.1" + implementation "com.superwall.sdk:superwall-android:2.6.2" implementation 'com.android.billingclient:billing:8.0.0' implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.2' } diff --git a/android/src/main/java/expo/modules/superwallexpo/SuperwallExpoModule.kt b/android/src/main/java/expo/modules/superwallexpo/SuperwallExpoModule.kt index 0aa9837..a17abd8 100644 --- a/android/src/main/java/expo/modules/superwallexpo/SuperwallExpoModule.kt +++ b/android/src/main/java/expo/modules/superwallexpo/SuperwallExpoModule.kt @@ -402,5 +402,20 @@ class SuperwallExpoModule : Module() { Superwall.instance.logLevel = logLevel } } + + AsyncFunction("consume") { purchaseToken, promise: Promise -> + ioScope.launch { + Superwall.instance.consume(purchaseToken) + .fold({ result -> + scope.launch { + promise.resolve(result) + } + }, { error -> + scope.launch { + promise.reject(CodedException(error)) + } + }) + } + } } } diff --git a/src/SuperwallExpoModule.ts b/src/SuperwallExpoModule.ts index 5998ef9..9ded365 100644 --- a/src/SuperwallExpoModule.ts +++ b/src/SuperwallExpoModule.ts @@ -58,6 +58,8 @@ declare class SuperwallExpoModule extends NativeModule + setLogLevel(level: string): void } diff --git a/src/compat/index.ts b/src/compat/index.ts index fb641e4..6120254 100644 --- a/src/compat/index.ts +++ b/src/compat/index.ts @@ -631,6 +631,18 @@ export default class Superwall { await SuperwallExpoModule.preloadPaywalls(Array.from(placementNames)) } + /** + * Initiates a consumption of an In-App product. + * + * Use this function to consume an In-App product after processing it in your application. + * + * @param {string} purchaseToken - The token related to the purchase you wish to consume. + * @return {Promise} Containing the consumed token, or an error. + */ + async consume(purchaseToken: string): Promise { + return await SuperwallExpoModule.consume(purchaseToken) + } + /** * Sets user attributes for use in paywalls and on the Superwall dashboard. * diff --git a/src/useSuperwall.ts b/src/useSuperwall.ts index 70fae0b..c3e52af 100644 --- a/src/useSuperwall.ts +++ b/src/useSuperwall.ts @@ -262,6 +262,9 @@ export const useSuperwallStore = create((set, get) => ({ const attributes = await SuperwallExpoModule.getDeviceAttributes() return attributes }, + consume: async (purchaseToken: string) => { + return await SuperwallExpoModule.consume(purchaseToken) + }, /* -------------------- Listener helpers -------------------- */ _initListeners: (): (() => void) => {