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

Assert that completeTransactions() was called when the app launches. #337

Merged
merged 2 commits into from
Jan 13, 2018
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.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