I have scenario same as this sample project of StoreKit 2 in SwiftUI.
I am facing issue while transaction will be interrupted (like change payment method, incoming call, app close, battery died, anything...)
While buying fuel, it will available for all cars. I want to track fuel for particular car. How can I track transaction(interrupted)?
func purchase(_ product: Product) async throws -> Transaction? {
// Begin purchasing the `Product` the user selects.
let result = try await product.purchase()
switch result {
case .success(let verification):
// Check whether the transaction is verified. If it isn't,
// this function rethrows the verification error.
let transaction = try checkVerified(verification)
// The transaction is verified. Deliver content to the user.
await updateCustomerProductStatus()
// Always finish a transaction.
await transaction.finish()
return transaction
case .userCancelled, .pending:
return nil
default:
return nil
}
}
Steps to understand the issue:
- Go to "Shop"
- Buy "Race Car" & "Off-road vehicle"
- Click on "Race Car" to go in the detail page
- Try to buying "fuel87" for "Race Car" (this scenario might be not reproducible in sandbox account)
Now, I can see "fuel87" for both car. (I know, fuel is fuel for all the car. BUT in my case I have to track "fuel" for selected car)
How can I achieve that?