react-native-iap 12.1.1 → 12.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/amazon/java/com/dooboolab/RNIap/RNIapAmazonListener.kt +29 -29
- package/android/src/amazon/java/com/dooboolab/RNIap/RNIapAmazonModule.kt +6 -6
- package/android/src/main/java/com/dooboolab/RNIap/PromiseUtils.kt +56 -0
- package/android/src/main/java/com/dooboolab/RNIap/PromiseUtlis.kt +1 -1
- package/android/src/play/java/com/dooboolab/RNIap/PlayUtils.kt +31 -35
- package/android/src/play/java/com/dooboolab/RNIap/RNIapModule.kt +21 -27
- package/ios/IapSerializationUtils.swift +11 -0
- package/ios/RNIapIosSk2.m +4 -0
- package/ios/RNIapIosSk2.swift +51 -0
- package/lib/commonjs/iap.js +1 -1
- package/lib/commonjs/iap.js.map +1 -1
- package/lib/commonjs/modules/android.js.map +1 -1
- package/lib/commonjs/modules/iosSk2.js +9 -1
- package/lib/commonjs/modules/iosSk2.js.map +1 -1
- package/lib/commonjs/types/appleSk2.js.map +1 -1
- package/lib/module/iap.js +1 -1
- package/lib/module/iap.js.map +1 -1
- package/lib/module/modules/android.js.map +1 -1
- package/lib/module/modules/iosSk2.js +5 -0
- package/lib/module/modules/iosSk2.js.map +1 -1
- package/lib/module/types/appleSk2.js.map +1 -1
- package/lib/typescript/modules/android.d.ts +1 -1
- package/lib/typescript/modules/iosSk2.d.ts +6 -1
- package/lib/typescript/types/appleSk2.d.ts +1 -0
- package/package.json +1 -1
- package/src/iap.ts +1 -1
- package/src/modules/android.ts +1 -1
- package/src/modules/iosSk2.ts +8 -0
- package/src/types/appleSk2.ts +2 -0
- package/android/src/main/java/com/dooboolab/RNIap/DoobooUtils.kt +0 -188
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Linking","NativeModules","checkNativeAndroidAvailable","getAndroidModule","InstallSourceAndroid","RNIapModule","AndroidModule","getInstallSourceAndroid","GOOGLE_PLAY","AMAZON","deepLinkToSubscriptionsAndroid","sku","openURL","getPackageName","validateReceiptAndroid","packageName","productId","productToken","accessToken","isSub","type","url","response","fetch","method","headers","ok","Object","assign","Error","statusText","statusCode","status","json","acknowledgePurchaseAndroid","token","developerPayload","acknowledgePurchase"],"sources":["android.ts"],"sourcesContent":["import {Linking, NativeModules} from 'react-native';\n\nimport {checkNativeAndroidAvailable, getAndroidModule} from '../internal';\nimport {\n InstallSourceAndroid,\n Product,\n ProductType,\n ProrationModesAndroid,\n Purchase,\n PurchaseResult,\n Sku,\n} from '../types';\nimport type * as Android from '../types/android';\n\nimport type {NativeModuleProps} from './common';\n\nconst {RNIapModule} = NativeModules;\n\ntype FlushFailedPurchasesCachedAsPending = () => Promise<boolean>;\n\ntype GetItemsByType = <T = Product>(\n type: ProductType,\n skus: Sku[],\n) => Promise<T[]>;\n\ntype GetAvailableItemsByType = <T = Purchase>(\n type: ProductType,\n) => Promise<T[]>;\n\ntype GetPurchaseHistoryByType = <T = Purchase>(\n type: ProductType,\n) => Promise<T[]>;\n\nexport type BuyItemByType = (\n type: string,\n skus: Sku[],\n purchaseToken: string | undefined,\n prorationMode: ProrationModesAndroid |
|
|
1
|
+
{"version":3,"names":["Linking","NativeModules","checkNativeAndroidAvailable","getAndroidModule","InstallSourceAndroid","RNIapModule","AndroidModule","getInstallSourceAndroid","GOOGLE_PLAY","AMAZON","deepLinkToSubscriptionsAndroid","sku","openURL","getPackageName","validateReceiptAndroid","packageName","productId","productToken","accessToken","isSub","type","url","response","fetch","method","headers","ok","Object","assign","Error","statusText","statusCode","status","json","acknowledgePurchaseAndroid","token","developerPayload","acknowledgePurchase"],"sources":["android.ts"],"sourcesContent":["import {Linking, NativeModules} from 'react-native';\n\nimport {checkNativeAndroidAvailable, getAndroidModule} from '../internal';\nimport {\n InstallSourceAndroid,\n Product,\n ProductType,\n ProrationModesAndroid,\n Purchase,\n PurchaseResult,\n Sku,\n} from '../types';\nimport type * as Android from '../types/android';\n\nimport type {NativeModuleProps} from './common';\n\nconst {RNIapModule} = NativeModules;\n\ntype FlushFailedPurchasesCachedAsPending = () => Promise<boolean>;\n\ntype GetItemsByType = <T = Product>(\n type: ProductType,\n skus: Sku[],\n) => Promise<T[]>;\n\ntype GetAvailableItemsByType = <T = Purchase>(\n type: ProductType,\n) => Promise<T[]>;\n\ntype GetPurchaseHistoryByType = <T = Purchase>(\n type: ProductType,\n) => Promise<T[]>;\n\nexport type BuyItemByType = (\n type: string,\n skus: Sku[],\n purchaseToken: string | undefined,\n prorationMode: ProrationModesAndroid | -1,\n obfuscatedAccountId: string | undefined,\n obfuscatedProfileId: string | undefined,\n subscriptionOffers: string[],\n isOfferPersonalized: boolean,\n) => Promise<Purchase>;\n\ntype AcknowledgePurchase = (\n purchaseToken: string,\n developerPayloadAndroid?: string,\n) => Promise<PurchaseResult | boolean>;\n\ntype ConsumeProduct = (\n purchaseToken: string,\n developerPayloadAndroid?: string,\n) => Promise<PurchaseResult | boolean>;\n\ntype StartListening = () => Promise<void>;\ntype GetPackageName = () => Promise<string>;\n\nexport interface AndroidModuleProps extends NativeModuleProps {\n flushFailedPurchasesCachedAsPending: FlushFailedPurchasesCachedAsPending;\n getItemsByType: GetItemsByType;\n getAvailableItemsByType: GetAvailableItemsByType;\n getPurchaseHistoryByType: GetPurchaseHistoryByType;\n buyItemByType: BuyItemByType;\n acknowledgePurchase: AcknowledgePurchase;\n consumeProduct: ConsumeProduct;\n startListening: StartListening;\n getPackageName: GetPackageName;\n}\n\nexport const AndroidModule = NativeModules.RNIapModule as AndroidModuleProps;\n\nexport const getInstallSourceAndroid = (): InstallSourceAndroid => {\n return RNIapModule\n ? InstallSourceAndroid.GOOGLE_PLAY\n : InstallSourceAndroid.AMAZON;\n};\n\n/**\n * Deep link to subscriptions screen on Android. No-op on iOS.\n * @param {string} sku The product's SKU (on Android)\n * @returns {Promise<void>}\n */\nexport const deepLinkToSubscriptionsAndroid = async ({\n sku,\n}: {\n sku: Sku;\n}): Promise<void> => {\n checkNativeAndroidAvailable();\n\n return Linking.openURL(\n `https://play.google.com/store/account/subscriptions?package=${await RNIapModule.getPackageName()}&sku=${sku}`,\n );\n};\n\n/**\n * Validate receipt for Android. NOTE: This method is here for debugging purposes only. Including\n * your access token in the binary you ship to users is potentially dangerous.\n * Use server side validation instead for your production builds\n * @param {string} packageName package name of your app.\n * @param {string} productId product id for your in app product.\n * @param {string} productToken token for your purchase.\n * @param {string} accessToken accessToken from googleApis.\n * @param {boolean} isSub whether this is subscription or inapp. `true` for subscription.\n * @returns {Promise<object>}\n */\nexport const validateReceiptAndroid = async ({\n packageName,\n productId,\n productToken,\n accessToken,\n isSub,\n}: {\n packageName: string;\n productId: string;\n productToken: string;\n accessToken: string;\n isSub?: boolean;\n}): Promise<Android.ReceiptType> => {\n const type = isSub ? 'subscriptions' : 'products';\n\n const url =\n 'https://androidpublisher.googleapis.com/androidpublisher/v3/applications' +\n `/${packageName}/purchases/${type}/${productId}` +\n `/tokens/${productToken}?access_token=${accessToken}`;\n\n const response = await fetch(url, {\n method: 'GET',\n headers: {\n 'Content-Type': 'application/json',\n },\n });\n\n if (!response.ok) {\n throw Object.assign(new Error(response.statusText), {\n statusCode: response.status,\n });\n }\n\n return response.json();\n};\n\n/**\n * Acknowledge a product (on Android.) No-op on iOS.\n * @param {string} token The product's token (on Android)\n * @returns {Promise<PurchaseResult | void>}\n */\nexport const acknowledgePurchaseAndroid = ({\n token,\n developerPayload,\n}: {\n token: string;\n developerPayload?: string;\n}): Promise<PurchaseResult | boolean | void> => {\n return getAndroidModule().acknowledgePurchase(token, developerPayload);\n};\n"],"mappings":"AAAA,SAAQA,OAAR,EAAiBC,aAAjB,QAAqC,cAArC;AAEA,SAAQC,2BAAR,EAAqCC,gBAArC,QAA4D,aAA5D;AACA,SACEC,oBADF,QAQO,UARP;AAaA,MAAM;EAACC;AAAD,IAAgBJ,aAAtB;AAqDA,OAAO,MAAMK,aAAa,GAAGL,aAAa,CAACI,WAApC;AAEP,OAAO,MAAME,uBAAuB,GAAG,MAA4B;EACjE,OAAOF,WAAW,GACdD,oBAAoB,CAACI,WADP,GAEdJ,oBAAoB,CAACK,MAFzB;AAGD,CAJM;AAMP;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,8BAA8B,GAAG,cAIzB;EAAA,IAJgC;IACnDC;EADmD,CAIhC;EACnBT,2BAA2B;EAE3B,OAAOF,OAAO,CAACY,OAAR,CACJ,+DAA8D,MAAMP,WAAW,CAACQ,cAAZ,EAA6B,QAAOF,GAAI,EADxG,CAAP;AAGD,CAVM;AAYP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMG,sBAAsB,GAAG,eAYF;EAAA,IAZS;IAC3CC,WAD2C;IAE3CC,SAF2C;IAG3CC,YAH2C;IAI3CC,WAJ2C;IAK3CC;EAL2C,CAYT;EAClC,MAAMC,IAAI,GAAGD,KAAK,GAAG,eAAH,GAAqB,UAAvC;EAEA,MAAME,GAAG,GACP,6EACC,IAAGN,WAAY,cAAaK,IAAK,IAAGJ,SAAU,EAD/C,GAEC,WAAUC,YAAa,iBAAgBC,WAAY,EAHtD;EAKA,MAAMI,QAAQ,GAAG,MAAMC,KAAK,CAACF,GAAD,EAAM;IAChCG,MAAM,EAAE,KADwB;IAEhCC,OAAO,EAAE;MACP,gBAAgB;IADT;EAFuB,CAAN,CAA5B;;EAOA,IAAI,CAACH,QAAQ,CAACI,EAAd,EAAkB;IAChB,MAAMC,MAAM,CAACC,MAAP,CAAc,IAAIC,KAAJ,CAAUP,QAAQ,CAACQ,UAAnB,CAAd,EAA8C;MAClDC,UAAU,EAAET,QAAQ,CAACU;IAD6B,CAA9C,CAAN;EAGD;;EAED,OAAOV,QAAQ,CAACW,IAAT,EAAP;AACD,CAlCM;AAoCP;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,0BAA0B,GAAG,SAMM;EAAA,IANL;IACzCC,KADyC;IAEzCC;EAFyC,CAMK;EAC9C,OAAOjC,gBAAgB,GAAGkC,mBAAnB,CAAuCF,KAAvC,EAA8CC,gBAA9C,CAAP;AACD,CARM"}
|
|
@@ -28,4 +28,9 @@ export const currentEntitlement = sku => RNIapIosSk2.currentEntitlement(sku);
|
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
30
|
export const latestTransaction = sku => RNIapIosSk2.latestTransaction(sku);
|
|
31
|
+
/**
|
|
32
|
+
*
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
export const beginRefundRequest = sku => RNIapIosSk2.beginRefundRequest(sku);
|
|
31
36
|
//# sourceMappingURL=iosSk2.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeModules","RNIapIosSk2","sync","isEligibleForIntroOffer","groupID","subscriptionStatus","sku","currentEntitlement","latestTransaction"],"sources":["iosSk2.ts"],"sourcesContent":["import {NativeModules} from 'react-native';\n\nimport type {Product, ProductPurchase, Purchase, Sku} from '../types';\nimport type {\n PaymentDiscountSk2,\n ProductSk2,\n ProductStatus,\n TransactionSk2,\n} from '../types/appleSk2';\n\nimport type {NativeModuleProps} from './common';\nconst {RNIapIosSk2} = NativeModules;\n\ntype getItems = (skus: Sku[]) => Promise<ProductSk2[]>;\n\ntype getAvailableItems = (\n alsoPublishToEventListener?: boolean,\n) => Promise<TransactionSk2[]>;\n\nexport type BuyProduct = (\n sku: Sku,\n andDangerouslyFinishTransactionAutomaticallyIOS: boolean,\n applicationUsername: string | undefined,\n quantity: number,\n withOffer: Record<keyof PaymentDiscountSk2, string> | undefined,\n) => Promise<Purchase>;\n\ntype clearTransaction = () => Promise<void>;\ntype clearProducts = () => Promise<void>;\ntype promotedProduct = () => Promise<Product | null>;\ntype buyPromotedProduct = () => Promise<void>;\n\ntype finishTransaction = (transactionIdentifier: string) => Promise<boolean>;\n\ntype getPendingTransactions = () => Promise<ProductPurchase[]>;\ntype presentCodeRedemptionSheet = () => Promise<null>;\n\nexport interface IosModulePropsSk2 extends NativeModuleProps {\n isAvailable(): number;\n latestTransaction(sku: string): Promise<TransactionSk2>;\n currentEntitlement(sku: string): Promise<TransactionSk2>;\n subscriptionStatus(sku: string): Promise<ProductStatus[]>;\n isEligibleForIntroOffer(groupID: string): Promise<Boolean>;\n sync(): Promise<null>;\n getItems: getItems;\n getAvailableItems: getAvailableItems;\n buyProduct: BuyProduct;\n clearTransaction: clearTransaction;\n clearProducts: clearProducts;\n promotedProduct: promotedProduct;\n buyPromotedProduct: buyPromotedProduct;\n finishTransaction: finishTransaction;\n getPendingTransactions: getPendingTransactions;\n presentCodeRedemptionSheet: presentCodeRedemptionSheet;\n disable: () => Promise<null>;\n}\n\n/**\n * Sync state with Appstore (iOS only)\n * https://developer.apple.com/documentation/storekit/appstore/3791906-sync\n */\nexport const sync = (): Promise<null> => RNIapIosSk2.sync();\n\n/**\n *\n */\nexport const isEligibleForIntroOffer = (groupID: string): Promise<Boolean> =>\n RNIapIosSk2.isEligibleForIntroOffer(groupID);\n\n/**\n *\n */\n\nexport const subscriptionStatus = (sku: string): Promise<ProductStatus[]> =>\n RNIapIosSk2.subscriptionStatus(sku);\n\n/**\n *\n */\nexport const currentEntitlement = (sku: string): Promise<TransactionSk2> =>\n RNIapIosSk2.currentEntitlement(sku);\n\n/**\n *\n */\nexport const latestTransaction = (sku: string): Promise<TransactionSk2> =>\n RNIapIosSk2.latestTransaction(sku);\n"],"mappings":"AAAA,SAAQA,aAAR,QAA4B,cAA5B;
|
|
1
|
+
{"version":3,"names":["NativeModules","RNIapIosSk2","sync","isEligibleForIntroOffer","groupID","subscriptionStatus","sku","currentEntitlement","latestTransaction","beginRefundRequest"],"sources":["iosSk2.ts"],"sourcesContent":["import {NativeModules} from 'react-native';\n\nimport type {Product, ProductPurchase, Purchase, Sku} from '../types';\nimport type {\n PaymentDiscountSk2,\n ProductSk2,\n ProductStatus,\n RefundRequestStatus,\n TransactionSk2,\n} from '../types/appleSk2';\n\nimport type {NativeModuleProps} from './common';\nconst {RNIapIosSk2} = NativeModules;\n\ntype getItems = (skus: Sku[]) => Promise<ProductSk2[]>;\n\ntype getAvailableItems = (\n alsoPublishToEventListener?: boolean,\n) => Promise<TransactionSk2[]>;\n\nexport type BuyProduct = (\n sku: Sku,\n andDangerouslyFinishTransactionAutomaticallyIOS: boolean,\n applicationUsername: string | undefined,\n quantity: number,\n withOffer: Record<keyof PaymentDiscountSk2, string> | undefined,\n) => Promise<Purchase>;\n\ntype clearTransaction = () => Promise<void>;\ntype clearProducts = () => Promise<void>;\ntype promotedProduct = () => Promise<Product | null>;\ntype buyPromotedProduct = () => Promise<void>;\n\ntype finishTransaction = (transactionIdentifier: string) => Promise<boolean>;\n\ntype getPendingTransactions = () => Promise<ProductPurchase[]>;\ntype presentCodeRedemptionSheet = () => Promise<null>;\n\nexport interface IosModulePropsSk2 extends NativeModuleProps {\n isAvailable(): number;\n latestTransaction(sku: string): Promise<TransactionSk2>;\n currentEntitlement(sku: string): Promise<TransactionSk2>;\n subscriptionStatus(sku: string): Promise<ProductStatus[]>;\n isEligibleForIntroOffer(groupID: string): Promise<Boolean>;\n sync(): Promise<null>;\n getItems: getItems;\n getAvailableItems: getAvailableItems;\n buyProduct: BuyProduct;\n clearTransaction: clearTransaction;\n clearProducts: clearProducts;\n promotedProduct: promotedProduct;\n buyPromotedProduct: buyPromotedProduct;\n finishTransaction: finishTransaction;\n getPendingTransactions: getPendingTransactions;\n presentCodeRedemptionSheet: presentCodeRedemptionSheet;\n disable: () => Promise<null>;\n beginRefundRequest: (sku: string) => Promise<RefundRequestStatus>;\n}\n\n/**\n * Sync state with Appstore (iOS only)\n * https://developer.apple.com/documentation/storekit/appstore/3791906-sync\n */\nexport const sync = (): Promise<null> => RNIapIosSk2.sync();\n\n/**\n *\n */\nexport const isEligibleForIntroOffer = (groupID: string): Promise<Boolean> =>\n RNIapIosSk2.isEligibleForIntroOffer(groupID);\n\n/**\n *\n */\n\nexport const subscriptionStatus = (sku: string): Promise<ProductStatus[]> =>\n RNIapIosSk2.subscriptionStatus(sku);\n\n/**\n *\n */\nexport const currentEntitlement = (sku: string): Promise<TransactionSk2> =>\n RNIapIosSk2.currentEntitlement(sku);\n\n/**\n *\n */\nexport const latestTransaction = (sku: string): Promise<TransactionSk2> =>\n RNIapIosSk2.latestTransaction(sku);\n\n/**\n *\n */\nexport const beginRefundRequest = (sku: string): Promise<RefundRequestStatus> =>\n RNIapIosSk2.beginRefundRequest(sku);\n"],"mappings":"AAAA,SAAQA,aAAR,QAA4B,cAA5B;AAYA,MAAM;EAACC;AAAD,IAAgBD,aAAtB;;AA+CA;AACA;AACA;AACA;AACA,OAAO,MAAME,IAAI,GAAG,MAAqBD,WAAW,CAACC,IAAZ,EAAlC;AAEP;AACA;AACA;;AACA,OAAO,MAAMC,uBAAuB,GAAIC,OAAD,IACrCH,WAAW,CAACE,uBAAZ,CAAoCC,OAApC,CADK;AAGP;AACA;AACA;;AAEA,OAAO,MAAMC,kBAAkB,GAAIC,GAAD,IAChCL,WAAW,CAACI,kBAAZ,CAA+BC,GAA/B,CADK;AAGP;AACA;AACA;;AACA,OAAO,MAAMC,kBAAkB,GAAID,GAAD,IAChCL,WAAW,CAACM,kBAAZ,CAA+BD,GAA/B,CADK;AAGP;AACA;AACA;;AACA,OAAO,MAAME,iBAAiB,GAAIF,GAAD,IAC/BL,WAAW,CAACO,iBAAZ,CAA8BF,GAA9B,CADK;AAGP;AACA;AACA;;AACA,OAAO,MAAMG,kBAAkB,GAAIH,GAAD,IAChCL,WAAW,CAACQ,kBAAZ,CAA+BH,GAA/B,CADK"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["SubscriptionPlatform","productSk2Map","id","description","displayName","price","displayPrice","prod","title","productId","String","type","localizedPrice","currency","subscriptionSk2Map","subscription","platform","ios","subscriptionPeriodNumberIOS","subscriptionPeriod","value","subscriptionPeriodUnitIOS","unit","toUpperCase","transactionSk2Map","originalPurchaseDate","productID","purchaseDate","purchasedQuantity","purchase","transactionId","transactionDate","transactionReceipt","purchaseToken","quantityIOS","originalTransactionDateIOS","originalTransactionIdentifierIOS","offerSk2Map","offer","undefined","offerID","identifier","keyID","keyIdentifier","nonce","signature","timestamp","toString"],"sources":["appleSk2.ts"],"sourcesContent":["import type {PurchaseError} from '../purchaseError';\n\nimport type {\n ProductIOS,\n Purchase,\n SubscriptionIOS,\n SubscriptionIosPeriod,\n} from '.';\nimport type * as Apple from './apple';\nimport {SubscriptionPlatform} from '.';\n\nexport type SubscriptionPeriod = {\n unit: 'day' | 'week' | 'month' | 'year';\n value: number;\n};\n\nexport type PaymentMode = 'freeTrial' | 'payAsYouGo' | 'payUpFront';\n\nexport type SubscriptionOffer = {\n displayPrice: string;\n id: string;\n paymentMode: PaymentMode;\n period: SubscriptionPeriod;\n periodCount: number;\n price: number;\n type: 'introductory' | 'promotional';\n};\n\nexport type SubscriptionInfo = {\n introductoryOffer?: SubscriptionOffer;\n promotionalOffers?: SubscriptionOffer[];\n subscriptionGroupID: string;\n subscriptionPeriod: SubscriptionPeriod;\n};\n\nexport type ProductSk2 = {\n description: string;\n displayName: string;\n displayPrice: string;\n id: number;\n isFamilyShareable: boolean;\n jsonRepresentation: string;\n price: number;\n subscription: SubscriptionInfo;\n type: 'autoRenewable' | 'consumable' | 'nonConsumable' | 'nonRenewable';\n};\nexport const productSk2Map = ({\n id,\n description,\n displayName,\n price,\n displayPrice,\n}: ProductSk2): ProductIOS => {\n const prod: ProductIOS = {\n title: displayName,\n productId: String(id),\n description,\n type: 'iap',\n price: String(price),\n localizedPrice: displayPrice,\n currency: '', // Not avaiable on new API, use localizedPrice instead\n };\n return prod;\n};\n\nexport const subscriptionSk2Map = ({\n id,\n description,\n displayName,\n price,\n displayPrice,\n subscription,\n}: ProductSk2): SubscriptionIOS => {\n const prod: SubscriptionIOS = {\n platform: SubscriptionPlatform.ios,\n title: displayName,\n productId: String(id),\n description,\n type: 'subs',\n price: String(price),\n localizedPrice: displayPrice,\n currency: '', // Not avaiable on new API, use localizedPrice instead\n subscriptionPeriodNumberIOS: `${subscription?.subscriptionPeriod?.value}`,\n subscriptionPeriodUnitIOS:\n subscription?.subscriptionPeriod?.unit.toUpperCase() as SubscriptionIosPeriod,\n };\n return prod;\n};\n\nexport type TransactionSk2 = {\n appAccountToken: string;\n appBundleID: string;\n debugDescription: string;\n deviceVerification: string;\n deviceVerificationNonce: string;\n expirationDate: number;\n id: number;\n isUpgraded: boolean;\n jsonRepresentation: string;\n offerID: string;\n offerType: string;\n originalID: string;\n originalPurchaseDate: number;\n ownershipType: string;\n productID: string;\n productType: string;\n purchaseDate: number;\n purchasedQuantity: number;\n revocationDate: number;\n revocationReason: string;\n signedDate: number;\n subscriptionGroupID: number;\n webOrderLineItemID: number;\n};\n\nexport type TransactionError = PurchaseError;\n\n/**\n * Only one of `transaction` and `error` is not undefined at the time\n */\nexport type TransactionEvent = {\n transaction?: TransactionSk2;\n error?: TransactionError;\n};\n\nexport type SubscriptionStatus =\n | 'expired'\n | 'inBillingRetryPeriod'\n | 'inGracePeriod'\n | 'revoked'\n | 'subscribed';\n\nexport type ProductStatus = {\n state: SubscriptionStatus;\n};\n\nexport const transactionSk2Map = ({\n id,\n originalPurchaseDate,\n productID,\n purchaseDate,\n purchasedQuantity,\n}: TransactionSk2): Purchase => {\n const purchase: Purchase = {\n productId: productID,\n transactionId: String(id),\n transactionDate: purchaseDate, //??\n transactionReceipt: '', // Not available\n purchaseToken: '', //Not avaiable\n quantityIOS: purchasedQuantity,\n originalTransactionDateIOS: String(originalPurchaseDate),\n originalTransactionIdentifierIOS: String(id), // ??\n };\n return purchase;\n};\n\n/**\n * Payment discount interface @see https://developer.apple.com/documentation/storekit/skpaymentdiscount?language=objc\n */\nexport interface PaymentDiscountSk2 {\n /**\n * A string used to uniquely identify a discount offer for a product.\n */\n offerID: string;\n\n /**\n * A string that identifies the key used to generate the signature.\n */\n keyID: string;\n\n /**\n * A universally unique ID (UUID) value that you define.\n */\n nonce: string;\n\n /**\n * A UTF-8 string representing the properties of a specific discount offer, cryptographically signed.\n */\n signature: string;\n\n /**\n * The date and time of the signature's creation in milliseconds, formatted in Unix epoch time.\n */\n timestamp: number;\n}\n\nexport const offerSk2Map = (\n offer: Apple.PaymentDiscount | undefined,\n): Record<keyof PaymentDiscountSk2, string> | undefined => {\n if (!offer) {\n return undefined;\n }\n return {\n offerID: offer.identifier,\n keyID: offer.keyIdentifier,\n nonce: offer.nonce,\n signature: offer.signature,\n timestamp: offer.timestamp.toString(),\n };\n};\n"],"mappings":"AASA,SAAQA,oBAAR,QAAmC,GAAnC;
|
|
1
|
+
{"version":3,"names":["SubscriptionPlatform","productSk2Map","id","description","displayName","price","displayPrice","prod","title","productId","String","type","localizedPrice","currency","subscriptionSk2Map","subscription","platform","ios","subscriptionPeriodNumberIOS","subscriptionPeriod","value","subscriptionPeriodUnitIOS","unit","toUpperCase","transactionSk2Map","originalPurchaseDate","productID","purchaseDate","purchasedQuantity","purchase","transactionId","transactionDate","transactionReceipt","purchaseToken","quantityIOS","originalTransactionDateIOS","originalTransactionIdentifierIOS","offerSk2Map","offer","undefined","offerID","identifier","keyID","keyIdentifier","nonce","signature","timestamp","toString"],"sources":["appleSk2.ts"],"sourcesContent":["import type {PurchaseError} from '../purchaseError';\n\nimport type {\n ProductIOS,\n Purchase,\n SubscriptionIOS,\n SubscriptionIosPeriod,\n} from '.';\nimport type * as Apple from './apple';\nimport {SubscriptionPlatform} from '.';\n\nexport type SubscriptionPeriod = {\n unit: 'day' | 'week' | 'month' | 'year';\n value: number;\n};\n\nexport type PaymentMode = 'freeTrial' | 'payAsYouGo' | 'payUpFront';\n\nexport type SubscriptionOffer = {\n displayPrice: string;\n id: string;\n paymentMode: PaymentMode;\n period: SubscriptionPeriod;\n periodCount: number;\n price: number;\n type: 'introductory' | 'promotional';\n};\n\nexport type SubscriptionInfo = {\n introductoryOffer?: SubscriptionOffer;\n promotionalOffers?: SubscriptionOffer[];\n subscriptionGroupID: string;\n subscriptionPeriod: SubscriptionPeriod;\n};\n\nexport type RefundRequestStatus = 'success' | 'userCancelled';\n\nexport type ProductSk2 = {\n description: string;\n displayName: string;\n displayPrice: string;\n id: number;\n isFamilyShareable: boolean;\n jsonRepresentation: string;\n price: number;\n subscription: SubscriptionInfo;\n type: 'autoRenewable' | 'consumable' | 'nonConsumable' | 'nonRenewable';\n};\nexport const productSk2Map = ({\n id,\n description,\n displayName,\n price,\n displayPrice,\n}: ProductSk2): ProductIOS => {\n const prod: ProductIOS = {\n title: displayName,\n productId: String(id),\n description,\n type: 'iap',\n price: String(price),\n localizedPrice: displayPrice,\n currency: '', // Not avaiable on new API, use localizedPrice instead\n };\n return prod;\n};\n\nexport const subscriptionSk2Map = ({\n id,\n description,\n displayName,\n price,\n displayPrice,\n subscription,\n}: ProductSk2): SubscriptionIOS => {\n const prod: SubscriptionIOS = {\n platform: SubscriptionPlatform.ios,\n title: displayName,\n productId: String(id),\n description,\n type: 'subs',\n price: String(price),\n localizedPrice: displayPrice,\n currency: '', // Not avaiable on new API, use localizedPrice instead\n subscriptionPeriodNumberIOS: `${subscription?.subscriptionPeriod?.value}`,\n subscriptionPeriodUnitIOS:\n subscription?.subscriptionPeriod?.unit.toUpperCase() as SubscriptionIosPeriod,\n };\n return prod;\n};\n\nexport type TransactionSk2 = {\n appAccountToken: string;\n appBundleID: string;\n debugDescription: string;\n deviceVerification: string;\n deviceVerificationNonce: string;\n expirationDate: number;\n id: number;\n isUpgraded: boolean;\n jsonRepresentation: string;\n offerID: string;\n offerType: string;\n originalID: string;\n originalPurchaseDate: number;\n ownershipType: string;\n productID: string;\n productType: string;\n purchaseDate: number;\n purchasedQuantity: number;\n revocationDate: number;\n revocationReason: string;\n signedDate: number;\n subscriptionGroupID: number;\n webOrderLineItemID: number;\n};\n\nexport type TransactionError = PurchaseError;\n\n/**\n * Only one of `transaction` and `error` is not undefined at the time\n */\nexport type TransactionEvent = {\n transaction?: TransactionSk2;\n error?: TransactionError;\n};\n\nexport type SubscriptionStatus =\n | 'expired'\n | 'inBillingRetryPeriod'\n | 'inGracePeriod'\n | 'revoked'\n | 'subscribed';\n\nexport type ProductStatus = {\n state: SubscriptionStatus;\n};\n\nexport const transactionSk2Map = ({\n id,\n originalPurchaseDate,\n productID,\n purchaseDate,\n purchasedQuantity,\n}: TransactionSk2): Purchase => {\n const purchase: Purchase = {\n productId: productID,\n transactionId: String(id),\n transactionDate: purchaseDate, //??\n transactionReceipt: '', // Not available\n purchaseToken: '', //Not avaiable\n quantityIOS: purchasedQuantity,\n originalTransactionDateIOS: String(originalPurchaseDate),\n originalTransactionIdentifierIOS: String(id), // ??\n };\n return purchase;\n};\n\n/**\n * Payment discount interface @see https://developer.apple.com/documentation/storekit/skpaymentdiscount?language=objc\n */\nexport interface PaymentDiscountSk2 {\n /**\n * A string used to uniquely identify a discount offer for a product.\n */\n offerID: string;\n\n /**\n * A string that identifies the key used to generate the signature.\n */\n keyID: string;\n\n /**\n * A universally unique ID (UUID) value that you define.\n */\n nonce: string;\n\n /**\n * A UTF-8 string representing the properties of a specific discount offer, cryptographically signed.\n */\n signature: string;\n\n /**\n * The date and time of the signature's creation in milliseconds, formatted in Unix epoch time.\n */\n timestamp: number;\n}\n\nexport const offerSk2Map = (\n offer: Apple.PaymentDiscount | undefined,\n): Record<keyof PaymentDiscountSk2, string> | undefined => {\n if (!offer) {\n return undefined;\n }\n return {\n offerID: offer.identifier,\n keyID: offer.keyIdentifier,\n nonce: offer.nonce,\n signature: offer.signature,\n timestamp: offer.timestamp.toString(),\n };\n};\n"],"mappings":"AASA,SAAQA,oBAAR,QAAmC,GAAnC;AAuCA,OAAO,MAAMC,aAAa,GAAG,QAMC;EAAA,IANA;IAC5BC,EAD4B;IAE5BC,WAF4B;IAG5BC,WAH4B;IAI5BC,KAJ4B;IAK5BC;EAL4B,CAMA;EAC5B,MAAMC,IAAgB,GAAG;IACvBC,KAAK,EAAEJ,WADgB;IAEvBK,SAAS,EAAEC,MAAM,CAACR,EAAD,CAFM;IAGvBC,WAHuB;IAIvBQ,IAAI,EAAE,KAJiB;IAKvBN,KAAK,EAAEK,MAAM,CAACL,KAAD,CALU;IAMvBO,cAAc,EAAEN,YANO;IAOvBO,QAAQ,EAAE,EAPa,CAOT;;EAPS,CAAzB;EASA,OAAON,IAAP;AACD,CAjBM;AAmBP,OAAO,MAAMO,kBAAkB,GAAG,SAOC;EAAA;;EAAA,IAPA;IACjCZ,EADiC;IAEjCC,WAFiC;IAGjCC,WAHiC;IAIjCC,KAJiC;IAKjCC,YALiC;IAMjCS;EANiC,CAOA;EACjC,MAAMR,IAAqB,GAAG;IAC5BS,QAAQ,EAAEhB,oBAAoB,CAACiB,GADH;IAE5BT,KAAK,EAAEJ,WAFqB;IAG5BK,SAAS,EAAEC,MAAM,CAACR,EAAD,CAHW;IAI5BC,WAJ4B;IAK5BQ,IAAI,EAAE,MALsB;IAM5BN,KAAK,EAAEK,MAAM,CAACL,KAAD,CANe;IAO5BO,cAAc,EAAEN,YAPY;IAQ5BO,QAAQ,EAAE,EARkB;IAQd;IACdK,2BAA2B,EAAG,GAAEH,YAAH,aAAGA,YAAH,gDAAGA,YAAY,CAAEI,kBAAjB,0DAAG,sBAAkCC,KAAM,EAT5C;IAU5BC,yBAAyB,EACvBN,YADuB,aACvBA,YADuB,iDACvBA,YAAY,CAAEI,kBADS,2DACvB,uBAAkCG,IAAlC,CAAuCC,WAAvC;EAX0B,CAA9B;EAaA,OAAOhB,IAAP;AACD,CAtBM;AAuEP,OAAO,MAAMiB,iBAAiB,GAAG,SAMD;EAAA,IANE;IAChCtB,EADgC;IAEhCuB,oBAFgC;IAGhCC,SAHgC;IAIhCC,YAJgC;IAKhCC;EALgC,CAMF;EAC9B,MAAMC,QAAkB,GAAG;IACzBpB,SAAS,EAAEiB,SADc;IAEzBI,aAAa,EAAEpB,MAAM,CAACR,EAAD,CAFI;IAGzB6B,eAAe,EAAEJ,YAHQ;IAGM;IAC/BK,kBAAkB,EAAE,EAJK;IAID;IACxBC,aAAa,EAAE,EALU;IAKN;IACnBC,WAAW,EAAEN,iBANY;IAOzBO,0BAA0B,EAAEzB,MAAM,CAACe,oBAAD,CAPT;IAQzBW,gCAAgC,EAAE1B,MAAM,CAACR,EAAD,CARf,CAQqB;;EARrB,CAA3B;EAUA,OAAO2B,QAAP;AACD,CAlBM;AAoBP;AACA;AACA;;AA4BA,OAAO,MAAMQ,WAAW,GACtBC,KADyB,IAEgC;EACzD,IAAI,CAACA,KAAL,EAAY;IACV,OAAOC,SAAP;EACD;;EACD,OAAO;IACLC,OAAO,EAAEF,KAAK,CAACG,UADV;IAELC,KAAK,EAAEJ,KAAK,CAACK,aAFR;IAGLC,KAAK,EAAEN,KAAK,CAACM,KAHR;IAILC,SAAS,EAAEP,KAAK,CAACO,SAJZ;IAKLC,SAAS,EAAER,KAAK,CAACQ,SAAN,CAAgBC,QAAhB;EALN,CAAP;AAOD,CAbM"}
|
|
@@ -5,7 +5,7 @@ declare type FlushFailedPurchasesCachedAsPending = () => Promise<boolean>;
|
|
|
5
5
|
declare type GetItemsByType = <T = Product>(type: ProductType, skus: Sku[]) => Promise<T[]>;
|
|
6
6
|
declare type GetAvailableItemsByType = <T = Purchase>(type: ProductType) => Promise<T[]>;
|
|
7
7
|
declare type GetPurchaseHistoryByType = <T = Purchase>(type: ProductType) => Promise<T[]>;
|
|
8
|
-
export declare type BuyItemByType = (type: string, skus: Sku[], purchaseToken: string | undefined, prorationMode: ProrationModesAndroid |
|
|
8
|
+
export declare type BuyItemByType = (type: string, skus: Sku[], purchaseToken: string | undefined, prorationMode: ProrationModesAndroid | -1, obfuscatedAccountId: string | undefined, obfuscatedProfileId: string | undefined, subscriptionOffers: string[], isOfferPersonalized: boolean) => Promise<Purchase>;
|
|
9
9
|
declare type AcknowledgePurchase = (purchaseToken: string, developerPayloadAndroid?: string) => Promise<PurchaseResult | boolean>;
|
|
10
10
|
declare type ConsumeProduct = (purchaseToken: string, developerPayloadAndroid?: string) => Promise<PurchaseResult | boolean>;
|
|
11
11
|
declare type StartListening = () => Promise<void>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Product, ProductPurchase, Purchase, Sku } from '../types';
|
|
2
|
-
import type { PaymentDiscountSk2, ProductSk2, ProductStatus, TransactionSk2 } from '../types/appleSk2';
|
|
2
|
+
import type { PaymentDiscountSk2, ProductSk2, ProductStatus, RefundRequestStatus, TransactionSk2 } from '../types/appleSk2';
|
|
3
3
|
import type { NativeModuleProps } from './common';
|
|
4
4
|
declare type getItems = (skus: Sku[]) => Promise<ProductSk2[]>;
|
|
5
5
|
declare type getAvailableItems = (alsoPublishToEventListener?: boolean) => Promise<TransactionSk2[]>;
|
|
@@ -29,6 +29,7 @@ export interface IosModulePropsSk2 extends NativeModuleProps {
|
|
|
29
29
|
getPendingTransactions: getPendingTransactions;
|
|
30
30
|
presentCodeRedemptionSheet: presentCodeRedemptionSheet;
|
|
31
31
|
disable: () => Promise<null>;
|
|
32
|
+
beginRefundRequest: (sku: string) => Promise<RefundRequestStatus>;
|
|
32
33
|
}
|
|
33
34
|
/**
|
|
34
35
|
* Sync state with Appstore (iOS only)
|
|
@@ -51,4 +52,8 @@ export declare const currentEntitlement: (sku: string) => Promise<TransactionSk2
|
|
|
51
52
|
*
|
|
52
53
|
*/
|
|
53
54
|
export declare const latestTransaction: (sku: string) => Promise<TransactionSk2>;
|
|
55
|
+
/**
|
|
56
|
+
*
|
|
57
|
+
*/
|
|
58
|
+
export declare const beginRefundRequest: (sku: string) => Promise<RefundRequestStatus>;
|
|
54
59
|
export {};
|
|
@@ -21,6 +21,7 @@ export declare type SubscriptionInfo = {
|
|
|
21
21
|
subscriptionGroupID: string;
|
|
22
22
|
subscriptionPeriod: SubscriptionPeriod;
|
|
23
23
|
};
|
|
24
|
+
export declare type RefundRequestStatus = 'success' | 'userCancelled';
|
|
24
25
|
export declare type ProductSk2 = {
|
|
25
26
|
description: string;
|
|
26
27
|
displayName: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-iap",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.2.0",
|
|
4
4
|
"description": "React Native In App Purchase Module.",
|
|
5
5
|
"repository": "https://github.com/dooboolab/react-native-iap",
|
|
6
6
|
"author": "dooboolab <support@dooboolab.com> (https://github.com/dooboolab)",
|
package/src/iap.ts
CHANGED
package/src/modules/android.ts
CHANGED
|
@@ -35,7 +35,7 @@ export type BuyItemByType = (
|
|
|
35
35
|
type: string,
|
|
36
36
|
skus: Sku[],
|
|
37
37
|
purchaseToken: string | undefined,
|
|
38
|
-
prorationMode: ProrationModesAndroid |
|
|
38
|
+
prorationMode: ProrationModesAndroid | -1,
|
|
39
39
|
obfuscatedAccountId: string | undefined,
|
|
40
40
|
obfuscatedProfileId: string | undefined,
|
|
41
41
|
subscriptionOffers: string[],
|
package/src/modules/iosSk2.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
PaymentDiscountSk2,
|
|
6
6
|
ProductSk2,
|
|
7
7
|
ProductStatus,
|
|
8
|
+
RefundRequestStatus,
|
|
8
9
|
TransactionSk2,
|
|
9
10
|
} from '../types/appleSk2';
|
|
10
11
|
|
|
@@ -53,6 +54,7 @@ export interface IosModulePropsSk2 extends NativeModuleProps {
|
|
|
53
54
|
getPendingTransactions: getPendingTransactions;
|
|
54
55
|
presentCodeRedemptionSheet: presentCodeRedemptionSheet;
|
|
55
56
|
disable: () => Promise<null>;
|
|
57
|
+
beginRefundRequest: (sku: string) => Promise<RefundRequestStatus>;
|
|
56
58
|
}
|
|
57
59
|
|
|
58
60
|
/**
|
|
@@ -85,3 +87,9 @@ export const currentEntitlement = (sku: string): Promise<TransactionSk2> =>
|
|
|
85
87
|
*/
|
|
86
88
|
export const latestTransaction = (sku: string): Promise<TransactionSk2> =>
|
|
87
89
|
RNIapIosSk2.latestTransaction(sku);
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
*
|
|
93
|
+
*/
|
|
94
|
+
export const beginRefundRequest = (sku: string): Promise<RefundRequestStatus> =>
|
|
95
|
+
RNIapIosSk2.beginRefundRequest(sku);
|
package/src/types/appleSk2.ts
CHANGED
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
package com.dooboolab.RNIap
|
|
2
|
-
|
|
3
|
-
import android.util.Log
|
|
4
|
-
import com.facebook.react.bridge.ObjectAlreadyConsumedException
|
|
5
|
-
import com.facebook.react.bridge.Promise
|
|
6
|
-
import com.facebook.react.bridge.ReadableArray
|
|
7
|
-
import com.facebook.react.bridge.ReadableMap
|
|
8
|
-
import com.facebook.react.bridge.ReadableType
|
|
9
|
-
import com.facebook.react.bridge.WritableArray
|
|
10
|
-
import com.facebook.react.bridge.WritableMap
|
|
11
|
-
import com.facebook.react.bridge.WritableNativeArray
|
|
12
|
-
import com.facebook.react.bridge.WritableNativeMap
|
|
13
|
-
import org.json.JSONArray
|
|
14
|
-
import org.json.JSONException
|
|
15
|
-
import org.json.JSONObject
|
|
16
|
-
import java.lang.Exception
|
|
17
|
-
import java.util.ArrayList
|
|
18
|
-
import java.util.HashMap
|
|
19
|
-
import kotlin.Throws
|
|
20
|
-
|
|
21
|
-
class DoobooUtils {
|
|
22
|
-
private val promises = HashMap<String, ArrayList<Promise>>()
|
|
23
|
-
fun addPromiseForKey(key: String, promise: Promise) {
|
|
24
|
-
try {
|
|
25
|
-
val list: ArrayList<Promise>
|
|
26
|
-
if (promises.containsKey(key)) {
|
|
27
|
-
list = promises[key]!!
|
|
28
|
-
} else {
|
|
29
|
-
list = ArrayList()
|
|
30
|
-
}
|
|
31
|
-
list.add(promise)
|
|
32
|
-
promises[key] = list
|
|
33
|
-
} catch (oce: ObjectAlreadyConsumedException) {
|
|
34
|
-
Log.e(TAG, oce.message!!)
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
fun resolvePromisesForKey(key: String, value: Any?) {
|
|
39
|
-
try {
|
|
40
|
-
if (promises.containsKey(key)) {
|
|
41
|
-
val list = promises[key]!!
|
|
42
|
-
for (promise in list) {
|
|
43
|
-
promise.resolve(value)
|
|
44
|
-
}
|
|
45
|
-
promises.remove(key)
|
|
46
|
-
}
|
|
47
|
-
} catch (oce: ObjectAlreadyConsumedException) {
|
|
48
|
-
Log.e(TAG, oce.message!!)
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
fun rejectAllPendingPromises() {
|
|
53
|
-
promises.flatMap { it.value }.forEach { promise ->
|
|
54
|
-
promise.safeReject(E_CONNECTION_CLOSED, "Connection has been closed", null)
|
|
55
|
-
}
|
|
56
|
-
promises.clear()
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
fun rejectPromisesForKey(
|
|
60
|
-
key: String,
|
|
61
|
-
code: String?,
|
|
62
|
-
message: String?,
|
|
63
|
-
err: Exception?
|
|
64
|
-
) {
|
|
65
|
-
try {
|
|
66
|
-
if (promises.containsKey(key)) {
|
|
67
|
-
val list = promises[key]!!
|
|
68
|
-
for (promise in list) {
|
|
69
|
-
promise.reject(code, message, err)
|
|
70
|
-
}
|
|
71
|
-
promises.remove(key)
|
|
72
|
-
}
|
|
73
|
-
} catch (oce: ObjectAlreadyConsumedException) {
|
|
74
|
-
Log.e(TAG, oce.message!!)
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
@Throws(JSONException::class)
|
|
79
|
-
fun convertJsonToMap(jsonObject: JSONObject): WritableMap {
|
|
80
|
-
val map: WritableMap = WritableNativeMap()
|
|
81
|
-
val iterator = jsonObject.keys()
|
|
82
|
-
while (iterator.hasNext()) {
|
|
83
|
-
val key = iterator.next()
|
|
84
|
-
val value = jsonObject[key]
|
|
85
|
-
if (value is JSONObject) {
|
|
86
|
-
map.putMap(key, convertJsonToMap(value))
|
|
87
|
-
} else if (value is JSONArray) {
|
|
88
|
-
map.putArray(key, convertJsonToArray(value))
|
|
89
|
-
} else if (value is Boolean) {
|
|
90
|
-
map.putBoolean(key, value)
|
|
91
|
-
} else if (value is Int) {
|
|
92
|
-
map.putInt(key, value)
|
|
93
|
-
} else if (value is Double) {
|
|
94
|
-
map.putDouble(key, value)
|
|
95
|
-
} else if (value is String) {
|
|
96
|
-
map.putString(key, value)
|
|
97
|
-
} else {
|
|
98
|
-
map.putString(key, value.toString())
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return map
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
@Throws(JSONException::class)
|
|
105
|
-
fun convertJsonToArray(jsonArray: JSONArray): WritableArray {
|
|
106
|
-
val array: WritableArray = WritableNativeArray()
|
|
107
|
-
for (i in 0 until jsonArray.length()) {
|
|
108
|
-
val value = jsonArray[i]
|
|
109
|
-
if (value is JSONObject) {
|
|
110
|
-
array.pushMap(convertJsonToMap(value))
|
|
111
|
-
} else if (value is JSONArray) {
|
|
112
|
-
array.pushArray(convertJsonToArray(value))
|
|
113
|
-
} else if (value is Boolean) {
|
|
114
|
-
array.pushBoolean(value)
|
|
115
|
-
} else if (value is Int) {
|
|
116
|
-
array.pushInt(value)
|
|
117
|
-
} else if (value is Double) {
|
|
118
|
-
array.pushDouble(value)
|
|
119
|
-
} else if (value is String) {
|
|
120
|
-
array.pushString(value)
|
|
121
|
-
} else {
|
|
122
|
-
array.pushString(value.toString())
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return array
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
@Throws(JSONException::class)
|
|
129
|
-
fun convertMapToJson(readableMap: ReadableMap?): JSONObject {
|
|
130
|
-
val `object` = JSONObject()
|
|
131
|
-
val iterator = readableMap?.keySetIterator()
|
|
132
|
-
iterator?.let {
|
|
133
|
-
while (iterator.hasNextKey()) {
|
|
134
|
-
val key = iterator.nextKey()
|
|
135
|
-
when (readableMap.getType(key)) {
|
|
136
|
-
ReadableType.Null -> `object`.put(key, JSONObject.NULL)
|
|
137
|
-
ReadableType.Boolean -> `object`.put(key, readableMap.getBoolean(key))
|
|
138
|
-
ReadableType.Number -> `object`.put(key, readableMap.getDouble(key))
|
|
139
|
-
ReadableType.String -> `object`.put(key, readableMap.getString(key))
|
|
140
|
-
ReadableType.Map -> `object`.put(key, convertMapToJson(readableMap.getMap(key)))
|
|
141
|
-
ReadableType.Array -> `object`.put(
|
|
142
|
-
key,
|
|
143
|
-
convertArrayToJson(readableMap.getArray(key))
|
|
144
|
-
)
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
return `object`
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
@Throws(JSONException::class)
|
|
152
|
-
fun convertArrayToJson(readableArray: ReadableArray?): JSONArray {
|
|
153
|
-
val array = JSONArray()
|
|
154
|
-
readableArray?.let {
|
|
155
|
-
for (i in 0 until readableArray.size()) {
|
|
156
|
-
when (readableArray.getType(i)) {
|
|
157
|
-
ReadableType.Null -> {
|
|
158
|
-
}
|
|
159
|
-
ReadableType.Boolean -> array.put(readableArray.getBoolean(i))
|
|
160
|
-
ReadableType.Number -> array.put(readableArray.getDouble(i))
|
|
161
|
-
ReadableType.String -> array.put(readableArray.getString(i))
|
|
162
|
-
ReadableType.Map -> array.put(convertMapToJson(readableArray.getMap(i)))
|
|
163
|
-
ReadableType.Array -> array.put(convertArrayToJson(readableArray.getArray(i)))
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
return array
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
companion object {
|
|
171
|
-
private const val TAG = "DoobooUtils"
|
|
172
|
-
const val E_UNKNOWN = "E_UNKNOWN"
|
|
173
|
-
const val E_NOT_PREPARED = "E_NOT_PREPARED"
|
|
174
|
-
const val E_ALREADY_PREPARED = "E_ALREADY_PREPARED"
|
|
175
|
-
const val E_NOT_ENDED = "E_NOT_ENDED"
|
|
176
|
-
const val E_USER_CANCELLED = "E_USER_CANCELLED"
|
|
177
|
-
const val E_ITEM_UNAVAILABLE = "E_ITEM_UNAVAILABLE"
|
|
178
|
-
const val E_NETWORK_ERROR = "E_NETWORK_ERROR"
|
|
179
|
-
const val E_SERVICE_ERROR = "E_SERVICE_ERROR"
|
|
180
|
-
const val E_ALREADY_OWNED = "E_ALREADY_OWNED"
|
|
181
|
-
const val E_REMOTE_ERROR = "E_REMOTE_ERROR"
|
|
182
|
-
const val E_USER_ERROR = "E_USER_ERROR"
|
|
183
|
-
const val E_DEVELOPER_ERROR = "E_DEVELOPER_ERROR"
|
|
184
|
-
const val E_BILLING_RESPONSE_JSON_PARSE_ERROR = "E_BILLING_RESPONSE_JSON_PARSE_ERROR"
|
|
185
|
-
const val E_CONNECTION_CLOSED = "E_CONNECTION_CLOSED"
|
|
186
|
-
val instance = DoobooUtils()
|
|
187
|
-
}
|
|
188
|
-
}
|