Skip to content

Commit

Permalink
Merge pull request #264 from dooboolab/force-finish-transaction
Browse files Browse the repository at this point in the history
Force finish transaction
  • Loading branch information
hyochan committed Sep 16, 2018
2 parents 1ea17c0 + 2576c53 commit 589013a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions index.js
Expand Up @@ -148,6 +148,17 @@ export const finishTransaction = () => Platform.select({
android: () => Promise.resolve(),
})();

/**
* Clear Transaction (iOS only)
* Finish remaining transactions. Related to issue #257
* link : https://github.com/dooboolab/react-native-iap/issues/257
* @returns {null}
*/
export const clearTransaction = () => Platform.select({
ios: () => RNIapIos.clearTransaction(),
android: () => console.log(' No effect on Android!'),
})();

/**
* Consume a product (on Android.) No-op on iOS.
* @param {string} token The product's token (on Android)
Expand Down Expand Up @@ -256,6 +267,7 @@ export default {
buyProductWithQuantityIOS,
buyProductWithoutFinishTransaction,
finishTransaction,
clearTransaction,
consumePurchase,
validateReceiptIos,
validateReceiptAndroid,
Expand Down
8 changes: 8 additions & 0 deletions ios/RNIapIos.m
Expand Up @@ -169,6 +169,14 @@ -(void)rejectPromisesForKey:(NSString*)key code:(NSString*)code message:(NSStrin
currentTransaction = nil;
}

RCT_EXPORT_METHOD(clearTransaction) {
NSArray *pendingTrans = [[SKPaymentQueue defaultQueue] transactions];
NSLog(@"\n\n\n *** clear remaining Transactions. Call this before make a new transaction \n\n.");
for (int k = 0; k < pendingTrans.count; k++) {
[[SKPaymentQueue defaultQueue] finishTransaction:pendingTrans[k]];
}
}

#pragma mark ===== StoreKit Delegate

-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
Expand Down

0 comments on commit 589013a

Please sign in to comment.