diff --git a/InAppUtils/InAppUtils.h b/InAppUtils/InAppUtils.h index a3a95ff..0b28bfd 100644 --- a/InAppUtils/InAppUtils.h +++ b/InAppUtils/InAppUtils.h @@ -2,7 +2,8 @@ #import #import +#import -@interface InAppUtils : NSObject +@interface InAppUtils : RCTEventEmitter @end diff --git a/InAppUtils/InAppUtils.m b/InAppUtils/InAppUtils.m index 3b545cb..cc9eb17 100644 --- a/InAppUtils/InAppUtils.m +++ b/InAppUtils/InAppUtils.m @@ -8,17 +8,31 @@ @implementation InAppUtils { NSArray *products; NSMutableDictionary *_callbacks; + BOOL hasPurchaseCompletedListeners; + SKPaymentTransaction *currentTransaction; + BOOL shouldFinishTransactions; } - (instancetype)init { if ((self = [super init])) { + hasPurchaseCompletedListeners = NO; + shouldFinishTransactions = YES; _callbacks = [[NSMutableDictionary alloc] init]; [[SKPaymentQueue defaultQueue] addTransactionObserver:self]; } return self; } + +- (void)startObserving { + hasPurchaseCompletedListeners = YES; +} + +- (void)stopObserving { + hasPurchaseCompletedListeners = NO; +} + + (BOOL)requiresMainQueueSetup { return NO; } @@ -30,13 +44,26 @@ - (dispatch_queue_t)methodQueue RCT_EXPORT_MODULE() +- (NSArray *)supportedEvents +{ + return @[@"purchaseCompleted"]; +} + +// Transactions initiated from App Store +- (BOOL)paymentQueue:(SKPaymentQueue *)queue +shouldAddStorePayment:(SKPayment *)payment + forProduct:(SKProduct *)product { + return hasPurchaseCompletedListeners; +} + - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions { for (SKPaymentTransaction *transaction in transactions) { switch (transaction.transactionState) { case SKPaymentTransactionStateFailed: { - NSString *key = RCTKeyForInstance(transaction.payment.productIdentifier); + NSLog(@"purchase failed"); + NSString *key = transaction.payment.productIdentifier; RCTResponseSenderBlock callback = _callbacks[key]; if (callback) { callback(@[RCTJSErrorFromNSError(transaction.error)]); @@ -44,30 +71,37 @@ - (void)paymentQueue:(SKPaymentQueue *)queue } else { RCTLogWarn(@"No callback registered for transaction with state failed."); } - [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; + [self finishTransaction:transaction]; break; } case SKPaymentTransactionStatePurchased: { - NSString *key = RCTKeyForInstance(transaction.payment.productIdentifier); + NSLog(@"purchased"); + currentTransaction = transaction; + NSString *key = transaction.payment.productIdentifier; RCTResponseSenderBlock callback = _callbacks[key]; + NSDictionary *purchase = [self getPurchaseData:transaction]; if (callback) { - NSDictionary *purchase = [self getPurchaseData:transaction]; callback(@[[NSNull null], purchase]); [_callbacks removeObjectForKey:key]; - } else { - RCTLogWarn(@"No callback registered for transaction with state purchased."); } - [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; + if (hasPurchaseCompletedListeners) { + [self sendEventWithName:@"purchaseCompleted" body:purchase]; + } + if (!callback && !hasPurchaseCompletedListeners) { + RCTLogWarn(@"No callback or listener registered for transaction with state purchased."); + } + [self finishTransaction:transaction]; break; } case SKPaymentTransactionStateRestored: - [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; + NSLog(@"purchase restored"); + [self finishTransaction:transaction]; break; case SKPaymentTransactionStatePurchasing: NSLog(@"purchasing"); break; case SKPaymentTransactionStateDeferred: - NSLog(@"deferred"); + NSLog(@"purchase deferred"); break; default: break; @@ -107,25 +141,33 @@ - (void) doPurchaseProduct:(NSString *)productIdentifier payment.applicationUsername = username; } [[SKPaymentQueue defaultQueue] addPayment:payment]; - _callbacks[RCTKeyForInstance(payment.productIdentifier)] = callback; + _callbacks[payment.productIdentifier] = callback; } else { - callback(@[@"invalid_product"]); + callback(@[RCTMakeError(@"invalid_product", nil, nil)]); + } +} + +- (void) finishTransaction:(SKPaymentTransaction *)transaction +{ + if (shouldFinishTransactions) { + [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; + NSLog(@"transaction finished"); } } - (void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error { - NSString *key = RCTKeyForInstance(@"restoreRequest"); + NSString *key = @"restoreRequest"; RCTResponseSenderBlock callback = _callbacks[key]; if (callback) { switch (error.code) { case SKErrorPaymentCancelled: - callback(@[@"user_cancelled"]); + callback(@[RCTMakeError(@"user_cancelled", nil, nil)]); break; default: - callback(@[@"restore_failed"]); + callback(@[RCTJSErrorFromNSError(error)]); break; } @@ -137,7 +179,7 @@ - (void)paymentQueue:(SKPaymentQueue *)queue - (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue { - NSString *key = RCTKeyForInstance(@"restoreRequest"); + NSString *key = @"restoreRequest"; RCTResponseSenderBlock callback = _callbacks[key]; if (callback) { NSMutableArray *productsArrayForJS = [NSMutableArray array]; @@ -147,7 +189,7 @@ - (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue NSDictionary *purchase = [self getPurchaseData:transaction]; [productsArrayForJS addObject:purchase]; - [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; + [self finishTransaction:transaction]; } } callback(@[[NSNull null], productsArrayForJS]); @@ -160,17 +202,17 @@ - (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue RCT_EXPORT_METHOD(restorePurchases:(RCTResponseSenderBlock)callback) { NSString *restoreRequest = @"restoreRequest"; - _callbacks[RCTKeyForInstance(restoreRequest)] = callback; + _callbacks[restoreRequest] = callback; [[SKPaymentQueue defaultQueue] restoreCompletedTransactions]; } RCT_EXPORT_METHOD(restorePurchasesForUser:(NSString *)username - callback:(RCTResponseSenderBlock)callback) + callback:(RCTResponseSenderBlock)callback) { NSString *restoreRequest = @"restoreRequest"; - _callbacks[RCTKeyForInstance(restoreRequest)] = callback; + _callbacks[restoreRequest] = callback; if(!username) { - callback(@[@"username_required"]); + callback(@[RCTMakeError(@"username_required", nil, nil)]); return; } [[SKPaymentQueue defaultQueue] restoreCompletedTransactionsWithApplicationUsername:username]; @@ -189,14 +231,14 @@ - (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue RCT_EXPORT_METHOD(canMakePayments: (RCTResponseSenderBlock)callback) { BOOL canMakePayments = [SKPaymentQueue canMakePayments]; - callback(@[@(canMakePayments)]); + callback(@[[NSNull null], @(canMakePayments)]); } RCT_EXPORT_METHOD(receiptData:(RCTResponseSenderBlock)callback) { NSString *receipt = [self grandUnifiedReceipt]; if (receipt == nil) { - callback(@[@"not_available"]); + callback(@[RCTMakeError(@"receipt_not_available", nil, nil)]); } else { callback(@[[NSNull null], receipt]); } @@ -214,6 +256,51 @@ - (NSString *)grandUnifiedReceipt } } +RCT_EXPORT_METHOD(shouldFinishTransactions:(BOOL)finishTransactions + callback:(RCTResponseSenderBlock)callback) { + shouldFinishTransactions = finishTransactions; + callback(@[[NSNull null]]); +} + +RCT_EXPORT_METHOD(getPurchaseTransactions:(RCTResponseSenderBlock)callback) { + NSArray *transactions = [[SKPaymentQueue defaultQueue] transactions]; + NSMutableArray *purchasedTransactions = [NSMutableArray array]; + for (int k = 0; k < transactions.count; k++) { + SKPaymentTransaction *transaction = transactions[k]; + if (transaction.transactionState == SKPaymentTransactionStatePurchased) { + NSDictionary *purchase = [self getPurchaseData:transaction]; + [purchasedTransactions addObject:purchase]; + [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; + } + } + callback(@[[NSNull null], purchasedTransactions]); +} + +RCT_EXPORT_METHOD(finishCurrentTransaction:(RCTResponseSenderBlock)callback) { + if (currentTransaction) { + [[SKPaymentQueue defaultQueue] finishTransaction:currentTransaction]; + currentTransaction = nil; + NSLog(@"current transaction cleared"); + } + callback(@[[NSNull null]]); +} + +// Clears all transactions that are not in purchasing state +RCT_EXPORT_METHOD(clearCompletedTransactions:(RCTResponseSenderBlock)callback) { + NSArray *pendingTrans = [[SKPaymentQueue defaultQueue] transactions]; + int transactionsCleared = 0; + for (int k = 0; k < pendingTrans.count; k++) { + SKPaymentTransaction *transaction = pendingTrans[k]; + // Transactions in purchasing state cannot be cleared + if (transaction.transactionState != SKPaymentTransactionStatePurchasing) { + [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; + transactionsCleared++; + } + } + NSLog(@"cleared %i transactions", transactionsCleared); + callback(@[[NSNull null]]); +} + // SKProductsRequestDelegate protocol method - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response @@ -224,7 +311,7 @@ - (void)productsRequest:(SKProductsRequest *)request products = [NSMutableArray arrayWithArray:response.products]; NSMutableArray *productsArrayForJS = [NSMutableArray array]; for(SKProduct *item in response.products) { - NSDictionary *product = @{ + NSMutableDictionary *product = [NSMutableDictionary dictionaryWithDictionary:@{ @"identifier": item.productIdentifier, @"price": item.price, @"currencySymbol": [item.priceLocale objectForKey:NSLocaleCurrencySymbol], @@ -234,7 +321,12 @@ - (void)productsRequest:(SKProductsRequest *)request @"downloadable": item.isDownloadable ? @"true" : @"false" , @"description": item.localizedDescription ? item.localizedDescription : @"", @"title": item.localizedTitle ? item.localizedTitle : @"", - }; + }]; + if (@available(iOS 11.2, *)) { + if (item.introductoryPrice) { + product[@"introPrice"] = @(item.introductoryPrice.price.floatValue) ?: @""; + } + } [productsArrayForJS addObject:product]; } callback(@[[NSNull null], productsArrayForJS]); diff --git a/Readme.md b/Readme.md index 79ba175..dfad65e 100644 --- a/Readme.md +++ b/Readme.md @@ -16,16 +16,22 @@ A react-native wrapper for handling in-app purchases in iOS. ## Installation -1. Install with react-native cli `react-native install react-native-in-app-utils` +1. Install: `npm i --save react-native-in-app-utils` -2. Whenever you want to use it within React code now you just have to do: `var InAppUtils = require('NativeModules').InAppUtils;` - or for ES6: +2. Link: `react-native link react-native-in-app-utils` + +3. Use: ``` -import { NativeModules } from 'react-native' -const { InAppUtils } = NativeModules +var InAppUtils = require('react-native-in-app-utils'); ``` +or + +``` +// ES6 +import InAppUtils from 'react-native-in-app-utils'; +``` ## API @@ -34,39 +40,40 @@ const { InAppUtils } = NativeModules You have to load the products first to get the correctly internationalized name and price in the correct currency. ```javascript -const identifiers = [ - 'com.xyz.abc', -]; +const identifiers = ["com.xyz.abc"]; InAppUtils.loadProducts(identifiers, (error, products) => { - console.log(products); - //update store here. + console.log(products); + //update store here. }); ``` **Response:** An array of product objects with the following fields: -| Field | Type | Description | -| -------------- | ------- | ------------------------------------------- | -| identifier | string | The product identifier | -| price | number | The price as a number | -| currencySymbol | string | The currency symbol, i.e. "$" or "SEK" | -| currencyCode | string | The currency code, i.e. "USD" of "SEK" | -| priceString | string | Localised string of price, i.e. "$1,234.00" | -| countryCode | string | Country code of the price, i.e. "GB" or "FR"| -| downloadable | boolean | Whether the purchase is downloadable | -| description | string | Description string | -| title | string | Title string | +| Field | Type | Description | +| -------------- | ------- | -------------------------------------------- | +| identifier | string | The product identifier | +| price | number | The price as a number | +| currencySymbol | string | The currency symbol, i.e. "\$" or "SEK" | +| currencyCode | string | The currency code, i.e. "USD" of "SEK" | +| priceString | string | Localised string of price, i.e. "\$1,234.00" | +| countryCode | string | Country code of the price, i.e. "GB" or "FR" | +| downloadable | boolean | Whether the purchase is downloadable | +| description | string | Description string | +| title | string | Title string | **Troubleshooting:** If you do not get back your product(s) then there's a good chance that something in your iTunes Connect or Xcode is not properly configured. Take a look at this [StackOverflow Answer](http://stackoverflow.com/a/11707704/293280) to determine what might be the issue(s). ### Checking if payments are allowed ```javascript -InAppUtils.canMakePayments((canMakePayments) => { - if(!canMakePayments) { - Alert.alert('Not Allowed', 'This device is not allowed to make purchases. Please check restrictions on device'); - } -}) +InAppUtils.canMakePayments((error, enabled) => { + if (!enabled) { + Alert.alert( + "Not Allowed", + "This device is not allowed to make purchases. Please check restrictions on device" + ); + } +}); ``` **NOTE:** canMakePayments may return false because of country limitation or parental contol/restriction setup on the device. @@ -74,13 +81,16 @@ InAppUtils.canMakePayments((canMakePayments) => { ### Buy product ```javascript -var productIdentifier = 'com.xyz.abc'; +var productIdentifier = "com.xyz.abc"; InAppUtils.purchaseProduct(productIdentifier, (error, response) => { - // NOTE for v3.0: User can cancel the payment which will be available as error object here. - if(response && response.productIdentifier) { - Alert.alert('Purchase Successful', 'Your Transaction ID is ' + response.transactionIdentifier); - //unlock store here. - } + // NOTE for v3.0: User can cancel the payment which will be available as error object here. + if (response && response.productIdentifier) { + Alert.alert( + "Purchase Successful", + "Your Transaction ID is " + response.transactionIdentifier + ); + //unlock store here. + } }); ``` @@ -93,37 +103,40 @@ https://stackoverflow.com/questions/29255568/is-there-any-way-to-know-purchase-m **Response:** A transaction object with the following fields: -| Field | Type | Description | -| --------------------- | ------ | -------------------------------------------------- | -| originalTransactionDate | number | The original transaction date (ms since epoch) | -| originalTransactionIdentifier | string | The original transaction identifier | -| transactionDate | number | The transaction date (ms since epoch) | -| transactionIdentifier | string | The transaction identifier | -| productIdentifier | string | The product identifier | -| transactionReceipt | string | The transaction receipt as a base64 encoded string | +| Field | Type | Description | +| ----------------------------- | ------ | -------------------------------------------------- | +| originalTransactionDate | number | The original transaction date (ms since epoch) | +| originalTransactionIdentifier | string | The original transaction identifier | +| transactionDate | number | The transaction date (ms since epoch) | +| transactionIdentifier | string | The transaction identifier | +| productIdentifier | string | The product identifier | +| transactionReceipt | string | The transaction receipt as a base64 encoded string | -**NOTE:** `originalTransactionDate` and `originalTransactionIdentifier` are only available for subscriptions that were previously cancelled or expired. +**NOTE:** `originalTransactionDate` and `originalTransactionIdentifier` are only available for subscriptions that were previously cancelled or expired. ### Restore payments ```javascript InAppUtils.restorePurchases((error, response) => { - if(error) { - Alert.alert('itunes Error', 'Could not connect to itunes store.'); - } else { - Alert.alert('Restore Successful', 'Successfully restores all your purchases.'); - - if (response.length === 0) { - Alert.alert('No Purchases', "We didn't find any purchases to restore."); - return; - } + if (error) { + Alert.alert("itunes Error", "Could not connect to itunes store."); + } else { + Alert.alert( + "Restore Successful", + "Successfully restores all your purchases." + ); + + if (response.length === 0) { + Alert.alert("No Purchases", "We didn't find any purchases to restore."); + return; + } - response.forEach((purchase) => { - if (purchase.productIdentifier === 'com.xyz.abc') { - // Handle purchased product. - } - }); - } + response.forEach(purchase => { + if (purchase.productIdentifier === "com.xyz.abc") { + // Handle purchased product. + } + }); + } }); ``` @@ -132,24 +145,23 @@ https://stackoverflow.com/questions/29255568/is-there-any-way-to-know-purchase-m **Response:** An array of transaction objects with the following fields: -| Field | Type | Description | -| ------------------------------ | ------ | -------------------------------------------------- | -| originalTransactionDate | number | The original transaction date (ms since epoch) | -| originalTransactionIdentifier | string | The original transaction identifier | -| transactionDate | number | The transaction date (ms since epoch) | -| transactionIdentifier | string | The transaction identifier | -| productIdentifier | string | The product identifier | -| transactionReceipt | string | The transaction receipt as a base64 encoded string | - +| Field | Type | Description | +| ----------------------------- | ------ | -------------------------------------------------- | +| originalTransactionDate | number | The original transaction date (ms since epoch) | +| originalTransactionIdentifier | string | The original transaction identifier | +| transactionDate | number | The transaction date (ms since epoch) | +| transactionIdentifier | string | The transaction identifier | +| productIdentifier | string | The product identifier | +| transactionReceipt | string | The transaction receipt as a base64 encoded string | ### Receipts iTunes receipts are associated to the users iTunes account and can be retrieved without any product reference. ```javascript -InAppUtils.receiptData((error, receiptData)=> { - if(error) { - Alert.alert('itunes Error', 'Receipt not found.'); +InAppUtils.receiptData((error, receiptData) => { + if (error) { + Alert.alert("itunes Error", "Receipt not found."); } else { //send to validation server } @@ -163,21 +175,99 @@ InAppUtils.receiptData((error, receiptData)=> { Check if in-app purchases are enabled/disabled. ```javascript -InAppUtils.canMakePayments((enabled) => { - if(enabled) { - Alert.alert('IAP enabled'); +InAppUtils.canMakePayments((error, enabled) => { + if (enabled) { + Alert.alert("IAP enabled"); } else { - Alert.alert('IAP disabled'); + Alert.alert("IAP disabled"); } }); ``` **Response:** The enabled boolean flag. +### Listen for purchase events + +Can be used for purchases initiated from the App Store or subscription renewals. + +```javascript +import InAppUtils from "react-native-in-app-utils"; + +const listener = InAppUtils.addListener("purchaseCompleted", purchase => { + if (purchase && purchase.productIdentifier) { + Alert.alert( + "Purchase Successful", + "Your Transaction ID is " + purchase.transactionIdentifier + ); + //unlock store here. + } +}); +``` + +to remove listener: + +```javascript +listener.remove(); +``` + +**Response:** A transaction object with the following fields: + +| Field | Type | Description | +| --------------------- | ------ | -------------------------------------------------- | +| transactionDate | number | The transaction date (ms since epoch) | +| transactionIdentifier | string | The transaction identifier | +| productIdentifier | string | The product identifier | +| transactionReceipt | string | The transaction receipt as a base64 encoded string | + +### Helpers + +```javascript +// Accepts a boolean. +// Transactions are (by default) automatically finished unless you call this method before the purchase. +InAppUtils.shouldFinishTransactions(false); + +// Clears current transaction from queue. +// If you call InAppUtils.shouldFinishTransactions(false) before a purchase, +// make sure to call InAppUtils.finishCurrentTransaction() after you are done with +// the purchase data. +InAppUtils.finishCurrentTransaction(); + +// Returns all completed purchase transactions in queue and removes them from the queue +InAppUtils.getPurchaseTransactions(); + +// Clears all transactions (that are not in a purchasing state) from queue. +// Be carefull when you call this, especially if you are listening for purchases initiated +// from the App Store. You might mistakenly clear these transactions. +// Avoid calling this method on app start. +InAppUtils.clearCompletedTransactions(); +``` + +You should not need to use these helpers unless you are having any of the following issues or you know what you are doing: + +#### If users gets charged but product does not get unlocked or subscription does not get stored, then try this: + +```js +await InAppUtils.shouldFinishTransactions(false) +const purchase = await InAppUtils.purchaseProduct(...) + +// Here you can unlock product or save subscription... + +await InAppUtils.finishCurrentTransaction() +await InAppUtils.shouldFinishTransactions(true) +``` + +#### Sometimes queues are not resolved and subsequent purchases fail. Then try this: + +```js +// Don't call InAppUtils.clearCompletedTransactions() on app start +// Call it just before user initiates a purchase +await InAppUtils.clearCompletedTransactions() +const purchase = await InAppUtils.purchaseProduct(...) +``` ## Testing -To test your in-app purchases, you have to *run the app on an actual device*. Using the iOS Simulator, they will always fail as the simulator cannot connect to the iTunes Store. However, you can do certain tasks like using `loadProducts` without the need to run on a real device. +To test your in-app purchases, you have to _run the app on an actual device_. Using the iOS Simulator, they will always fail as the simulator cannot connect to the iTunes Store. However, you can do certain tasks like using `loadProducts` without the need to run on a real device. 1. Set up a test account ("Sandbox Tester") in iTunes Connect. See the official documentation [here](https://developer.apple.com/library/ios/documentation/LanguagesUtilities/Conceptual/iTunesConnect_Guide/Chapters/SettingUpUserAccounts.html#//apple_ref/doc/uid/TP40011225-CH25-SW9). @@ -211,11 +301,13 @@ async validate(receiptData) { This works on both react native and backend server, you should setup a cron job that run everyday to check if the receipt is still valid ## Free trial period for in-app-purchase + There is nothing to set up related to this library. Instead, If you want to set up a free trial period for in-app-purchase, you have to set it up at iTunes Connect > your app > your in-app-purchase > free trial period (say 3-days or any period you can find from the pulldown menu) The flow we know at this point seems to be (auto-renewal case): + 1. FIRST, user have to 'purchase' no matter the free trial period is set or not. 2. If the app is configured to have a free trial period, THEN user can use the app in that free trial period without being charged. 3. When the free trial period is over, Apple's system will start to auto-renew user's purchase, therefore user can continue to use the app, but user will be charged from that point on. diff --git a/index.js b/index.js new file mode 100644 index 0000000..05b7b9c --- /dev/null +++ b/index.js @@ -0,0 +1,76 @@ +import { NativeEventEmitter, NativeModules, Platform } from "react-native"; + +const { InAppUtils } = NativeModules; + +const InAppUtilsEmitter = new NativeEventEmitter(InAppUtils); + +const promisify = fn => (...args) => + new Promise((resolve, reject) => { + fn(...args, (err, res) => (err ? reject(err) : resolve(res))); + }); + +const IAU = Platform.select({ + ios: { + loadProducts: (products, cb) => + cb + ? InAppUtils.loadProducts(products, cb) + : promisify(InAppUtils.loadProducts)(products), + + canMakePayments: cb => + cb + ? InAppUtils.canMakePayments(cb) + : promisify(InAppUtils.canMakePayments)(), + + purchaseProduct: (productIdentifier, cb) => + cb + ? InAppUtils.purchaseProduct(productIdentifier, cb) + : promisify(InAppUtils.purchaseProduct)(productIdentifier), + + purchaseProductForUser: (productIdentifier, username, cb) => + cb + ? InAppUtils.purchaseProductForUser(productIdentifier, username, cb) + : promisify(InAppUtils.purchaseProductForUser)( + productIdentifier, + username + ), + + restorePurchases: cb => + cb + ? InAppUtils.restorePurchases(cb) + : promisify(InAppUtils.restorePurchases)(), + + restorePurchasesForUser: (username, cb) => + cb + ? InAppUtils.restorePurchasesForUser(username, cb) + : promisify(InAppUtils.restorePurchasesForUser)(username), + + receiptData: cb => + cb ? InAppUtils.receiptData(cb) : promisify(InAppUtils.receiptData)(), + + shouldFinishTransactions: (finishTransactions, cb) => + cb + ? InAppUtils.shouldFinishTransactions(finishTransactions, cb) + : promisify(InAppUtils.shouldFinishTransactions)(finishTransactions), + + getPurchaseTransactions: cb => + cb + ? InAppUtils.getPurchaseTransactions(cb) + : promisify(InAppUtils.getPurchaseTransactions)(), + + finishCurrentTransaction: cb => + cb + ? InAppUtils.finishCurrentTransaction(cb) + : promisify(InAppUtils.finishCurrentTransaction)(), + + clearCompletedTransactions: cb => + cb + ? InAppUtils.clearCompletedTransactions(cb) + : promisify(InAppUtils.clearCompletedTransactions)(), + + addListener: (...args) => InAppUtilsEmitter.addListener(...args) + }, + + android: {} +}); + +export default IAU;