Created
December 9, 2016 15:30
-
-
Save EllinaKuznetcova/4e3462ddad63f6f4d73b53af1d39169a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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