My code presents a full screen cover when starting IAP and dismisses it at the end of the process. Not having this callback will cause the user’s screen and the underlying Async/Await I wrapped around the callbacks to lock up indefinitely.
It seems that in the Swift code of the IAP package, nothing is sent back to the C# side indicate that the purchase was cancelled.
/**
Purchase the `Product`. Once the StoreKit returns result of the purchase, the function checks whether the transaction is verified.
If it is verified, this function returns the content to the user using transactionObserver and finish a transaction.
If it isn't verified, this function rethrows the verification error.
*/
#if !os(visionOS)
private func purchase(_ product: Product, options: Set<Product.PurchaseOption>) async throws -> PurchaseDetails? {
let result = try await product.purchase(options: options)
switch result {
case .success(let verification):
_ = try transactionObserver.checkVerified(verification)
return verification.purchaseDetails()
case .userCancelled:
return nil
case .pending:
let jsonString = encodeToJSON( ["products": [product]])
await storeKitCallback.callback(subject: "OnPurchaseDeferred", payload: jsonString, entitlementStatus: 0)
return nil
default:
return nil
}
}
#endif