Skip to content

Commit

Permalink
Use a different plugin URL for WooPayments and Stripe
Browse files Browse the repository at this point in the history
  • Loading branch information
staskus committed Jan 23, 2025
1 parent 041e882 commit 69a793a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
12 changes: 8 additions & 4 deletions WooCommerce/Classes/Extensions/Site+URL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ extension Site {
}

/// Returns the plugin URL from wp-admin that handles pending tasks or requirements during onboarding.
/// Both WCPay and Stripe use the same URL.
/// Payments Connect page was recommended by the web team over Payments Overview page in pdfdoF-5Bo-p2#comment-6655
///
func cardPresentPluginHasPendingTasksURL() -> String {
return adminURL + "admin.php?page=wc-admin&path=%2Fpayments%2Fconnect"
func cardPresentPluginHasPendingTasksURL(plugin: CardPresentPaymentsPlugin) -> String {
switch plugin {
case .wcPay:
/// Payments Connect page was recommended by the web team over Payments Overview page in pdfdoF-5Bo-p2#comment-6655
return adminURL + "admin.php?page=wc-admin&path=%2Fpayments%2Fconnect"
case .stripe:
return pluginSettingsSectionURL(from: .stripe) + "&panel=settings"
}
}

/// Returns the WooCommerce admin URL, or attempts to construct it from the site URL.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ struct CardPresentPaymentsOnboardingView: View {
viewModel.refresh)
case .pluginSetupNotCompleted(let plugin):
InPersonPaymentsPluginNotSetup(plugin: plugin, analyticReason: viewModel.state.reasonForAnalytics, onRefresh: viewModel.refresh)
case .stripeAccountOverdueRequirement:
case .stripeAccountOverdueRequirement(let plugin):
InPersonPaymentsStripeAccountOverdue(analyticReason: viewModel.state.reasonForAnalytics,
onRefresh: viewModel.refresh)
onRefresh: viewModel.refresh,
plugin: plugin)
case .stripeAccountPendingRequirement(_, let deadline):
InPersonPaymentsStripeAccountPending(
deadline: deadline,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct InPersonPaymentsPluginNotSetup: View {
}

private var setupURL: URL? {
guard let pluginSectionURL = ServiceLocator.stores.sessionManager.defaultSite?.cardPresentPluginHasPendingTasksURL() else {
guard let pluginSectionURL = ServiceLocator.stores.sessionManager.defaultSite?.cardPresentPluginHasPendingTasksURL(plugin: plugin) else {
return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import enum Yosemite.CardPresentPaymentsPlugin
struct InPersonPaymentsStripeAccountOverdue: View {
let analyticReason: String
let onRefresh: () -> Void
let plugin: CardPresentPaymentsPlugin
@State private var presentedSetupURL: URL? = nil

private let plugin: CardPresentPaymentsPlugin = .stripe

var body: some View {
InPersonPaymentsOnboardingError(
Expand Down Expand Up @@ -36,7 +36,7 @@ struct InPersonPaymentsStripeAccountOverdue: View {
}

private var setupURL: URL? {
guard let pluginSectionURL = ServiceLocator.stores.sessionManager.defaultSite?.cardPresentPluginHasPendingTasksURL() else {
guard let pluginSectionURL = ServiceLocator.stores.sessionManager.defaultSite?.cardPresentPluginHasPendingTasksURL(plugin: plugin) else {
return nil
}

Expand Down Expand Up @@ -77,6 +77,6 @@ private enum Localization {

struct InPersonPaymentsStripeAccountOverdue_Previews: PreviewProvider {
static var previews: some View {
InPersonPaymentsStripeAccountOverdue(analyticReason: "", onRefresh: { })
InPersonPaymentsStripeAccountOverdue(analyticReason: "", onRefresh: { }, plugin: .stripe)
}
}
14 changes: 14 additions & 0 deletions WooCommerce/WooCommerceTests/Extensions/SitePluginsURLTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,18 @@ final class Site_PluginsURLTests: XCTestCase {
// Then
XCTAssertEqual(site.pluginSettingsSectionURL(from: .stripe), expectedURL)
}

func test_cardPresentPluginHasPendingTasksURL_when_plugin_is_wcpay_then_returns_correct_URL() {
let expectedURL = adminURL + "admin.php?page=wc-admin&path=%2Fpayments%2Fconnect"

// Then
XCTAssertEqual(site.cardPresentPluginHasPendingTasksURL(plugin: .wcPay), expectedURL)
}

func test_cardPresentPluginHasPendingTasksURL_when_plugin_is_stripe_then_returns_correct_URL() {
let expectedURL = adminURL + "admin.php?page=wc-settings&tab=checkout&section=stripe&panel=settings"

// Then
XCTAssertEqual(site.cardPresentPluginHasPendingTasksURL(plugin: .stripe), expectedURL)
}
}

0 comments on commit 69a793a

Please sign in to comment.