"You're all set" alert not showing when a purchase is done a second time

92 Views Asked by At

I'm adding in-app purchase in my app using the new ProductView. The first time I tried to purchase my product, I got an alert saying "You're all set". But when I purchased my product a second time, the alert did not show up. The product is a consumable. Why is that alert not showing? What am I missing?

ProductView(id: productId)
    .productViewStyle(.compact)
    .onInAppPurchaseStart { product in
        logger.log("User has started buying \(product.id)")
    }
    .onInAppPurchaseCompletion { product, result in
        if case .success(.success(let transaction)) = result {
            logger.log("Success")
        } else {
            logger.log("Failure")
        }
    }
2

There are 2 best solutions below

1
shim On

After the purchase is successful you still need to call finish on the transaction somewhere down the line.

.onInAppPurchaseCompletion { product, result in
    if case .success(.success(let transaction)) = result {
        logger.log("Success")
        // do anything you need to do on your end to complete the transaction
        transaction.finish()
    } else {
        logger.log("Failure")
    }
}
0
Vincent Garcia On

The code bellow "works" in a way that every time I purchase the same product, the transaction actually completes and I get the expected "You're all set" acknowledgment alert message:

ProductView(id: productId)
    .productViewStyle(.compact)
    .onInAppPurchaseStart { product in
        logger.log("User has started buying \(product.id)")
    }
    .onInAppPurchaseCompletion { product, result in
        switch result {

        case .success(let purchaseResult):
            switch purchaseResult {
            case .success(let verificationResult):
                switch verificationResult {
                case .verified(let transaction):
                    // Do something
                    await transaction.finish()
                case .unverified(let transaction, let verificationError):
                    // Do something
                }
            case .pending:
                // Do something
            case .userCancelled:
                // Do something
            @unknown default:
                // Do something
                break
            }

        case .failure(let error):
            // Do something
        }
    }

The different placeholders need to be replaced with actual code.