Skip to content

Commit 1d6d5bd

Browse files
committed
Move receipt printing to shared function
1 parent f5b2d02 commit 1d6d5bd

File tree

6 files changed

+64
-29
lines changed

6 files changed

+64
-29
lines changed

WooCommerce/Classes/ViewModels/CardPresentPayments/PaymentCaptureOrchestrator.swift

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,6 @@ final class PaymentCaptureOrchestrator {
8181
ServiceLocator.stores.dispatch(action)
8282
}
8383

84-
func printReceipt(for order: Order, params: CardPresentReceiptParameters) {
85-
let action = ReceiptAction.print(order: order, parameters: params) { (result) in
86-
switch result {
87-
case .success:
88-
ServiceLocator.analytics.track(.receiptPrintSuccess)
89-
case .cancel:
90-
ServiceLocator.analytics.track(.receiptPrintCanceled)
91-
case .failure(let error):
92-
ServiceLocator.analytics.track(.receiptPrintFailed, withError: error)
93-
}
94-
}
95-
96-
ServiceLocator.stores.dispatch(action)
97-
}
98-
9984
func emailReceipt(for order: Order, params: CardPresentReceiptParameters, onContent: @escaping (String) -> Void) {
10085
let action = ReceiptAction.generateContent(order: order, parameters: params) { emailContent in
10186
onContent(emailContent)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import Foundation
2+
import Yosemite
3+
4+
struct ReceiptPrintingCoordinator {
5+
static func printReceipt(for order: Order, params: CardPresentReceiptParameters) {
6+
ServiceLocator.analytics.track(.receiptPrintTapped)
7+
8+
let action = ReceiptAction.print(order: order, parameters: params) { (result) in
9+
switch result {
10+
case .success:
11+
ServiceLocator.analytics.track(.receiptPrintSuccess)
12+
case .cancel:
13+
ServiceLocator.analytics.track(.receiptPrintCanceled)
14+
case .failure(let error):
15+
ServiceLocator.analytics.track(.receiptPrintFailed, withError: error)
16+
}
17+
}
18+
19+
ServiceLocator.stores.dispatch(action)
20+
}
21+
}

WooCommerce/Classes/ViewModels/CardPresentPayments/ReceiptViewModel.swift

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,6 @@ final class ReceiptViewModel {
2929

3030
/// Prints the receipt
3131
func printReceipt() {
32-
ServiceLocator.analytics.track(.receiptPrintTapped)
33-
let action = ReceiptAction.print(order: order, parameters: receipt) { (result) in
34-
switch result {
35-
case .success:
36-
ServiceLocator.analytics.track(.receiptPrintSuccess)
37-
case .cancel:
38-
ServiceLocator.analytics.track(.receiptPrintCanceled)
39-
case .failure(let error):
40-
ServiceLocator.analytics.track(.receiptPrintFailed, withError: error)
41-
}
42-
}
43-
ServiceLocator.stores.dispatch(action)
32+
ReceiptPrintingCoordinator.printReceipt(for: order, params: receipt)
4433
}
4534
}

WooCommerce/Classes/ViewModels/Order Details/OrderDetailsViewModel.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,7 @@ extension OrderDetailsViewModel {
550550
}
551551

552552
func printReceipt(params: CardPresentReceiptParameters) {
553-
ServiceLocator.analytics.track(.receiptPrintTapped)
554-
paymentOrchestrator.printReceipt(for: order, params: params)
553+
ReceiptPrintingCoordinator.printReceipt(for: order, params: params)
555554
}
556555

557556
func emailReceipt(params: CardPresentReceiptParameters, onContent: @escaping (String) -> Void) {

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,8 @@
372372
02F6800325807C9B00C3BAD2 /* ShippingLabelPaperSizeOptionListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02F6800225807C9B00C3BAD2 /* ShippingLabelPaperSizeOptionListView.swift */; };
373373
02F6800925807CD300C3BAD2 /* GridStackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02F6800825807CD300C3BAD2 /* GridStackView.swift */; };
374374
02FE89C7231FAA4100E85EF8 /* MainTabBarControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02FE89C6231FAA4100E85EF8 /* MainTabBarControllerTests.swift */; };
375+
03AA165E2719B7EF005CCB7B /* ReceiptPrintingCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03AA165D2719B7EF005CCB7B /* ReceiptPrintingCoordinator.swift */; };
376+
03AA16602719B83D005CCB7B /* RecieptPrintingCoordinatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03AA165F2719B83D005CCB7B /* RecieptPrintingCoordinatorTests.swift */; };
375377
247CE89C2583402A00F9D9D1 /* Embassy in Frameworks */ = {isa = PBXBuildFile; productRef = 247CE89B2583402A00F9D9D1 /* Embassy */; };
376378
247CE8A6258340E600F9D9D1 /* ScreenshotImages.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 247CE8A5258340E600F9D9D1 /* ScreenshotImages.xcassets */; };
377379
24C5AC7625A53021008FD769 /* Embassy in Frameworks */ = {isa = PBXBuildFile; productRef = 247CE89B2583402A00F9D9D1 /* Embassy */; };
@@ -1807,6 +1809,8 @@
18071809
02F6800225807C9B00C3BAD2 /* ShippingLabelPaperSizeOptionListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShippingLabelPaperSizeOptionListView.swift; sourceTree = "<group>"; };
18081810
02F6800825807CD300C3BAD2 /* GridStackView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GridStackView.swift; sourceTree = "<group>"; };
18091811
02FE89C6231FAA4100E85EF8 /* MainTabBarControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTabBarControllerTests.swift; sourceTree = "<group>"; };
1812+
03AA165D2719B7EF005CCB7B /* ReceiptPrintingCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReceiptPrintingCoordinator.swift; sourceTree = "<group>"; };
1813+
03AA165F2719B83D005CCB7B /* RecieptPrintingCoordinatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecieptPrintingCoordinatorTests.swift; sourceTree = "<group>"; };
18101814
247CE8A5258340E600F9D9D1 /* ScreenshotImages.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = ScreenshotImages.xcassets; sourceTree = "<group>"; };
18111815
24C579D124F476300076E1B4 /* Woo-Alpha.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "Woo-Alpha.entitlements"; sourceTree = "<group>"; };
18121816
24F98C4F2502AEE200F49B68 /* EventLogging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventLogging.swift; sourceTree = "<group>"; };
@@ -6259,6 +6263,7 @@
62596263
E12AF69A26BA8B2000C371C1 /* CardPresentPaymentsOnboardingUseCaseTests.swift */,
62606264
D810F8F72639EDE900437C67 /* CardPresentPaymentsModalViewControllerTests.swift */,
62616265
31E906A226CC91A70099A985 /* CardReaderConnectionControllerTests.swift */,
6266+
03AA165F2719B83D005CCB7B /* RecieptPrintingCoordinatorTests.swift */,
62626267
);
62636268
path = CardPresentPayments;
62646269
sourceTree = "<group>";
@@ -6356,6 +6361,7 @@
63566361
31AD0B1026E9575F000B6391 /* CardPresentModalConnectingFailed.swift */,
63576362
D8EE9697264D3CCB0033B2F9 /* ReceiptViewModel.swift */,
63586363
D8752EF6265E60F4008ACC80 /* PaymentCaptureCelebration.swift */,
6364+
03AA165D2719B7EF005CCB7B /* ReceiptPrintingCoordinator.swift */,
63596365
);
63606366
path = CardPresentPayments;
63616367
sourceTree = "<group>";
@@ -7716,6 +7722,7 @@
77167722
E12AF69926BA8ADC00C371C1 /* CardPresentPaymentsOnboardingUseCase.swift in Sources */,
77177723
45C11B7C2508E156006C2089 /* SelectedSiteSettings.swift in Sources */,
77187724
B5A56BF3219F46470065A902 /* UIButton+Animations.swift in Sources */,
7725+
03AA165E2719B7EF005CCB7B /* ReceiptPrintingCoordinator.swift in Sources */,
77197726
B54FBE552111F70700390F57 /* ResultsController+UIKit.swift in Sources */,
77207727
CE2409F1215D12D30091F887 /* WooNavigationController.swift in Sources */,
77217728
0294F8AB25E8A12C005B537A /* WooTabNavigationController.swift in Sources */,
@@ -8100,6 +8107,7 @@
81008107
26FE09E124DB8FA000B9BDF5 /* SurveyCoordinatorControllerTests.swift in Sources */,
81018108
0277AEAB256CAA5300F45C4A /* MockShippingLabelAddress.swift in Sources */,
81028109
D83F593D225B4B5000626E75 /* ManualTrackingViewControllerTests.swift in Sources */,
8110+
03AA16602719B83D005CCB7B /* RecieptPrintingCoordinatorTests.swift in Sources */,
81038111
CEEC9B6621E7C5200055EEF0 /* AppRatingManagerTests.swift in Sources */,
81048112
263EB409242C58EA00F3A15F /* ProductFormActionsFactoryTests.swift in Sources */,
81058113
02BA23C022EE9DAF009539E7 /* AsyncDictionaryTests.swift in Sources */,
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// RecieptPrintingCoordinatorTests.swift
3+
// WooCommerceTests
4+
//
5+
// Created by Josh Heald on 15/10/2021.
6+
// Copyright © 2021 Automattic. All rights reserved.
7+
//
8+
9+
import XCTest
10+
11+
class RecieptPrintingCoordinatorTests: XCTestCase {
12+
13+
override func setUpWithError() throws {
14+
// Put setup code here. This method is called before the invocation of each test method in the class.
15+
}
16+
17+
override func tearDownWithError() throws {
18+
// Put teardown code here. This method is called after the invocation of each test method in the class.
19+
}
20+
21+
func testExample() throws {
22+
// This is an example of a functional test case.
23+
// Use XCTAssert and related functions to verify your tests produce the correct results.
24+
}
25+
26+
func testPerformanceExample() throws {
27+
// This is an example of a performance test case.
28+
self.measure {
29+
// Put the code you want to measure the time of here.
30+
}
31+
}
32+
33+
}

0 commit comments

Comments
 (0)