Skip to content

Commit

Permalink
Merge pull request #337 from bizz84/assert-complete-transactions-call…
Browse files Browse the repository at this point in the history
…ed-on-startup

Assert that completeTransactions() was called when the app launches.
  • Loading branch information
bizz84 authored Jan 13, 2018
2 parents 109ef6e + 2ea310f commit a56093c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
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.12.1](https://github.com/bizz84/SwiftyStoreKit/releases/tag/0.12.1) Assert that `completeTransactions` was called when the app launches.

* Assert that `completeTransactions()` was called when the app launches ([#337](https://github.com/bizz84/SwiftyStoreKit/pull/337), related issue: [#287](https://github.com/bizz84/SwiftyStoreKit/issues/287))

## [0.12.0](https://github.com/bizz84/SwiftyStoreKit/releases/tag/0.12.0) Add `verifySubscriptions` method for subscription groups

* Add `verifySubscriptions` method to check all subscriptions in a group at once ([#333](https://github.com/bizz84/SwiftyStoreKit/pull/333), related issue: [#194](https://github.com/bizz84/SwiftyStoreKit/issues/194))
Expand Down
10 changes: 9 additions & 1 deletion SwiftyStoreKit/PaymentQueueController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,16 @@ class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
super.init()
paymentQueue.add(self)
}

private func assertCompleteTransactionsWasCalled() {

let message = "SwiftyStoreKit.completeTransactions() must be called when the app launches."
assert(completeTransactionsController.completeTransactions != nil, message)
}

func startPayment(_ payment: Payment) {

assertCompleteTransactionsWasCalled()

let skPayment = SKMutablePayment(product: payment.product)
skPayment.applicationUsername = payment.applicationUsername
skPayment.quantity = payment.quantity
Expand All @@ -115,6 +122,7 @@ class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
}

func restorePurchases(_ restorePurchases: RestorePurchases) {
assertCompleteTransactionsWasCalled()

if restorePurchasesController.restorePurchases != nil {
return
Expand Down
14 changes: 8 additions & 6 deletions SwiftyStoreKitTests/PaymentQueueControllerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class PaymentQueueControllerTests: XCTestCase {

let payment = makeTestPayment(productIdentifier: "com.SwiftyStoreKit.product1") { _ in }

paymentQueueController.completeTransactions(CompleteTransactions(atomically: true) { _ in })

paymentQueueController.startPayment(payment)

XCTAssertEqual(spy.payments.count, 1)
Expand Down Expand Up @@ -127,12 +129,12 @@ class PaymentQueueControllerTests: XCTestCase {
}

// run
paymentQueueController.completeTransactions(completeTransactions)

paymentQueueController.startPayment(testPayment)

paymentQueueController.restorePurchases(restorePurchases)

paymentQueueController.completeTransactions(completeTransactions)

paymentQueueController.paymentQueue(SKPaymentQueue(), updatedTransactions: transactions)
paymentQueueController.paymentQueueRestoreCompletedTransactionsFinished(SKPaymentQueue())

Expand Down Expand Up @@ -183,10 +185,10 @@ class PaymentQueueControllerTests: XCTestCase {
}

// run
paymentQueueController.startPayment(testPayment)

paymentQueueController.completeTransactions(completeTransactions)

paymentQueueController.startPayment(testPayment)

paymentQueueController.paymentQueue(SKPaymentQueue(), updatedTransactions: transactions)
paymentQueueController.paymentQueueRestoreCompletedTransactionsFinished(SKPaymentQueue())

Expand Down Expand Up @@ -238,10 +240,10 @@ class PaymentQueueControllerTests: XCTestCase {
}

// run
paymentQueueController.restorePurchases(restorePurchases)

paymentQueueController.completeTransactions(completeTransactions)

paymentQueueController.restorePurchases(restorePurchases)

paymentQueueController.paymentQueue(SKPaymentQueue(), updatedTransactions: transactions)
paymentQueueController.paymentQueueRestoreCompletedTransactionsFinished(SKPaymentQueue())

Expand Down

0 comments on commit a56093c

Please sign in to comment.