Failed transaction appears in the payment queue when user tries to buy product in sandbox environment

Sometimes when the user tries to buy a product, a failed transaction appears in the payment queue.


When user taps on buy button, the following code is run


func buy(product: SKProduct) {
    let payment = SKPayment(product: product)
    SKPaymentQueue.default().add(payment)
}


Afterwards, the method `paymentQueue(_:updatedTransactions:)` of the registered SKPaymentTransactionObserver is called with a failed transaction.


The error object of the transaction is as follows-


Cannot connect to iTunes Store Error Domain=NSURLErrorDomain Code=-1200 "Cannot connect to iTunes Store" UserInfo={_kCFStreamErrorDomainKey=3, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask<E979C8A8-8B0B-498D-B086-212B6AFF4B3E>.<2>, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, NSErrorFailingURLKey=https://sandbox.itunes.apple.com/WebObjects/MZFinance.woa/wa/inAppBuy, _NSURLErrorRelatedURLSessionTaskErrorKey=("LocalDataTask <E979C8A8-8B9B-498D-B0860212B6AFF4B3E>.<2>"), NSLocalisedDescription=Cannot connect to iTunes Store, NSErrorFailingURLStringKey=https://sandbox.itunes.apple.com/WebObjects/MZFinance.woa/wa/inAppBuy,NSUnderlyingError=0x280ad8060 {Error Domain=kCFErrorDomainCFNetwork Code=-1200 "(null)" UserInfo={_kCFStreamPropertySSLClientCertificateState=0, _kCFNetworkCGStreamSSLErrorOriginalValue=-9816, _kCGStreamErrorDomainKey=3, _kCGStreamErrorCodeKey=-9816}}, _kCGStreamErrorCodeKey=-9816}



Can anyone point out how to solve this issue?

Answered by PBK in 412862022

This will occur when the user is asked by the App Store to update their credit card information. Ater they do that they are given the choice of proceeding with the purchase. If they chose 'no' then the app gets a single transaction with state 'failed'. If they say 'yes' then the app gets two transactions in rapid succession - the first is 'failed' and the seocnd is 'purchased'. You need to maintain a transactionObserver after the first transaction to get the second transaction.

Accepted Answer

This will occur when the user is asked by the App Store to update their credit card information. Ater they do that they are given the choice of proceeding with the purchase. If they chose 'no' then the app gets a single transaction with state 'failed'. If they say 'yes' then the app gets two transactions in rapid succession - the first is 'failed' and the seocnd is 'purchased'. You need to maintain a transactionObserver after the first transaction to get the second transaction.

I have the same issue....after the first try buyings are fine.


Unfortunally my app is in review and they rejects it!

Failed transaction appears in the payment queue when user tries to buy product in sandbox environment
 
 
Q