[StoreKit2] Purchase completion is displayed even if it has not been completed.

StoreKit2 is being tested in a Sandbox environment for the purchase of consumable items. The code being implemented is below.

        let result = try? await product.purchase()
        switch result {
        case let .success(verification):
            switch verification {
            case let .verified(transaction):
                let jws = verification.jwsRepresentation
                let success = await purchaseItem(of: itemId, with: jws)
                if success {
                    await transaction.finish()
                    return (success: true, error: nil)
                } else {
                    return (success: false, error: .serverError)
                }
            case .unverified:
                return (success: false, error: .unverified)
            }

Assume that the verification was successful, but a server error occurred. in let success = await purchaseItem(of: itemId, with: jws), success = false

When tested in Sandbox and local environment, the first alert of purchase completion is displayed. After that, a purchase failure alert is displayed. (The purchase failure alert is displayed by the result of return (success: false, error: .serverError))

  1. Is it proper behavior to display purchase completion once?

  2. Is it appropriate behavior for the purchase completion to be displayed once in the production environment?

  3. Is the billing actually occurring at this time?

Thank you in advance for your answers!

case let .verified(transaction):

The above case indicates that the purchase succeeded. Your customer was successfully charged.

After that, a purchase failure alert is displayed. (The purchase failure alert is displayed by the result of return (success: false, error: .serverError)) BlockQuote

This most likely comes from executing:

let success = await purchaseItem(of: itemId, with: jws)

You need to debug the above line to understand why it is failing.
For more information about the purchase lifecycle, see 2024 WWDC Explore App Store server APIs for In-App Purchase.

[StoreKit2] Purchase completion is displayed even if it has not been completed.
 
 
Q