Skip to content

Instantly share code, notes, and snippets.

@EllinaKuznetcova
Created December 9, 2016 15:30
Show Gist options
  • Save EllinaKuznetcova/4e3462ddad63f6f4d73b53af1d39169a to your computer and use it in GitHub Desktop.
Save EllinaKuznetcova/4e3462ddad63f6f4d73b53af1d39169a to your computer and use it in GitHub Desktop.
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
for transaction in transactions {
guard let productType = ProductType(rawValue: transaction.payment.productIdentifier) else {fatalError()}
switch transaction.transactionState {
case .purchasing:
self.delegate?.inAppLoadingStarted()
case .purchased:
SKPaymentQueue.default().finishTransaction(transaction)
self.updateSubscriptionStatus()
self.isSubscriptionAvailable = true
self.delegate?.inAppLoadingSucceded(productType: productType)
case .failed:
if let transactionError = transaction.error as? NSError,
transactionError.code != SKError.paymentCancelled.rawValue {
self.delegate?.inAppLoadingFailed(error: transaction.error)
} else {
self.delegate?.inAppLoadingFailed(error: InAppErrors.noSubscriptionPurchased)
}
SKPaymentQueue.default().finishTransaction(transaction)
case .restored:
SKPaymentQueue.default().finishTransaction(transaction)
self.updateSubscriptionStatus()
self.isSubscriptionAvailable = true
self.delegate?.inAppLoadingSucceded(productType: productType)
case .deferred:
self.delegate?.inAppLoadingSucceded(productType: productType)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment