Skip to content

Commit 6242f86

Browse files
authored
Merge pull request #6594 from woocommerce/issue/6087-use-correct-payment-link
2 parents 0447aba + 1b6de8e commit 6242f86

File tree

7 files changed

+21
-154
lines changed

7 files changed

+21
-154
lines changed

WooCommerce/Classes/Tools/PaymentLinkBuilder.swift

Lines changed: 0 additions & 27 deletions
This file was deleted.

WooCommerce/Classes/ViewRelated/Orders/Simple Payments/Method/SimplePaymentsMethod.swift

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,23 @@ struct SimplePaymentsMethod: View {
4040
Divider()
4141

4242
Group {
43-
MethodRow(icon: .priceImage, title: Localization.cash, showBetaAnnotation: false) {
43+
MethodRow(icon: .priceImage, title: Localization.cash) {
4444
showingCashAlert = true
4545
viewModel.trackCollectByCash()
4646
}
4747

4848
if viewModel.showPayWithCardRow {
4949
Divider()
5050

51-
MethodRow(icon: .creditCardImage, title: Localization.card, showBetaAnnotation: false) {
51+
MethodRow(icon: .creditCardImage, title: Localization.card) {
5252
viewModel.collectPayment(on: rootViewController, onSuccess: dismiss)
5353
}
5454
}
5555

5656
if viewModel.showPaymentLinkRow {
5757
Divider()
5858

59-
MethodRow(icon: .linkImage, title: Localization.link, showBetaAnnotation: true) {
59+
MethodRow(icon: .linkImage, title: Localization.link) {
6060
sharingPaymentLink = true
6161
viewModel.trackCollectByPaymentLink()
6262
}
@@ -114,10 +114,6 @@ private struct MethodRow: View {
114114
///
115115
let title: String
116116

117-
/// Defines if the beta tag should be shown.
118-
///
119-
let showBetaAnnotation: Bool
120-
121117
/// Action when the row is selected
122118
///
123119
let action: () -> ()
@@ -141,14 +137,9 @@ private struct MethodRow: View {
141137
.foregroundColor(Color(.systemGray))
142138
.accessibility(hidden: true)
143139

144-
HStack {
145-
Text(title)
146-
.bodyStyle()
147-
148-
BetaTag()
149-
.renderedIf(showBetaAnnotation)
150-
}
151-
.frame(maxWidth: .infinity, alignment: .leading)
140+
Text(title)
141+
.bodyStyle()
142+
.frame(maxWidth: .infinity, alignment: .leading)
152143

153144
DisclosureIndicator()
154145
}
@@ -158,30 +149,6 @@ private struct MethodRow: View {
158149
}
159150
}
160151

161-
/// Represents a Beta annotation tag
162-
///
163-
private struct BetaTag: View {
164-
/// Constants
165-
///
166-
enum Localization {
167-
static let beta = NSLocalizedString("Beta", comment: "Beta annotation for sharing a payment link")
168-
}
169-
170-
enum Layout {
171-
static let padding: CGFloat = 5
172-
static let cornerRadius: CGFloat = 7
173-
}
174-
175-
var body: some View {
176-
Text(Localization.beta)
177-
.font(.caption)
178-
.foregroundColor(Color(.textInverted))
179-
.padding(Layout.padding)
180-
.background(Color(.accent))
181-
.cornerRadius(Layout.cornerRadius)
182-
}
183-
}
184-
185152
// MARK: Constants
186153
private extension SimplePaymentsMethod {
187154
enum Localization {

WooCommerce/Classes/ViewRelated/Orders/Simple Payments/Method/SimplePaymentsMethodsViewModel.swift

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ final class SimplePaymentsMethodsViewModel: ObservableObject {
2525

2626
/// Stores the payment link for the order.
2727
///
28-
@Published private(set) var paymentLink: URL?
28+
let paymentLink: URL?
2929

3030
/// Defines if the view should be disabled to prevent any further action.
3131
/// Useful to prevent any double tap while a network operation is being performed.
@@ -99,7 +99,7 @@ final class SimplePaymentsMethodsViewModel: ObservableObject {
9999

100100
init(siteID: Int64 = 0,
101101
orderID: Int64 = 0,
102-
orderKey: String = "",
102+
paymentLink: URL? = nil,
103103
formattedTotal: String,
104104
presentNoticeSubject: PassthroughSubject<SimplePaymentsNotice, Never> = PassthroughSubject(),
105105
cppStoreStateObserver: CardPresentPaymentsOnboardingUseCaseProtocol = CardPresentPaymentsOnboardingUseCase(),
@@ -108,6 +108,7 @@ final class SimplePaymentsMethodsViewModel: ObservableObject {
108108
analytics: Analytics = ServiceLocator.analytics) {
109109
self.siteID = siteID
110110
self.orderID = orderID
111+
self.paymentLink = paymentLink
111112
self.formattedTotal = formattedTotal
112113
self.presentNoticeSubject = presentNoticeSubject
113114
self.cppStoreStateObserver = cppStoreStateObserver
@@ -117,7 +118,6 @@ final class SimplePaymentsMethodsViewModel: ObservableObject {
117118
self.title = String(format: Localization.title, formattedTotal)
118119

119120
bindStoreCPPState()
120-
fetchPaymentLink(orderKey: orderKey)
121121
}
122122

123123
/// Creates the info text when the merchant selects the cash payment method.
@@ -226,29 +226,6 @@ private extension SimplePaymentsMethodsViewModel {
226226
cppStoreStateObserver.refresh()
227227
}
228228

229-
230-
/// Fetches and builds the order payment link based on the store settings.
231-
///
232-
func fetchPaymentLink(orderKey: String) {
233-
guard let storeURL = stores.sessionManager.defaultSite?.url else {
234-
return DDLogError("⛔️ Couldn't find a valid store URL")
235-
}
236-
237-
let action = SettingAction.getPaymentsPagePath(siteID: siteID) { [weak self] result in
238-
guard let self = self else { return }
239-
240-
switch result {
241-
case .success(let paymentPagePath):
242-
let linkBuilder = PaymentLinkBuilder(host: storeURL, orderID: self.orderID, orderKey: orderKey, paymentPagePath: paymentPagePath)
243-
self.paymentLink = URL(string: linkBuilder.build())
244-
245-
case .failure(let error):
246-
DDLogError("⛔️ Error retrieving the payments page path: \(error.localizedDescription)")
247-
}
248-
}
249-
stores.dispatch(action)
250-
}
251-
252229
/// Tracks the `simplePaymentsFlowCompleted` event.
253230
///
254231
func trackFlowCompleted(method: WooAnalyticsEvent.SimplePayments.PaymentMethod) {

WooCommerce/Classes/ViewRelated/Orders/Simple Payments/Summary/SimplePaymentsSummaryViewModel.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,10 @@ final class SimplePaymentsSummaryViewModel: ObservableObject {
114114
///
115115
private let orderID: Int64
116116

117-
/// Order Key. Needed to generate the payment link in `PaymentMethodViewModel`
117+
/// Order payment URL.
118+
/// Optional because older stores `(< 6.4)` don't provide this information.
118119
///
119-
private let orderKey: String
120+
private let paymentLink: URL?
120121

121122
/// Fee ID to update.
122123
///
@@ -144,15 +145,15 @@ final class SimplePaymentsSummaryViewModel: ObservableObject {
144145
noteContent: String? = nil,
145146
siteID: Int64 = 0,
146147
orderID: Int64 = 0,
147-
orderKey: String = "",
148+
paymentLink: URL? = nil,
148149
feeID: Int64 = 0,
149150
presentNoticeSubject: PassthroughSubject<SimplePaymentsNotice, Never> = PassthroughSubject(),
150151
currencyFormatter: CurrencyFormatter = CurrencyFormatter(currencySettings: ServiceLocator.currencySettings),
151152
stores: StoresManager = ServiceLocator.stores,
152153
analytics: Analytics = ServiceLocator.analytics) {
153154
self.siteID = siteID
154155
self.orderID = orderID
155-
self.orderKey = orderKey
156+
self.paymentLink = paymentLink
156157
self.feeID = feeID
157158
self.presentNoticeSubject = presentNoticeSubject
158159
self.currencyFormatter = currencyFormatter
@@ -194,7 +195,7 @@ final class SimplePaymentsSummaryViewModel: ObservableObject {
194195
taxLines: taxLines,
195196
siteID: order.siteID,
196197
orderID: order.orderID,
197-
orderKey: order.orderKey,
198+
paymentLink: order.paymentURL,
198199
feeID: order.fees.first?.feeID ?? 0,
199200
presentNoticeSubject: presentNoticeSubject,
200201
currencyFormatter: currencyFormatter,
@@ -249,7 +250,7 @@ final class SimplePaymentsSummaryViewModel: ObservableObject {
249250
func createMethodsViewModel() -> SimplePaymentsMethodsViewModel {
250251
SimplePaymentsMethodsViewModel(siteID: siteID,
251252
orderID: orderID,
252-
orderKey: orderKey,
253+
paymentLink: paymentLink,
253254
formattedTotal: total,
254255
presentNoticeSubject: presentNoticeSubject,
255256
stores: stores)

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,6 @@
496496
2667BFE92530ECE4008099D4 /* RefundProductsTotalViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2667BFE82530ECE4008099D4 /* RefundProductsTotalViewModelTests.swift */; };
497497
2667BFEB2535FF09008099D4 /* RefundShippingCalculationUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2667BFEA2535FF09008099D4 /* RefundShippingCalculationUseCase.swift */; };
498498
2667BFED25360681008099D4 /* RefundShippingCalculationUseCaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2667BFEC25360681008099D4 /* RefundShippingCalculationUseCaseTests.swift */; };
499-
267066052773DAE6008E1F68 /* PaymentLinkBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 267066042773DAE6008E1F68 /* PaymentLinkBuilder.swift */; };
500-
267066072773DC81008E1F68 /* PaymentLinkBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 267066062773DC81008E1F68 /* PaymentLinkBuilderTests.swift */; };
501499
26771A14256FFA8700EE030E /* IssueRefundCoordinatingController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26771A13256FFA8700EE030E /* IssueRefundCoordinatingController.swift */; };
502500
2678897C270E6E8B00BD249E /* SimplePaymentsAmount.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2678897B270E6E8B00BD249E /* SimplePaymentsAmount.swift */; };
503501
2687165524D21BC80042F6AE /* SurveySubmittedViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2687165324D21BC80042F6AE /* SurveySubmittedViewController.swift */; };
@@ -2192,8 +2190,6 @@
21922190
2667BFE82530ECE4008099D4 /* RefundProductsTotalViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RefundProductsTotalViewModelTests.swift; sourceTree = "<group>"; };
21932191
2667BFEA2535FF09008099D4 /* RefundShippingCalculationUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RefundShippingCalculationUseCase.swift; sourceTree = "<group>"; };
21942192
2667BFEC25360681008099D4 /* RefundShippingCalculationUseCaseTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RefundShippingCalculationUseCaseTests.swift; sourceTree = "<group>"; };
2195-
267066042773DAE6008E1F68 /* PaymentLinkBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentLinkBuilder.swift; sourceTree = "<group>"; };
2196-
267066062773DC81008E1F68 /* PaymentLinkBuilderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentLinkBuilderTests.swift; sourceTree = "<group>"; };
21972193
26771A13256FFA8700EE030E /* IssueRefundCoordinatingController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IssueRefundCoordinatingController.swift; sourceTree = "<group>"; };
21982194
2678897B270E6E8B00BD249E /* SimplePaymentsAmount.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimplePaymentsAmount.swift; sourceTree = "<group>"; };
21992195
267CFE1824435A5500AF3A13 /* ProductCategoryViewModelBuilderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductCategoryViewModelBuilderTests.swift; sourceTree = "<group>"; };
@@ -5951,7 +5947,6 @@
59515947
0211252D25773FB00075AD2A /* MockAggregateOrderItem.swift */,
59525948
DE68B84226FAF17A00C86CFB /* DefaultConnectivityObserver.swift */,
59535949
4590B651261C8D1E00A6FCE0 /* WeightFormatterTests.swift */,
5954-
267066062773DC81008E1F68 /* PaymentLinkBuilderTests.swift */,
59555950
);
59565951
path = Tools;
59575952
sourceTree = "<group>";
@@ -6049,7 +6044,6 @@
60496044
45D685FD23D0FB25005F87D0 /* Throttler.swift */,
60506045
262C921E26EEF8B100011F92 /* Binding.swift */,
60516046
31579027273EE2B1008CA3AF /* VersionHelpers.swift */,
6052-
267066042773DAE6008E1F68 /* PaymentLinkBuilder.swift */,
60536047
174CA86D27DBFD2D00126524 /* ShareAppTextItemActivitySource.swift */,
60546048
);
60556049
path = Tools;
@@ -8860,7 +8854,6 @@
88608854
025B174A237AA49D00C780B4 /* Product+ProductForm.swift in Sources */,
88618855
B57C744720F55BC800EEFC87 /* UIView+Helpers.swift in Sources */,
88628856
45912FE32526642200982948 /* ProductFormViewController+Helpers.swift in Sources */,
8863-
267066052773DAE6008E1F68 /* PaymentLinkBuilder.swift in Sources */,
88648857
B55D4C0620B6027200D7A50F /* AuthenticationManager.swift in Sources */,
88658858
451A04F02386F7B500E368C9 /* ProductImageCollectionViewCell.swift in Sources */,
88668859
AEACCB6D2785FF4A000D01F0 /* NavigationRow.swift in Sources */,
@@ -9742,7 +9735,6 @@
97429735
DE001323279A793A00EB0350 /* CouponWooTests.swift in Sources */,
97439736
45B98E1F25DECC1C00A1232B /* ShippingLabelAddressFormViewModelTests.swift in Sources */,
97449737
02BC5AA424D27F8900C43326 /* ProductVariationFormViewModel+ObservablesTests.swift in Sources */,
9745-
267066072773DC81008E1F68 /* PaymentLinkBuilderTests.swift in Sources */,
97469738
CCCC5B1326CC2B9F0034FB63 /* ShippingLabelCustomPackageFormViewModelTests.swift in Sources */,
97479739
D41C9F3126D9A43200993558 /* WhatsNewViewModelTests.swift in Sources */,
97489740
02A275BE23FE57DC005C560F /* ProductUIImageLoaderTests.swift in Sources */,

WooCommerce/WooCommerceTests/Tools/PaymentLinkBuilderTests.swift

Lines changed: 0 additions & 19 deletions
This file was deleted.

WooCommerce/WooCommerceTests/ViewRelated/Orders/Simple Payments/SimplePaymentsMethodsViewModelTests.swift

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -325,43 +325,19 @@ final class SimplePaymentsMethodsViewModelTests: XCTestCase {
325325
XCTAssertTrue(viewModel.showPayWithCardRow)
326326
}
327327

328-
func test_paymentLinkRow_is_hidden_if_payment_path_is_not_available() {
328+
func test_paymentLinkRow_is_hidden_if_payment_link_is_not_available() {
329329
// Given
330-
let stores = MockStoresManager(sessionManager: .testingInstance)
331-
stores.whenReceivingAction(ofType: SettingAction.self) { action in
332-
switch action {
333-
case let .getPaymentsPagePath(_, onCompletion):
334-
onCompletion(.failure(.paymentsPageNotFound))
335-
default:
336-
XCTFail("Unexpected action: \(action)")
337-
}
338-
}
339-
340-
// When
341-
let viewModel = SimplePaymentsMethodsViewModel(formattedTotal: "$12.00", stores: stores)
330+
let viewModel = SimplePaymentsMethodsViewModel(paymentLink: nil, formattedTotal: "$12.00")
342331

343332
// Then
344333
XCTAssertFalse(viewModel.showPaymentLinkRow)
345334
XCTAssertNil(viewModel.paymentLink)
346335
}
347336

348-
func test_paymentLinkRow_is_shown_if_payment_path_is_available() {
337+
func test_paymentLinkRow_is_shown_if_payment_link_is_available() {
349338
// Given
350-
let session = SessionManager.testingInstance
351-
session.defaultSite = .fake().copy(url: "https://www.test-store.com")
352-
353-
let stores = MockStoresManager(sessionManager: session)
354-
stores.whenReceivingAction(ofType: SettingAction.self) { action in
355-
switch action {
356-
case let .getPaymentsPagePath(_, onCompletion):
357-
onCompletion(.success("order-pay"))
358-
default:
359-
XCTFail("Unexpected action: \(action)")
360-
}
361-
}
362-
363-
// When
364-
let viewModel = SimplePaymentsMethodsViewModel(formattedTotal: "$12.00", stores: stores)
339+
let paymentURL = URL(string: "http://www.automattic.com")
340+
let viewModel = SimplePaymentsMethodsViewModel(paymentLink: paymentURL, formattedTotal: "$12.00")
365341

366342
// Then
367343
XCTAssertTrue(viewModel.showPaymentLinkRow)

0 commit comments

Comments
 (0)