Skip to content

Commit 8ebbd2e

Browse files
committed
Skip CIAB checks if CIAB is supported but site is not found
1 parent 83c536a commit 8ebbd2e

File tree

2 files changed

+53
-16
lines changed

2 files changed

+53
-16
lines changed

Modules/Sources/Yosemite/Stores/OrderCardPresentPaymentEligibilityStore.swift

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,20 @@ private extension OrderCardPresentPaymentEligibilityStore {
8181
)
8282
}
8383

84-
guard let site else {
85-
logFailedDefaultSiteRead(siteID: siteID)
86-
87-
return onCompletion(
88-
.failure(
89-
OrderIsEligibleForCardPresentPaymentError.failedToObtainSite
84+
if let site {
85+
guard siteCIABEligibilityChecker.isFeatureSupported(.cardReader, for: site) else {
86+
return onCompletion(
87+
.failure(
88+
OrderIsEligibleForCardPresentPaymentError.cardReaderPaymentOptionIsNotSupportedForCIABSites
89+
)
9090
)
91-
)
92-
}
93-
94-
guard siteCIABEligibilityChecker.isFeatureSupported(.cardReader, for: site) else {
95-
return onCompletion(
96-
.failure(
97-
OrderIsEligibleForCardPresentPaymentError.cardReaderPaymentOptionIsNotSupportedForCIABSites
98-
)
99-
)
91+
}
92+
} else {
93+
/// Don't interrupt the flow if the `site` is not found
94+
/// Making the assumption that it's not a CIAB site and skipping those checks
95+
///
96+
/// Log an error
97+
logFailedDefaultSiteRead(siteID: siteID)
10098
}
10199
}
102100

@@ -146,7 +144,6 @@ private extension OrderCardPresentPaymentEligibilityStore {
146144
extension OrderCardPresentPaymentEligibilityStore {
147145
enum OrderIsEligibleForCardPresentPaymentError: Error {
148146
case orderNotFoundInStorage
149-
case failedToObtainSite
150147
case cardReaderPaymentOptionIsNotSupportedForCIABSites
151148
}
152149
}

Modules/Tests/YosemiteTests/Stores/OrderCardPresentPaymentEligibilityStoreTests.swift

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,4 +253,44 @@ final class OrderCardPresentPaymentEligibilityStoreTests: XCTestCase {
253253
let eligibility = try XCTUnwrap(result.get())
254254
XCTAssertTrue(eligibility)
255255
}
256+
257+
func test_orderIsEligibleForCardPresentPayment_returns_success_when_site_is_not_obtained_and_CIAB_supported() throws {
258+
// Given
259+
let orderItem = OrderItem.fake().copy(itemID: 1234,
260+
name: "Chocolate cake",
261+
productID: 678,
262+
quantity: 1.0)
263+
let cppEligibleOrder = Order.fake().copy(siteID: sampleSiteID,
264+
orderID: 111,
265+
status: .pending,
266+
currency: "USD",
267+
datePaid: nil,
268+
total: "5.00",
269+
paymentMethodID: "woocommerce_payments",
270+
items: [orderItem])
271+
let nonSubscriptionProduct = Product.fake().copy(siteID: sampleSiteID,
272+
productID: 678,
273+
name: "Chocolate cake",
274+
productTypeKey: "simple")
275+
276+
storageManager.insertSampleProduct(readOnlyProduct: nonSubscriptionProduct)
277+
storageManager.insertSampleOrder(readOnlyOrder: cppEligibleOrder)
278+
279+
let configuration = CardPresentPaymentsConfiguration(country: .US)
280+
281+
// When
282+
let result = waitFor { promise in
283+
let action = OrderCardPresentPaymentEligibilityAction
284+
.orderIsEligibleForCardPresentPayment(orderID: 111,
285+
siteID: self.sampleSiteID,
286+
cardPresentPaymentsConfiguration: configuration) { result in
287+
promise(result)
288+
}
289+
self.store.onAction(action)
290+
}
291+
292+
// Then
293+
let eligibility = try XCTUnwrap(result.get())
294+
XCTAssertTrue(eligibility)
295+
}
256296
}

0 commit comments

Comments
 (0)