j3k0 / cordova-plugin-purchase

In-App Purchase for Cordova on iOS, Android and Windows
https://purchase.cordova.fovea.cc
1.29k stars 529 forks source link

Unfinished transactions are not removed #1535

Open selcukbeyhan opened 2 months ago

selcukbeyhan commented 2 months ago

I was reading the source code for iOS and came across a situation in the code of "InAppPurchase". This function is called in the app startup:

- (void) processTransactionUpdate:(SKPaymentTransaction*)transaction withArgs:(NSArray*)callbackArgs {

    DLog(@"processTransactionUpdate:withArgs: transactionIdentifier=%@", callbackArgs[PT_INDEX_TRANSACTION_IDENTIFIER]);
    NSString *js = [NSString
        stringWithFormat:@"window.storekit.transactionUpdated.apply(window.storekit, %@)",
        [callbackArgs JSONSerialize]];
    [self.commandDelegate evalJs:js];

    SKPaymentTransactionState state = transaction.transactionState;
    BOOL canFinish = state == SKPaymentTransactionStateRestored
        || state == SKPaymentTransactionStateFailed
        || state == SKPaymentTransactionStatePurchased;

    if (g_autoFinishEnabled && canFinish) {
        [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
        [self transactionFinished:transaction];
    }
    else {
        [self.unfinishedTransactions setObject:transaction forKey:callbackArgs[PT_INDEX_TRANSACTION_IDENTIFIER]];
    }
}

If a transaction is not finished (due to any reason), it is added to the set of "self.unfinishedTransactions". However, this set is never cleaned up.

There is only one section where this set is processed, it is within "- (void) finishTransaction: (CDVInvokedUrlCommand*)command". However, to call this successfully, you need the transactionID. You cannot provide the transactionID of those unfinishedTransactions because simply there is no get for that to process them.

It seems to be processed only if the flag "g_autoFinishEnabled" is activated.

There should be a way of processing those unfinishedTransactions too.

Thanks

AlexandrDegteari commented 3 weeks ago

same problem