Skip to content

Commit 92c3fc8

Browse files
authored
Merge pull request #5358 from woocommerce/issue/4428-in-test-mode-with-live-ui
[Mobile Payments] Prompt user to take live account out of test mode to do in-person payments
2 parents 4e170c4 + dff5eea commit 92c3fc8

File tree

10 files changed

+114
-10
lines changed

10 files changed

+114
-10
lines changed

Fakes/Fakes/Networking.generated.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,9 @@ extension PaymentGatewayAccount {
489489
defaultCurrency: .fake(),
490490
supportedCurrencies: .fake(),
491491
country: .fake(),
492-
isCardPresentEligible: .fake()
492+
isCardPresentEligible: .fake(),
493+
isLive: .fake(),
494+
isInTestMode: .fake()
493495
)
494496
}
495497
}

Networking/Networking/Model/Copiable/Models+Copiable.generated.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,9 @@ extension PaymentGatewayAccount {
286286
defaultCurrency: CopiableProp<String> = .copy,
287287
supportedCurrencies: CopiableProp<[String]> = .copy,
288288
country: CopiableProp<String> = .copy,
289-
isCardPresentEligible: CopiableProp<Bool> = .copy
289+
isCardPresentEligible: CopiableProp<Bool> = .copy,
290+
isLive: CopiableProp<Bool> = .copy,
291+
isInTestMode: CopiableProp<Bool> = .copy
290292
) -> PaymentGatewayAccount {
291293
let siteID = siteID ?? self.siteID
292294
let gatewayID = gatewayID ?? self.gatewayID
@@ -299,6 +301,8 @@ extension PaymentGatewayAccount {
299301
let supportedCurrencies = supportedCurrencies ?? self.supportedCurrencies
300302
let country = country ?? self.country
301303
let isCardPresentEligible = isCardPresentEligible ?? self.isCardPresentEligible
304+
let isLive = isLive ?? self.isLive
305+
let isInTestMode = isInTestMode ?? self.isInTestMode
302306

303307
return PaymentGatewayAccount(
304308
siteID: siteID,
@@ -311,7 +315,9 @@ extension PaymentGatewayAccount {
311315
defaultCurrency: defaultCurrency,
312316
supportedCurrencies: supportedCurrencies,
313317
country: country,
314-
isCardPresentEligible: isCardPresentEligible
318+
isCardPresentEligible: isCardPresentEligible,
319+
isLive: isLive,
320+
isInTestMode: isInTestMode
315321
)
316322
}
317323
}

Networking/Networking/Model/PaymentGatewayAccount.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ public struct PaymentGatewayAccount: GeneratedCopiable, GeneratedFakeable {
3030
/// A boolean flag indicating if this Account is eligible for card present payments
3131
public let isCardPresentEligible: Bool
3232

33+
/// Indicates if the account is live (i.e. can accept actual payments)
34+
public let isLive: Bool
35+
36+
/// Indicates if the gateway is set for test mode. This is NOT the same as
37+
/// whether the account is live or not. You can have a live account set for
38+
/// test mode, although we cannot accept in-person payments in that situation.
39+
public let isInTestMode: Bool
40+
3341
/// Struct initializer
3442
///
3543
public init(siteID: Int64,
@@ -42,7 +50,9 @@ public struct PaymentGatewayAccount: GeneratedCopiable, GeneratedFakeable {
4250
defaultCurrency: String,
4351
supportedCurrencies: [String],
4452
country: String,
45-
isCardPresentEligible: Bool
53+
isCardPresentEligible: Bool,
54+
isLive: Bool,
55+
isInTestMode: Bool
4656
) {
4757
self.siteID = siteID
4858
self.gatewayID = gatewayID
@@ -55,5 +65,7 @@ public struct PaymentGatewayAccount: GeneratedCopiable, GeneratedFakeable {
5565
self.supportedCurrencies = supportedCurrencies
5666
self.country = country
5767
self.isCardPresentEligible = isCardPresentEligible
68+
self.isLive = isLive
69+
self.isInTestMode = isInTestMode
5870
}
5971
}

WooCommerce/Classes/ViewRelated/Dashboard/Settings/In-Person Payments/CardPresentPaymentsOnboardingUseCase.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,7 @@ private extension CardPresentPaymentsOnboardingUseCase {
223223
}
224224

225225
func isWCPayInTestModeWithLiveStripeAccount(account: PaymentGatewayAccount) -> Bool {
226-
// TODO: not implemented yet
227-
return false
226+
account.isLive && account.isInTestMode
228227
}
229228

230229
func isStripeAccountUnderReview(account: PaymentGatewayAccount) -> Bool {

WooCommerce/Classes/ViewRelated/Dashboard/Settings/In-Person Payments/InPersonPaymentsViewController.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ struct InPersonPaymentsView: View {
3535
InPersonPaymentsPluginNotSupportedVersion(onRefresh: viewModel.refresh)
3636
case .wcpayNotActivated:
3737
InPersonPaymentsPluginNotActivated(onRefresh: viewModel.refresh)
38+
case .wcpayInTestModeWithLiveStripeAccount:
39+
InPersonPaymentsLiveSiteInTestMode(onRefresh:
40+
viewModel.refresh)
3841
case .wcpaySetupNotCompleted:
3942
InPersonPaymentsWCPayNotSetup(onRefresh: viewModel.refresh)
4043
case .stripeAccountOverdueRequirement:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import SwiftUI
2+
3+
struct InPersonPaymentsLiveSiteInTestMode: View {
4+
let onRefresh: () -> Void
5+
6+
var body: some View {
7+
ScrollableVStack {
8+
Spacer()
9+
10+
VStack(alignment: .center, spacing: 42) {
11+
Text(Localization.title)
12+
.font(.headline)
13+
Image(uiImage: .paymentsPlugin)
14+
.resizable()
15+
.scaledToFit()
16+
.frame(height: 108.0)
17+
Text(Localization.message)
18+
.font(.callout)
19+
}
20+
.multilineTextAlignment(.center)
21+
22+
Spacer()
23+
24+
Button(Localization.primaryButton, action: onRefresh)
25+
.buttonStyle(PrimaryButtonStyle())
26+
.padding(.bottom, 24.0)
27+
InPersonPaymentsLearnMore()
28+
}
29+
}
30+
}
31+
32+
private enum Localization {
33+
static let title = NSLocalizedString(
34+
"WooCommerce Payments is in Test Mode",
35+
comment: "Title for the error screen when WooCommerce Payments is in test mode on a live site"
36+
)
37+
38+
static let message = NSLocalizedString(
39+
"The WooCommerce Payments extension cannot be in test mode for In-Person Payments. "
40+
+ "Please disable test mode.",
41+
comment: "Error message when WooCommerce Payments is in test mode on a live site"
42+
)
43+
44+
static let primaryButton = NSLocalizedString(
45+
"Refresh After Updating",
46+
comment: "Button to reload plugin data after updating the WooCommerce Payments plugin settings"
47+
)
48+
}
49+
50+
struct InPersonPaymentsLiveSiteInTestMode_Previews: PreviewProvider {
51+
static var previews: some View {
52+
InPersonPaymentsLiveSiteInTestMode(onRefresh: {})
53+
}
54+
}

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@
475475
26FE09E124DB8FA000B9BDF5 /* SurveyCoordinatorControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26FE09E024DB8FA000B9BDF5 /* SurveyCoordinatorControllerTests.swift */; };
476476
26FE09E424DCFE5200B9BDF5 /* InAppFeedbackCardViewControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26FE09E324DCFE5200B9BDF5 /* InAppFeedbackCardViewControllerTests.swift */; };
477477
26FF455F24BE49EE00B3B2F4 /* DeprecatedStatsDashboardViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26FF455E24BE49EE00B3B2F4 /* DeprecatedStatsDashboardViewController.swift */; };
478+
310D1B482734919E001D55B4 /* InPersonPaymentsLiveSiteInTestModeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 310D1B472734919E001D55B4 /* InPersonPaymentsLiveSiteInTestModeView.swift */; };
478479
311237EE2714DA240033C44E /* CardPresentModalDisplayMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 311237ED2714DA240033C44E /* CardPresentModalDisplayMessage.swift */; };
479480
311D21E8264AEDB900102316 /* CardPresentModalScanningForReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 311D21E7264AEDB900102316 /* CardPresentModalScanningForReader.swift */; };
480481
311D21ED264AF0E700102316 /* CardReaderSettingsAlerts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 311D21EC264AF0E700102316 /* CardReaderSettingsAlerts.swift */; };
@@ -1936,6 +1937,7 @@
19361937
26FE09E324DCFE5200B9BDF5 /* InAppFeedbackCardViewControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InAppFeedbackCardViewControllerTests.swift; sourceTree = "<group>"; };
19371938
26FF455E24BE49EE00B3B2F4 /* DeprecatedStatsDashboardViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeprecatedStatsDashboardViewController.swift; sourceTree = "<group>"; };
19381939
2719B6FD1E6FE78A76B6AC74 /* Pods-WooCommerceTests.release-alpha.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WooCommerceTests.release-alpha.xcconfig"; path = "../Pods/Target Support Files/Pods-WooCommerceTests/Pods-WooCommerceTests.release-alpha.xcconfig"; sourceTree = "<group>"; };
1940+
310D1B472734919E001D55B4 /* InPersonPaymentsLiveSiteInTestModeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InPersonPaymentsLiveSiteInTestModeView.swift; sourceTree = "<group>"; };
19391941
311237ED2714DA240033C44E /* CardPresentModalDisplayMessage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardPresentModalDisplayMessage.swift; sourceTree = "<group>"; };
19401942
311D21E7264AEDB900102316 /* CardPresentModalScanningForReader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardPresentModalScanningForReader.swift; sourceTree = "<group>"; };
19411943
311D21EC264AF0E700102316 /* CardReaderSettingsAlerts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardReaderSettingsAlerts.swift; sourceTree = "<group>"; };
@@ -6649,6 +6651,7 @@
66496651
D8B4D5ED26C2C26C00F34E94 /* InPersonPaymentsStripeAcountReviewView.swift */,
66506652
D8B4D5F326C30E7C00F34E94 /* InPersonPaymentsStripeRejectedView.swift */,
66516653
E15F163026C5117300D3059B /* InPersonPaymentsNoConnectionView.swift */,
6654+
310D1B472734919E001D55B4 /* InPersonPaymentsLiveSiteInTestModeView.swift */,
66526655
);
66536656
path = "Onboarding Errors";
66546657
sourceTree = "<group>";
@@ -7638,6 +7641,7 @@
76387641
B555530F21B57DE700449E71 /* ApplicationAdapter.swift in Sources */,
76397642
025C00682550DE4700FAC222 /* ProductSKUInputScannerViewController.swift in Sources */,
76407643
456BEFB626D912EC002AC16C /* AuthenticatedWebView.swift in Sources */,
7644+
310D1B482734919E001D55B4 /* InPersonPaymentsLiveSiteInTestModeView.swift in Sources */,
76417645
26F65C9825DEDAF0008FAE29 /* GenerateVariationUseCase.swift in Sources */,
76427646
747AA08B2107CF8D0047A89B /* TracksProvider.swift in Sources */,
76437647
CE1EC8F120B8A408009762BF /* OrderNoteTableViewCell.swift in Sources */,

WooCommerce/WooCommerceTests/ViewRelated/CardPresentPayments/CardPresentPaymentsOnboardingUseCaseTests.swift

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,20 @@ class CardPresentPaymentsOnboardingUseCaseTests: XCTestCase {
9595
XCTAssertEqual(state, .wcpayUnsupportedVersion)
9696
}
9797

98+
func test_onboarding_returns_wcpay_in_test_mode_with_live_stripe_account_when_live_account_in_test_mode() {
99+
// Given
100+
setupCountry(country: .us)
101+
setupPlugin(status: .active, version: .minimumSupportedVersionWithPatch)
102+
setupPaymentGatewayAccount(status: .complete, isLive: true, isInTestMode: true)
103+
104+
// When
105+
let useCase = CardPresentPaymentsOnboardingUseCase(storageManager: storageManager, stores: stores)
106+
let state = useCase.state
107+
108+
// Then
109+
XCTAssertEqual(state, .wcpayInTestModeWithLiveStripeAccount)
110+
}
111+
98112
func test_onboarding_returns_complete_when_plugin_version_has_newer_patch_release() {
99113
// Given
100114
setupCountry(country: .us)
@@ -112,7 +126,7 @@ class CardPresentPaymentsOnboardingUseCaseTests: XCTestCase {
112126
func test_onboarding_returns_complete_when_active() {
113127
// Given
114128
setupCountry(country: .us)
115-
setupPlugin(status: .networkActive, version: .minimumSupportedVersionWithPatch)
129+
setupPlugin(status: .active, version: .minimumSupportedVersionWithPatch)
116130
setupPaymentGatewayAccount(status: .complete)
117131

118132
// When
@@ -386,6 +400,8 @@ private extension CardPresentPaymentsOnboardingUseCaseTests {
386400
status: WCPayAccountStatusEnum,
387401
hasPendingRequirements: Bool = false,
388402
hasOverdueRequirements: Bool = false,
403+
isLive: Bool = false,
404+
isInTestMode: Bool = false,
389405
isCardPresentEligible: Bool = true
390406
) {
391407
let paymentGatewayAccount = PaymentGatewayAccount
@@ -396,7 +412,9 @@ private extension CardPresentPaymentsOnboardingUseCaseTests {
396412
status: status.rawValue,
397413
hasPendingRequirements: hasPendingRequirements,
398414
hasOverdueRequirements: hasOverdueRequirements,
399-
isCardPresentEligible: isCardPresentEligible
415+
isCardPresentEligible: isCardPresentEligible,
416+
isLive: isLive,
417+
isInTestMode: isInTestMode
400418
)
401419
storageManager.insertSamplePaymentGatewayAccount(readOnlyAccount: paymentGatewayAccount)
402420
}

Yosemite/Yosemite/Model/Payments/WCPayAccount+PaymentGatewayAccount.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ public extension WCPayAccount {
1515
defaultCurrency: defaultCurrency,
1616
supportedCurrencies: supportedCurrencies,
1717
country: country,
18-
isCardPresentEligible: isCardPresentEligible
18+
isCardPresentEligible: isCardPresentEligible,
19+
isLive: isLiveAccount,
20+
isInTestMode: isInTestMode
1921
)
2022
}
2123
}

Yosemite/Yosemite/Model/Storage/PaymentGatewayAccount+ReadOnlyConvertible.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ extension Storage.PaymentGatewayAccount: ReadOnlyConvertible {
1919
supportedCurrencies = paymentGatewayAccount.supportedCurrencies
2020
country = paymentGatewayAccount.country
2121
isCardPresentEligible = paymentGatewayAccount.isCardPresentEligible
22+
isLive = paymentGatewayAccount.isLive
23+
isInTestMode = paymentGatewayAccount.isInTestMode
2224
}
2325

2426
/// Returns a ReadOnly version for Yosemite.
@@ -36,6 +38,8 @@ extension Storage.PaymentGatewayAccount: ReadOnlyConvertible {
3638
defaultCurrency: defaultCurrency,
3739
supportedCurrencies: supportedCurrencies,
3840
country: country,
39-
isCardPresentEligible: isCardPresentEligible)
41+
isCardPresentEligible: isCardPresentEligible,
42+
isLive: isLive,
43+
isInTestMode: isInTestMode)
4044
}
4145
}

0 commit comments

Comments
 (0)