benjaminmayo / merchantkit

A modern In-App Purchases management framework for iOS.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crash when force unwrapping `transaction.error!`

pkamb opened this issue · comments

I'm attempting to purchase a sandbox environment IAP with my non-sandbox Apple ID.

Using tag 0.14.0.

This displays an alert error message:

You are not authorized to make purchases of this InApp in Sandbox at this time.
[Environment: Sandbox]

and then hits the delegate method in StoreKitTransactionObserver.swift:

fileprivate func failPurchase(for transaction: SKPaymentTransaction, on paymentQueue: SKPaymentQueue) {
    self.delegate?.storeInterface(self.storeInterface, didFailToPurchaseProductWith: transaction.payment.productIdentifier, error: transaction.error!)
    
    paymentQueue.finishTransaction(transaction)
}

The transaction.error! force unwrap there is crashing as error is nil.

po transaction
<SKPaymentTransaction: 0x600000016030>

po transaction.error
nil

I'm going to switch to using a Sandbox account, which should hopefully fix the issue. But wanted to open an Issue here before I forget.

Thanks for flagging this. We had a similar issue before. StoreKit's documented nullability conditions are not adhered to religiously by the framework, particularly when mixing sandbox/test/production accounts and receipts.