Skip to content

Commit 838681d

Browse files
authored
Merge pull request #248 from bizz84/feature/pre-filter-transaction-state-purchasing
Filter out transactions in purchasing state
2 parents 0efbc39 + c0e2276 commit 838681d

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

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

5+
## 0.10.5 Filter out transactions in purchasing state
6+
* 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))
7+
* Sample app: print localized description when a purchase fails with `.unknown` error
8+
59
## 0.10.4 Documentation and updates for Xcode 9
610

711
* Update to Xcode 9 recommended project settings ([#247](https://github.com/bizz84/SwiftyStoreKit/pull/247))

SwiftyStoreKit-iOS-Demo/ViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ extension ViewController {
209209
case .error(let error):
210210
print("Purchase Failed: \(error)")
211211
switch error.code {
212-
case .unknown: return alertWithTitle("Purchase failed", message: "Unknown error. Please contact support")
212+
case .unknown: return alertWithTitle("Purchase failed", message: error.localizedDescription)
213213
case .clientInvalid: // client is not allowed to issue the request, etc.
214214
return alertWithTitle("Purchase failed", message: "Not allowed to make the payment")
215215
case .paymentCancelled: // user cancelled the request, etc.

SwiftyStoreKit-macOS-Demo/ViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ extension ViewController {
200200
case .error(let error):
201201
print("Purchase Failed: \(error)")
202202
switch error.code {
203-
case .unknown: return alertWithTitle("Purchase failed", message: "Unknown error. Please contact support")
203+
case .unknown: return alertWithTitle("Purchase failed", message: error.localizedDescription)
204204
case .clientInvalid: // client is not allowed to issue the request, etc.
205205
return alertWithTitle("Purchase failed", message: "Not allowed to make the payment")
206206
case .paymentCancelled: // user cancelled the request, etc.

SwiftyStoreKit/PaymentQueueController.swift

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,16 +167,20 @@ class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
167167
* 3. complete transactions (transactionState: .purchased, .failed, .restored, .deferred)
168168
* Any transactions where state == .purchasing are ignored.
169169
*/
170-
var unhandledTransactions = paymentsController.processTransactions(transactions, on: paymentQueue)
170+
var unhandledTransactions = transactions.filter { $0.transactionState != .purchasing }
171+
172+
if unhandledTransactions.count > 0 {
173+
174+
unhandledTransactions = paymentsController.processTransactions(transactions, on: paymentQueue)
171175

172-
unhandledTransactions = restorePurchasesController.processTransactions(unhandledTransactions, on: paymentQueue)
176+
unhandledTransactions = restorePurchasesController.processTransactions(unhandledTransactions, on: paymentQueue)
173177

174-
unhandledTransactions = completeTransactionsController.processTransactions(unhandledTransactions, on: paymentQueue)
178+
unhandledTransactions = completeTransactionsController.processTransactions(unhandledTransactions, on: paymentQueue)
175179

176-
unhandledTransactions = unhandledTransactions.filter { $0.transactionState != .purchasing }
177-
if unhandledTransactions.count > 0 {
178-
let strings = unhandledTransactions.map { $0.debugDescription }.joined(separator: "\n")
179-
print("unhandledTransactions:\n\(strings)")
180+
if unhandledTransactions.count > 0 {
181+
let strings = unhandledTransactions.map { $0.debugDescription }.joined(separator: "\n")
182+
print("unhandledTransactions:\n\(strings)")
183+
}
180184
}
181185
}
182186

0 commit comments

Comments
 (0)