Skip to content

Commit 58187d6

Browse files
committed
Pass stripeExtensionInPersonPayments feature flag into CardPresentPaymentStore
1 parent f2f6a89 commit 58187d6

File tree

3 files changed

+55
-17
lines changed

3 files changed

+55
-17
lines changed

WooCommerce/Classes/Yosemite/AuthenticatedState.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class AuthenticatedState: StoresManagerState {
2626
let storageManager = ServiceLocator.storageManager
2727
let network = AlamofireNetwork(credentials: credentials)
2828

29+
/// TODO - remove this feature flag related logic when no longer needed
30+
let allowStripeIPP = ServiceLocator.featureFlagService.isFeatureFlagEnabled(.stripeExtensionInPersonPayments)
31+
2932
services = [
3033
AccountStore(dispatcher: dispatcher, storageManager: storageManager, network: network),
3134
AppSettingsStore(dispatcher: dispatcher, storageManager: storageManager, fileStorage: PListFileStorage()),
@@ -63,7 +66,8 @@ class AuthenticatedState: StoresManagerState {
6366
CardPresentPaymentStore(dispatcher: dispatcher,
6467
storageManager: storageManager,
6568
network: network,
66-
cardReaderService: ServiceLocator.cardReaderService),
69+
cardReaderService: ServiceLocator.cardReaderService,
70+
allowStripeIPP: allowStripeIPP),
6771
ReceiptStore(dispatcher: dispatcher,
6872
storageManager: storageManager,
6973
network: network,

Yosemite/Yosemite/Stores/CardPresentPaymentStore.swift

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ public final class CardPresentPaymentStore: Store {
1313
// If retaining the service here ended up being a problem, we would need to move this Store out of Yosemite and push it up to WooCommerce.
1414
private let cardReaderService: CardReaderService
1515

16+
/// Instead of adding a reference to the feature flag service (in the WooCommerce layer),
17+
/// and since feature flag values don't mutate, let's just have a private bool passed into this service
18+
/// to allow (or not) Stripe IPP.
19+
/// TODO: Remove this feature flag when no longer needed.
20+
///
21+
private var allowStripeIPP: Bool
22+
1623
/// Which backend is the store using? Default to WCPay until told otherwise
1724
private var usingBackend: CardPresentPaymentStoreBackend = .wcpay
1825

@@ -24,10 +31,17 @@ public final class CardPresentPaymentStore: Store {
2431
/// We need to be able to cancel the process of collecting a payment.
2532
private var paymentCancellable: AnyCancellable? = nil
2633

27-
public init(dispatcher: Dispatcher, storageManager: StorageManagerType, network: Network, cardReaderService: CardReaderService) {
34+
public init(
35+
dispatcher: Dispatcher,
36+
storageManager: StorageManagerType,
37+
network: Network,
38+
cardReaderService: CardReaderService,
39+
allowStripeIPP: Bool
40+
) {
2841
self.cardReaderService = cardReaderService
2942
self.remote = WCPayRemote(network: network)
3043
self.stripeRemote = StripeRemote(network: network)
44+
self.allowStripeIPP = allowStripeIPP
3145
super.init(dispatcher: dispatcher, storageManager: storageManager, network: network)
3246
}
3347

@@ -404,6 +418,11 @@ private extension CardPresentPaymentStore {
404418
/// Does nothing if the store is already using Stripe.
405419
///
406420
func useStripeAsBackend() {
421+
guard allowStripeIPP else {
422+
DDLogError("useStripeAsBackend called when stripeExtensionInPersonPayments disabled")
423+
return
424+
}
425+
407426
guard usingBackend != .stripe else {
408427
return
409428
}

Yosemite/YosemiteTests/Stores/CardPresentPaymentStoreTests.swift

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ final class CardPresentPaymentStoreTests: XCTestCase {
6868
let cardPresentStore = CardPresentPaymentStore(dispatcher: dispatcher,
6969
storageManager: storageManager,
7070
network: network,
71-
cardReaderService: mockCardReaderService)
71+
cardReaderService: mockCardReaderService,
72+
allowStripeIPP: false)
7273

7374
let action = CardPresentPaymentAction.startCardReaderDiscovery(siteID: sampleSiteID, onReaderDiscovered: { _ in }, onError: { _ in })
7475

@@ -81,7 +82,8 @@ final class CardPresentPaymentStoreTests: XCTestCase {
8182
let cardPresentStore = CardPresentPaymentStore(dispatcher: dispatcher,
8283
storageManager: storageManager,
8384
network: network,
84-
cardReaderService: mockCardReaderService)
85+
cardReaderService: mockCardReaderService,
86+
allowStripeIPP: false)
8587

8688
let expectation = self.expectation(description: "Readers discovered")
8789

@@ -102,7 +104,8 @@ final class CardPresentPaymentStoreTests: XCTestCase {
102104
let cardPresentStore = CardPresentPaymentStore(dispatcher: dispatcher,
103105
storageManager: storageManager,
104106
network: network,
105-
cardReaderService: mockCardReaderService)
107+
cardReaderService: mockCardReaderService,
108+
allowStripeIPP: false)
106109

107110
let action = CardPresentPaymentAction.startCardReaderDiscovery(siteID: sampleSiteID, onReaderDiscovered: { _ in }, onError: { _ in })
108111

@@ -124,7 +127,8 @@ final class CardPresentPaymentStoreTests: XCTestCase {
124127
let cardPresentStore = CardPresentPaymentStore(dispatcher: dispatcher,
125128
storageManager: storageManager,
126129
network: network,
127-
cardReaderService: mockCardReaderService)
130+
cardReaderService: mockCardReaderService,
131+
allowStripeIPP: false)
128132

129133
network.simulateResponse(requestUrlSuffix: "payments/connection_tokens", filename: "generic_error")
130134

@@ -148,7 +152,8 @@ final class CardPresentPaymentStoreTests: XCTestCase {
148152
let cardPresentStore = CardPresentPaymentStore(dispatcher: dispatcher,
149153
storageManager: storageManager,
150154
network: network,
151-
cardReaderService: mockCardReaderService)
155+
cardReaderService: mockCardReaderService,
156+
allowStripeIPP: false)
152157

153158
let action = CardPresentPaymentAction.cancelCardReaderDiscovery { result in
154159
//
@@ -165,7 +170,8 @@ final class CardPresentPaymentStoreTests: XCTestCase {
165170
let cardPresentStore = CardPresentPaymentStore(dispatcher: dispatcher,
166171
storageManager: storageManager,
167172
network: network,
168-
cardReaderService: mockCardReaderService)
173+
cardReaderService: mockCardReaderService,
174+
allowStripeIPP: false)
169175

170176
let expectation = self.expectation(description: "Cancelling discovery published idle as discoveryStatus")
171177

@@ -184,7 +190,8 @@ final class CardPresentPaymentStoreTests: XCTestCase {
184190
let cardPresentStore = CardPresentPaymentStore(dispatcher: dispatcher,
185191
storageManager: storageManager,
186192
network: network,
187-
cardReaderService: mockCardReaderService)
193+
cardReaderService: mockCardReaderService,
194+
allowStripeIPP: false)
188195

189196
let expectation = self.expectation(description: "Cancelling discovery changes discoveryStatus to idle")
190197

@@ -208,7 +215,8 @@ final class CardPresentPaymentStoreTests: XCTestCase {
208215
let cardPresentStore = CardPresentPaymentStore(dispatcher: dispatcher,
209216
storageManager: storageManager,
210217
network: network,
211-
cardReaderService: mockCardReaderService)
218+
cardReaderService: mockCardReaderService,
219+
allowStripeIPP: false)
212220

213221
let expectation = self.expectation(description: "Connect to card reader")
214222

@@ -233,7 +241,8 @@ final class CardPresentPaymentStoreTests: XCTestCase {
233241
let cardPresentStore = CardPresentPaymentStore(dispatcher: dispatcher,
234242
storageManager: storageManager,
235243
network: network,
236-
cardReaderService: mockCardReaderService)
244+
cardReaderService: mockCardReaderService,
245+
allowStripeIPP: false)
237246

238247
let action = CardPresentPaymentAction.disconnect(onCompletion: { result in
239248
//
@@ -250,7 +259,8 @@ final class CardPresentPaymentStoreTests: XCTestCase {
250259
let store = CardPresentPaymentStore(dispatcher: dispatcher,
251260
storageManager: storageManager,
252261
network: network,
253-
cardReaderService: mockCardReaderService)
262+
cardReaderService: mockCardReaderService,
263+
allowStripeIPP: false)
254264
let expectation = self.expectation(description: "Load Account error response")
255265
network.simulateResponse(requestUrlSuffix: "payments/accounts", filename: "generic_error")
256266

@@ -271,7 +281,8 @@ final class CardPresentPaymentStoreTests: XCTestCase {
271281
let store = CardPresentPaymentStore(dispatcher: dispatcher,
272282
storageManager: storageManager,
273283
network: network,
274-
cardReaderService: mockCardReaderService)
284+
cardReaderService: mockCardReaderService,
285+
allowStripeIPP: false)
275286
let expectation = self.expectation(description: "Load Account fetch response")
276287
network.simulateResponse(requestUrlSuffix: "payments/accounts", filename: "wcpay-account-complete")
277288
let action = CardPresentPaymentAction.loadAccounts(siteID: sampleSiteID, onCompletion: { result in
@@ -300,7 +311,8 @@ final class CardPresentPaymentStoreTests: XCTestCase {
300311
let store = CardPresentPaymentStore(dispatcher: dispatcher,
301312
storageManager: storageManager,
302313
network: network,
303-
cardReaderService: mockCardReaderService)
314+
cardReaderService: mockCardReaderService,
315+
allowStripeIPP: false)
304316
let expectation = self.expectation(description: "Capture Payment Intent error response")
305317
network.simulateResponse(requestUrlSuffix: "payments/orders/\(sampleOrderID)/capture_terminal_payment", filename: "generic_error")
306318
let action = CardPresentPaymentAction.captureOrderPayment(siteID: sampleSiteID,
@@ -321,7 +333,8 @@ final class CardPresentPaymentStoreTests: XCTestCase {
321333
let store = CardPresentPaymentStore(dispatcher: dispatcher,
322334
storageManager: storageManager,
323335
network: network,
324-
cardReaderService: mockCardReaderService)
336+
cardReaderService: mockCardReaderService,
337+
allowStripeIPP: false)
325338
let expectation = self.expectation(description: "Load Account fetch response")
326339
network.simulateResponse(requestUrlSuffix: "payments/orders/\(sampleOrderID)/capture_terminal_payment",
327340
filename: "wcpay-payment-intent-succeeded")
@@ -342,7 +355,8 @@ final class CardPresentPaymentStoreTests: XCTestCase {
342355
let store = CardPresentPaymentStore(dispatcher: dispatcher,
343356
storageManager: storageManager,
344357
network: network,
345-
cardReaderService: mockCardReaderService)
358+
cardReaderService: mockCardReaderService,
359+
allowStripeIPP: false)
346360
let expectation = self.expectation(description: #function)
347361
network.simulateResponse(requestUrlSuffix: "payments/orders/\(sampleOrderID)/create_customer",
348362
filename: "wcpay-customer")
@@ -365,7 +379,8 @@ final class CardPresentPaymentStoreTests: XCTestCase {
365379
let store = CardPresentPaymentStore(dispatcher: dispatcher,
366380
storageManager: storageManager,
367381
network: network,
368-
cardReaderService: mockCardReaderService)
382+
cardReaderService: mockCardReaderService,
383+
allowStripeIPP: false)
369384
let expectation = self.expectation(description: #function)
370385
network.simulateResponse(requestUrlSuffix: "payments/orders/\(sampleOrderID)/create_customer",
371386
filename: "wcpay-customer-error")

0 commit comments

Comments
 (0)