From 10452b04718dc9f0e7249347ae240c28e9f16de5 Mon Sep 17 00:00:00 2001 From: Sumita Canopas Date: Mon, 18 Nov 2024 10:41:02 +0530 Subject: [PATCH] Add common NamiPurchaseSuccess Type --- examples/Basic/App.tsx | 14 +++++++------- examples/TestNamiTV/App.tsx | 6 +++--- src/NamiEntitlementManager.d.ts | 2 +- src/NamiEntitlementManager.ts | 2 +- src/NamiPaywallManager.d.ts | 2 ++ src/NamiPaywallManager.ts | 5 +++++ src/types.d.ts | 13 +++++++++++++ src/types.ts | 14 ++++++++++++++ 8 files changed, 46 insertions(+), 12 deletions(-) diff --git a/examples/Basic/App.tsx b/examples/Basic/App.tsx index 0ea465ef..cc7a725b 100644 --- a/examples/Basic/App.tsx +++ b/examples/Basic/App.tsx @@ -53,7 +53,7 @@ const Tab = createBottomTabNavigator(); const App = () => { const [subscriptions, setSubscriptions] = useState([]); const [products, setProducts] = useState([]); - const [namiSku, setNamiSku] = useState(undefined); + const [namiSku, setNamiSku] = useState({} as NamiSKU); useEffect(() => { Linking.addEventListener('url', handleDeepLink); @@ -103,13 +103,13 @@ const App = () => { } if (Platform.OS === 'ios' || Platform.isTV) { - console.log('Preparing to call buySkuCompleteApple'); + console.log('Preparing to call buySkuComplete with Apple'); console.log(namiSku); console.log(purchase.transactionId); console.log(purchase.originalTransactionIdentifierIOS); - NamiPaywallManager.buySkuCompleteApple({ + NamiPaywallManager.buySkuComplete({ product: namiSku, transactionID: purchase.transactionId ?? '', originalTransactionID: purchase.originalTransactionIdentifierIOS ?? purchase.transactionId ?? '', @@ -118,8 +118,8 @@ const App = () => { }); } else if (Platform.OS === 'android') { if (Platform.constants.Manufacturer === 'Amazon') { - console.log('Preparing to call buySkuCompleteAmazon'); - NamiPaywallManager.buySkuCompleteAmazon({ + console.log('Preparing to call buySkuComplete with Amazon'); + NamiPaywallManager.buySkuComplete({ product: namiSku, receiptId: purchase.transactionId ?? '', localizedPrice: price, @@ -127,8 +127,8 @@ const App = () => { marketplace: purchase.userMarketplaceAmazon ?? '', }); } else { - console.log('Preparing to call buySkuCompleteGooglePlay'); - NamiPaywallManager.buySkuCompleteGooglePlay({ + console.log('Preparing to call buySkuComplete with GooglePlay'); + NamiPaywallManager.buySkuComplete({ product: namiSku, purchaseToken: purchase.purchaseToken ?? '', orderId: purchase.transactionId ?? '', diff --git a/examples/TestNamiTV/App.tsx b/examples/TestNamiTV/App.tsx index 1b887f44..95a4b393 100644 --- a/examples/TestNamiTV/App.tsx +++ b/examples/TestNamiTV/App.tsx @@ -61,7 +61,7 @@ const App = () => { NamiPaywallManager.dismiss(); if (Platform.OS === 'ios') { - NamiPaywallManager.buySkuCompleteApple({ + NamiPaywallManager.buySkuComplete({ product: sku, transactionID: '12345', originalTransactionID: '12345', @@ -70,7 +70,7 @@ const App = () => { }); } else if (Platform.OS === 'android') { if (Platform.constants.Manufacturer === 'Amazon') { - NamiPaywallManager.buySkuCompleteAmazon({ + NamiPaywallManager.buySkuComplete({ product: sku, receiptId: '12345', localizedPrice: '120', @@ -78,7 +78,7 @@ const App = () => { marketplace: 'US', }); } else { - NamiPaywallManager.buySkuCompleteGooglePlay({ + NamiPaywallManager.buySkuComplete({ product: sku, purchaseToken: 'jolbnkpmojnpnjecgmphbmkc.AO-J1OznE4AIzyUvKFe1RSVkxw4KEtv0WfyL_tkzozOqnlSvIPsyQJBphCN80gwIMaex4EMII95rFCZhMCbVPZDc-y_VVhQU5Ddua1dLn8zV7ms_tdwoDmE', diff --git a/src/NamiEntitlementManager.d.ts b/src/NamiEntitlementManager.d.ts index 112b05ce..279c3095 100644 --- a/src/NamiEntitlementManager.d.ts +++ b/src/NamiEntitlementManager.d.ts @@ -7,7 +7,7 @@ export declare enum NamiEntitlementManagerEvents { export interface INamiEntitlementManager { emitter: NativeEventEmitter; active: () => Promise>; - isEntitlementActive: (label?: string) => boolean; + isEntitlementActive: (label: string) => boolean; refresh: (resultCallback?: (entitlements?: NamiEntitlement[]) => void) => void; registerActiveEntitlementsHandler: (callback: (activeEntitlements: NamiEntitlement[]) => void) => EmitterSubscription['remove']; clearProvisionalEntitlementGrants: () => void; diff --git a/src/NamiEntitlementManager.ts b/src/NamiEntitlementManager.ts index 08a9a44e..784fe651 100644 --- a/src/NamiEntitlementManager.ts +++ b/src/NamiEntitlementManager.ts @@ -15,7 +15,7 @@ export enum NamiEntitlementManagerEvents { export interface INamiEntitlementManager { emitter: NativeEventEmitter; active: () => Promise>; - isEntitlementActive: (label?: string) => boolean; + isEntitlementActive: (label: string) => boolean; refresh: ( resultCallback?: (entitlements?: NamiEntitlement[]) => void, ) => void; diff --git a/src/NamiPaywallManager.d.ts b/src/NamiPaywallManager.d.ts index eea6815d..a0158df9 100644 --- a/src/NamiPaywallManager.d.ts +++ b/src/NamiPaywallManager.d.ts @@ -1,5 +1,6 @@ import { NativeEventEmitter, EmitterSubscription } from 'react-native'; import { NamiPurchaseSuccessAmazon, NamiPurchaseSuccessApple, NamiPurchaseSuccessGooglePlay, NamiSKU } from './types'; +import { NamiPurchaseSuccess } from './types'; export declare enum NamiPaywallManagerEvents { RegisterBuySKU = "RegisterBuySKU", PaywallCloseRequested = "PaywallCloseRequested", @@ -16,6 +17,7 @@ export interface INamiPaywallManager { buySkuCompleteApple: (purchaseSuccess: NamiPurchaseSuccessApple) => void; buySkuCompleteAmazon: (purchaseSuccess: NamiPurchaseSuccessAmazon) => void; buySkuCompleteGooglePlay: (purchaseSuccess: NamiPurchaseSuccessGooglePlay) => void; + buySkuComplete: (purchaseSuccess: NamiPurchaseSuccess) => void; buySkuCancel: () => void; registerBuySkuHandler: (callback: (sku: NamiSKU) => void) => EmitterSubscription['remove']; registerCloseHandler: (callback: () => void) => EmitterSubscription['remove']; diff --git a/src/NamiPaywallManager.ts b/src/NamiPaywallManager.ts index f79a491e..0e5453cb 100644 --- a/src/NamiPaywallManager.ts +++ b/src/NamiPaywallManager.ts @@ -4,6 +4,7 @@ import { EmitterSubscription, } from 'react-native'; import { + NamiPurchaseSuccess, NamiPurchaseSuccessAmazon, NamiPurchaseSuccessApple, NamiPurchaseSuccessGooglePlay, @@ -30,6 +31,7 @@ export interface INamiPaywallManager { buySkuCompleteGooglePlay: ( purchaseSuccess: NamiPurchaseSuccessGooglePlay, ) => void; + buySkuComplete: (purchaseSuccess: NamiPurchaseSuccess) => void; buySkuCancel: () => void; registerBuySkuHandler: ( callback: (sku: NamiSKU) => void, @@ -59,6 +61,9 @@ export const NamiPaywallManager: INamiPaywallManager = { paywallEmitter: new NativeEventEmitter(RNNamiPaywallManager), ...RNNamiPaywallManager, ...NamiPaywallManagerBridge, + buySkuComplete: (purchaseSuccess: NamiPurchaseSuccess) => { + RNNamiPaywallManager.buySkuComplete(purchaseSuccess); + }, buySkuCompleteApple: (purchaseSuccess: NamiPurchaseSuccessApple) => { RNNamiPaywallManager.buySkuComplete(purchaseSuccess); }, diff --git a/src/types.d.ts b/src/types.d.ts index 9d604bbb..ff2c05f4 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -132,6 +132,19 @@ export type NamiPurchaseSuccessAmazon = { userId: string; marketplace: string; }; +export type NamiPurchaseSuccess = { + product: NamiSKU; + transactionID?: string; + originalTransactionID?: string; + price?: string; + currencyCode?: string; + orderId?: string; + purchaseToken?: string; + receiptId?: string; + localizedPrice?: string; + userId?: string; + marketplace?: string; +} export declare enum NamiPaywallAction { BUY_SKU = "BUY_SKU", SELECT_SKU = "SELECT_SKU", diff --git a/src/types.ts b/src/types.ts index 9f04973f..fa285d7e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -268,6 +268,20 @@ export type NamiPurchaseSuccessAmazon = { marketplace: string; }; +export type NamiPurchaseSuccess = { + product: NamiSKU; + transactionID?: string; + originalTransactionID?: string; + price?: string; + currencyCode?: string; + orderId?: string; + purchaseToken?: string; + receiptId?: string; + localizedPrice?: string; + userId?: string; + marketplace?: string; +} + export enum NamiPaywallAction { BUY_SKU = 'BUY_SKU', SELECT_SKU = 'SELECT_SKU',