Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force finish transaction #264

Merged
merged 2 commits into from Sep 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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