Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #60 from jinSasaki/fix-product-ids
Browse files Browse the repository at this point in the history
Fix product ids bug
  • Loading branch information
jinSasaki authored Aug 12, 2021
2 parents 5ad2e9e + 2fb81d6 commit 75ebf91
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions Sources/InAppPurchase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ final public class InAppPurchase {
fileprivate let receiptRefreshProvider: ReceiptRefreshProvidable

internal init(product: ProductProvidable = ProductProvider(),
payment: PaymentProvidable = PaymentProvider(),
payment: PaymentProvidable = PaymentProvider(shouldCompleteImmediately: true, productIds: nil),
receiptRefresh: ReceiptRefreshProvidable = ReceiptRefreshProvider()) {
self.productProvider = product
self.paymentProvider = payment
Expand All @@ -56,7 +56,7 @@ final public class InAppPurchase {

extension InAppPurchase {
public convenience init(shouldCompleteImmediately: Bool, productIds: [String]? = nil) {
self.init(payment: PaymentProvider(shouldCompleteImmediately: shouldCompleteImmediately))
self.init(payment: PaymentProvider(shouldCompleteImmediately: shouldCompleteImmediately, productIds: productIds))
}
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/Internal/PaymentProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ final internal class PaymentProvider: NSObject {
private lazy var dispatchQueue: DispatchQueue = DispatchQueue(label: String(describing: self))

init(paymentQueue: PaymentQueue = SKPaymentQueue.default(),
shouldCompleteImmediately: Bool = true,
productIds: [String]? = nil) {
shouldCompleteImmediately: Bool,
productIds: [String]?) {
self.paymentQueue = paymentQueue
self.shouldCompleteImmediately = shouldCompleteImmediately
self.productIds = productIds
Expand Down
2 changes: 1 addition & 1 deletion Tests/InAppPurchaseIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class InAppPurchaseIntegrationTests: XCTestCase {
let product = StubProduct(productIdentifier: "PRODUCT_001")
let productProvider = StubProductProvider(result: .success([product]))
let queue = StubPaymentQueue()
let paymentProvider = PaymentProvider(paymentQueue: queue)
let paymentProvider = PaymentProvider(paymentQueue: queue, shouldCompleteImmediately: true, productIds: nil)

let expectation1 = self.expectation()
let expectation2 = self.expectation()
Expand Down
40 changes: 20 additions & 20 deletions Tests/PaymentProviderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class PaymentProviderTests: XCTestCase {

func testCanMakePayments() {
let queue1 = StubPaymentQueue(canMakePayments: true)
let provider1 = PaymentProvider(paymentQueue: queue1)
let provider1 = PaymentProvider(paymentQueue: queue1, shouldCompleteImmediately: true, productIds: nil)
XCTAssertTrue(provider1.canMakePayments())

let queue2 = StubPaymentQueue(canMakePayments: false)
let provider2 = PaymentProvider(paymentQueue: queue2)
let provider2 = PaymentProvider(paymentQueue: queue2, shouldCompleteImmediately: true, productIds: nil)
XCTAssertFalse(provider2.canMakePayments())
}

Expand All @@ -28,7 +28,7 @@ class PaymentProviderTests: XCTestCase {
XCTAssertTrue(observer is PaymentProvider)
expectation.fulfill()
})
let provider = PaymentProvider(paymentQueue: queue)
let provider = PaymentProvider(paymentQueue: queue, shouldCompleteImmediately: true, productIds: nil)
provider.addTransactionObserver()
self.wait(for: [expectation], timeout: 1)
}
Expand All @@ -39,7 +39,7 @@ class PaymentProviderTests: XCTestCase {
XCTAssertTrue(observer is PaymentProvider)
expectation.fulfill()
})
let provider = PaymentProvider(paymentQueue: queue)
let provider = PaymentProvider(paymentQueue: queue, shouldCompleteImmediately: true, productIds: nil)
provider.removeTransactionObserver()
self.wait(for: [expectation], timeout: 1)
}
Expand All @@ -51,7 +51,7 @@ class PaymentProviderTests: XCTestCase {
})

let payment = StubPayment(productIdentifier: "PAYMENT_001")
let provider = PaymentProvider(paymentQueue: queue)
let provider = PaymentProvider(paymentQueue: queue, shouldCompleteImmediately: true, productIds: nil)
provider.add(payment: payment) { _, _ in }
self.wait(for: [expectation], timeout: 1)
}
Expand All @@ -64,7 +64,7 @@ class PaymentProviderTests: XCTestCase {
})

let payment = StubPayment(productIdentifier: "NOT_SUPPORT_PRODUCT_001")
let provider = PaymentProvider(paymentQueue: queue, productIds: ["PRODUCT_001"])
let provider = PaymentProvider(paymentQueue: queue, shouldCompleteImmediately: true, productIds: ["PRODUCT_001"])
let addExpectation = self.expectation()
provider.add(payment: payment) { _, result in
switch result {
Expand All @@ -82,7 +82,7 @@ class PaymentProviderTests: XCTestCase {
let expectation = self.expectation()
let queue = StubPaymentQueue()

let provider = PaymentProvider(paymentQueue: queue)
let provider = PaymentProvider(paymentQueue: queue, shouldCompleteImmediately: true, productIds: nil)
provider.addPaymentHandler(withProductIdentifier: "PAYMENT_001", handler: { _, _ in
expectation.fulfill()
})
Expand All @@ -103,7 +103,7 @@ class PaymentProviderTests: XCTestCase {
let queue = StubPaymentQueue(finishTransactionHandler: { _ in
finishExpectation.fulfill()
})
let provider = PaymentProvider(paymentQueue: queue)
let provider = PaymentProvider(paymentQueue: queue, shouldCompleteImmediately: true, productIds: nil)
let payment = StubPayment(productIdentifier: "PAYMENT_001")
let expectation = self.expectation()

Expand Down Expand Up @@ -133,7 +133,7 @@ class PaymentProviderTests: XCTestCase {
let queue = StubPaymentQueue(finishTransactionHandler: { _ in
finishExpectation.fulfill()
})
let provider = PaymentProvider(paymentQueue: queue)
let provider = PaymentProvider(paymentQueue: queue, shouldCompleteImmediately: true, productIds: nil)
let payment = StubPayment(productIdentifier: "PAYMENT_001")
let expectation = self.expectation()
expectation.isInverted = true // For checking not called add(payment:)
Expand Down Expand Up @@ -164,7 +164,7 @@ class PaymentProviderTests: XCTestCase {
let queue = StubPaymentQueue(finishTransactionHandler: { _ in
finishExpectation.fulfill()
})
let provider = PaymentProvider(paymentQueue: queue, shouldCompleteImmediately: false)
let provider = PaymentProvider(paymentQueue: queue, shouldCompleteImmediately: false, productIds: nil)
let payment = StubPayment(productIdentifier: "PAYMENT_001")
let expectation = self.expectation()

Expand Down Expand Up @@ -195,7 +195,7 @@ class PaymentProviderTests: XCTestCase {
finishExpectation.fulfill()
})

let provider = PaymentProvider(paymentQueue: queue, productIds: ["PRODUCT_001"])
let provider = PaymentProvider(paymentQueue: queue, shouldCompleteImmediately: true, productIds: ["PRODUCT_001"])
let payment = StubPayment(productIdentifier: "NOT_SUPPORT_PRODUCT_001")

let fallbackExpectation = self.expectation()
Expand All @@ -220,7 +220,7 @@ class PaymentProviderTests: XCTestCase {
expectation.fulfill()
})

let provider = PaymentProvider(paymentQueue: queue)
let provider = PaymentProvider(paymentQueue: queue, shouldCompleteImmediately: true, productIds: nil)
provider.restoreCompletedTransactions(handler: { _, _ -> Void in })
self.wait(for: [expectation], timeout: 1)
}
Expand All @@ -243,7 +243,7 @@ class PaymentProviderTests: XCTestCase {
finishTransactionHandler: { _ in
finishExepextation.fulfill()
})
let provider = PaymentProvider(paymentQueue: queue)
let provider = PaymentProvider(paymentQueue: queue, shouldCompleteImmediately: true, productIds: nil)
let expectation = self.expectation()
provider.restoreCompletedTransactions { queue, error in
XCTAssertNil(error)
Expand All @@ -266,7 +266,7 @@ class PaymentProviderTests: XCTestCase {
// Should be called 2 times
finishExpectation.fulfill()
})
let provider = PaymentProvider(paymentQueue: queue)
let provider = PaymentProvider(paymentQueue: queue, shouldCompleteImmediately: true, productIds: nil)

let expectation = self.expectation()
provider.restoreCompletedTransactions { _, error in
Expand Down Expand Up @@ -297,7 +297,7 @@ class PaymentProviderTests: XCTestCase {
let queue = StubPaymentQueue(finishTransactionHandler: { _ in
finishExpectation.fulfill()
})
let provider = PaymentProvider(paymentQueue: queue)
let provider = PaymentProvider(paymentQueue: queue, shouldCompleteImmediately: true, productIds: nil)

// First restore
let expectation1 = self.expectation()
Expand Down Expand Up @@ -331,7 +331,7 @@ class PaymentProviderTests: XCTestCase {
let queue = StubPaymentQueue(finishTransactionHandler: { _ in
finishExpectation.fulfill()
})
let provider = PaymentProvider(paymentQueue: queue)
let provider = PaymentProvider(paymentQueue: queue, shouldCompleteImmediately: true, productIds: nil)

let expectation = self.expectation()
provider.restoreCompletedTransactions { _, error in
Expand Down Expand Up @@ -362,7 +362,7 @@ class PaymentProviderTests: XCTestCase {
let queue = StubPaymentQueue(finishTransactionHandler: { _ in
finishExpectation.fulfill()
})
let provider = PaymentProvider(paymentQueue: queue)
let provider = PaymentProvider(paymentQueue: queue, shouldCompleteImmediately: true, productIds: nil)
let expectation = self.expectation()
provider.set(fallbackHandler: { (_, result) in
switch result {
Expand All @@ -386,7 +386,7 @@ class PaymentProviderTests: XCTestCase {

func testSetShouldAddStorePaymentHandler() {
let queue = StubPaymentQueue()
let provider = PaymentProvider(paymentQueue: queue)
let provider = PaymentProvider(paymentQueue: queue, shouldCompleteImmediately: true, productIds: nil)
let expectation = self.expectation()
provider.set(shouldAddStorePaymentHandler: { (_, _, _) -> Bool in
expectation.fulfill()
Expand All @@ -405,7 +405,7 @@ class PaymentProviderTests: XCTestCase {
expectation.fulfill()
XCTAssertEqual(transaction.transactionIdentifier, "TRANSACTION_001")
})
let provider = PaymentProvider(paymentQueue: queue)
let provider = PaymentProvider(paymentQueue: queue, shouldCompleteImmediately: true, productIds: nil)
let payment = StubPayment(productIdentifier: "PAYMENT_001")
let transaction = StubPaymentTransaction(transactionIdentifier: "TRANSACTION_001", transactionState: .purchased, original: nil, payment: payment, error: nil)
provider.finish(transaction: .init(transaction))
Expand All @@ -423,7 +423,7 @@ class PaymentProviderTests: XCTestCase {
transactionState: .deferred
)
])
let provider = PaymentProvider(paymentQueue: queue)
let provider = PaymentProvider(paymentQueue: queue, shouldCompleteImmediately: true, productIds: nil)
let transactions = provider.transactions
XCTAssertEqual(transactions.count, 2)
XCTAssertEqual(transactions[0].transactionIdentifier, "TRANSACTION_001")
Expand Down

0 comments on commit 75ebf91

Please sign in to comment.