Skip to content

Commit

Permalink
Add common NamiPurchaseSuccess Type
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-sumi-k committed Nov 18, 2024
1 parent b876f7c commit 10452b0
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 12 deletions.
14 changes: 7 additions & 7 deletions examples/Basic/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const Tab = createBottomTabNavigator<ViewerTabNavigatorParams>();
const App = () => {
const [subscriptions, setSubscriptions] = useState<Subscription[]>([]);
const [products, setProducts] = useState<Product[]>([]);
const [namiSku, setNamiSku] = useState<NamiSKU>(undefined);
const [namiSku, setNamiSku] = useState<NamiSKU>({} as NamiSKU);

useEffect(() => {
Linking.addEventListener('url', handleDeepLink);
Expand Down Expand Up @@ -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 ?? '',
Expand All @@ -118,17 +118,17 @@ 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,
userId: purchase.userIdAmazon ?? '',
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 ?? '',
Expand Down
6 changes: 3 additions & 3 deletions examples/TestNamiTV/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const App = () => {
NamiPaywallManager.dismiss();

if (Platform.OS === 'ios') {
NamiPaywallManager.buySkuCompleteApple({
NamiPaywallManager.buySkuComplete({
product: sku,
transactionID: '12345',
originalTransactionID: '12345',
Expand All @@ -70,15 +70,15 @@ const App = () => {
});
} else if (Platform.OS === 'android') {
if (Platform.constants.Manufacturer === 'Amazon') {
NamiPaywallManager.buySkuCompleteAmazon({
NamiPaywallManager.buySkuComplete({
product: sku,
receiptId: '12345',
localizedPrice: '120',
userId: '12345',
marketplace: 'US',
});
} else {
NamiPaywallManager.buySkuCompleteGooglePlay({
NamiPaywallManager.buySkuComplete({
product: sku,
purchaseToken:
'jolbnkpmojnpnjecgmphbmkc.AO-J1OznE4AIzyUvKFe1RSVkxw4KEtv0WfyL_tkzozOqnlSvIPsyQJBphCN80gwIMaex4EMII95rFCZhMCbVPZDc-y_VVhQU5Ddua1dLn8zV7ms_tdwoDmE',
Expand Down
2 changes: 1 addition & 1 deletion src/NamiEntitlementManager.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export declare enum NamiEntitlementManagerEvents {
export interface INamiEntitlementManager {
emitter: NativeEventEmitter;
active: () => Promise<Array<NamiEntitlement>>;
isEntitlementActive: (label?: string) => boolean;
isEntitlementActive: (label: string) => boolean;
refresh: (resultCallback?: (entitlements?: NamiEntitlement[]) => void) => void;
registerActiveEntitlementsHandler: (callback: (activeEntitlements: NamiEntitlement[]) => void) => EmitterSubscription['remove'];
clearProvisionalEntitlementGrants: () => void;
Expand Down
2 changes: 1 addition & 1 deletion src/NamiEntitlementManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export enum NamiEntitlementManagerEvents {
export interface INamiEntitlementManager {
emitter: NativeEventEmitter;
active: () => Promise<Array<NamiEntitlement>>;
isEntitlementActive: (label?: string) => boolean;
isEntitlementActive: (label: string) => boolean;
refresh: (
resultCallback?: (entitlements?: NamiEntitlement[]) => void,
) => void;
Expand Down
2 changes: 2 additions & 0 deletions src/NamiPaywallManager.d.ts
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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'];
Expand Down
5 changes: 5 additions & 0 deletions src/NamiPaywallManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
EmitterSubscription,
} from 'react-native';
import {
NamiPurchaseSuccess,
NamiPurchaseSuccessAmazon,
NamiPurchaseSuccessApple,
NamiPurchaseSuccessGooglePlay,
Expand All @@ -30,6 +31,7 @@ export interface INamiPaywallManager {
buySkuCompleteGooglePlay: (
purchaseSuccess: NamiPurchaseSuccessGooglePlay,
) => void;
buySkuComplete: (purchaseSuccess: NamiPurchaseSuccess) => void;
buySkuCancel: () => void;
registerBuySkuHandler: (
callback: (sku: NamiSKU) => void,
Expand Down Expand Up @@ -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);
},
Expand Down
13 changes: 13 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 14 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Check failure on line 283 in src/types.ts

View workflow job for this annotation

GitHub Actions / ESLint

Insert `;`

export enum NamiPaywallAction {
BUY_SKU = 'BUY_SKU',
SELECT_SKU = 'SELECT_SKU',
Expand Down

0 comments on commit 10452b0

Please sign in to comment.