Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter out transactions in purchasing state #248

Merged
merged 3 commits into from
Aug 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to this project will be documented in this file.

## 0.10.5 Filter out transactions in purchasing state
* Filter out all transactions with state == .purchasing early in purchase flows (related to [#169](https://github.com/bizz84/SwiftyStoreKit/issues/169), [#188](https://github.com/bizz84/SwiftyStoreKit/pull/188), [#179](https://github.com/bizz84/SwiftyStoreKit/issues/179))
* Sample app: print localized description when a purchase fails with `.unknown` error

## 0.10.4 Documentation and updates for Xcode 9

* Update to Xcode 9 recommended project settings ([#247](https://github.com/bizz84/SwiftyStoreKit/pull/247))
Expand Down
2 changes: 1 addition & 1 deletion SwiftyStoreKit-iOS-Demo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ extension ViewController {
case .error(let error):
print("Purchase Failed: \(error)")
switch error.code {
case .unknown: return alertWithTitle("Purchase failed", message: "Unknown error. Please contact support")
case .unknown: return alertWithTitle("Purchase failed", message: error.localizedDescription)
case .clientInvalid: // client is not allowed to issue the request, etc.
return alertWithTitle("Purchase failed", message: "Not allowed to make the payment")
case .paymentCancelled: // user cancelled the request, etc.
Expand Down
2 changes: 1 addition & 1 deletion SwiftyStoreKit-macOS-Demo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ extension ViewController {
case .error(let error):
print("Purchase Failed: \(error)")
switch error.code {
case .unknown: return alertWithTitle("Purchase failed", message: "Unknown error. Please contact support")
case .unknown: return alertWithTitle("Purchase failed", message: error.localizedDescription)
case .clientInvalid: // client is not allowed to issue the request, etc.
return alertWithTitle("Purchase failed", message: "Not allowed to make the payment")
case .paymentCancelled: // user cancelled the request, etc.
Expand Down
18 changes: 11 additions & 7 deletions SwiftyStoreKit/PaymentQueueController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,20 @@ class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
* 3. complete transactions (transactionState: .purchased, .failed, .restored, .deferred)
* Any transactions where state == .purchasing are ignored.
*/
var unhandledTransactions = paymentsController.processTransactions(transactions, on: paymentQueue)
var unhandledTransactions = transactions.filter { $0.transactionState != .purchasing }

if unhandledTransactions.count > 0 {

unhandledTransactions = paymentsController.processTransactions(transactions, on: paymentQueue)

unhandledTransactions = restorePurchasesController.processTransactions(unhandledTransactions, on: paymentQueue)
unhandledTransactions = restorePurchasesController.processTransactions(unhandledTransactions, on: paymentQueue)

unhandledTransactions = completeTransactionsController.processTransactions(unhandledTransactions, on: paymentQueue)
unhandledTransactions = completeTransactionsController.processTransactions(unhandledTransactions, on: paymentQueue)

unhandledTransactions = unhandledTransactions.filter { $0.transactionState != .purchasing }
if unhandledTransactions.count > 0 {
let strings = unhandledTransactions.map { $0.debugDescription }.joined(separator: "\n")
print("unhandledTransactions:\n\(strings)")
if unhandledTransactions.count > 0 {
let strings = unhandledTransactions.map { $0.debugDescription }.joined(separator: "\n")
print("unhandledTransactions:\n\(strings)")
}
}
}

Expand Down