Skip to content

Commit 085bf11

Browse files
committed
Separate refund details for submission.
1 parent 3a63cab commit 085bf11

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

WooCommerce/Classes/ViewRelated/Orders/Order Details/Issue Refunds/RefundConfirmationViewModel.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,15 @@ final class RefundConfirmationViewModel {
9999

100100
// Submits refund.
101101
let submissionUseCase = RefundSubmissionUseCase(siteID: details.order.siteID,
102-
details: details,
102+
details: .init(order: details.order,
103+
charge: details.charge,
104+
amount: details.amount),
103105
rootViewController: rootViewController,
104106
currencyFormatter: currencyFormatter,
105107
stores: actionProcessor,
106108
analytics: analytics)
107109
self.submissionUseCase = submissionUseCase
108110
submissionUseCase.submitRefund(refund,
109-
details: details,
110111
showInProgressUI: showInProgressUI,
111112
onCompletion: { [weak self] result in
112113
guard let self = self else { return }

WooCommerce/Classes/ViewRelated/Orders/Refund/RefundSubmissionUseCase.swift

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import Foundation
22
import Combine
33
import Yosemite
4-
import MessageUI
54
import protocol Storage.StorageManagerType
65

76
/// Protocol to abstract the `CollectOrderPaymentUseCase`.
@@ -11,15 +10,13 @@ protocol RefundSubmissionProtocol {
1110
/// Starts the refund submission flow.
1211
///
1312
/// - Parameter refund: the refund to submit.
14-
/// - Parameter details: details about the refund.
1513
/// - Parameter showInProgressUI: called when the in-progress UI should be shown during refund submission.
1614
/// - Parameter onCompletion: called when the refund completes.
17-
func submitRefund(_ refund: Refund, details: RefundDetails, showInProgressUI: @escaping (() -> Void), onCompletion: @escaping (Result<Void, Error>) -> Void)
15+
func submitRefund(_ refund: Refund,
16+
showInProgressUI: @escaping (() -> Void),
17+
onCompletion: @escaping (Result<Void, Error>) -> Void)
1818
}
1919

20-
// TODO: rename or create a new struct with necessary info
21-
typealias RefundDetails = RefundConfirmationViewModel.Details
22-
2320
/// Use case to submit a refund for an order.
2421
/// If in-person refund is required for the payment method (e.g. Interac in Canada), orchestrates reader connection, refund, UI alerts,
2522
/// submit refund to the site, and analytics.
@@ -29,7 +26,7 @@ final class RefundSubmissionUseCase: NSObject, RefundSubmissionProtocol {
2926
private let siteID: Int64
3027

3128
/// Refund details.
32-
private let details: RefundDetails
29+
private let details: Details
3330

3431
/// Order of the refund.
3532
private var order: Order {
@@ -87,7 +84,7 @@ final class RefundSubmissionUseCase: NSObject, RefundSubmissionProtocol {
8784
}
8885

8986
init(siteID: Int64,
90-
details: RefundDetails,
87+
details: Details,
9188
rootViewController: UIViewController,
9289
currencyFormatter: CurrencyFormatter,
9390
currencySettings: CurrencySettings = ServiceLocator.currencySettings,
@@ -120,11 +117,9 @@ final class RefundSubmissionUseCase: NSObject, RefundSubmissionProtocol {
120117
///
121118
/// - Parameters:
122119
/// - refund: the refund to submit.
123-
/// - details: details about the refund.
124120
/// - showInProgressUI: called when the in-progress UI should be shown during refund submission.
125121
/// - onCompletion: called when the refund completes.
126122
func submitRefund(_ refund: Refund,
127-
details: RefundDetails,
128123
showInProgressUI: @escaping (() -> Void),
129124
onCompletion: @escaping (Result<Void, Error>) -> Void) {
130125
if let charge = details.charge, shouldRefundWithCardReader(details: details) {
@@ -149,12 +144,27 @@ final class RefundSubmissionUseCase: NSObject, RefundSubmissionProtocol {
149144
}
150145
}
151146

147+
// MARK: Refund Details
148+
extension RefundSubmissionUseCase {
149+
/// Details about a refund for submission.
150+
struct Details {
151+
/// Order to refund.
152+
let order: Order
153+
154+
/// Charge of original payment.
155+
let charge: WCPayCharge?
156+
157+
/// Total amount to refund.
158+
let amount: String
159+
}
160+
}
161+
152162
// MARK: Private functions
153163
private extension RefundSubmissionUseCase {
154164
/// Determines if in-person refund is required. Currently, only Interac payment method requires in-person refunds.
155165
/// - Parameter details: details about the refund.
156166
/// - Returns: whether the refund should be in-person with a card reader.
157-
func shouldRefundWithCardReader(details: RefundDetails) -> Bool {
167+
func shouldRefundWithCardReader(details: Details) -> Bool {
158168
let isInterac: Bool = {
159169
switch details.charge?.paymentMethodDetails {
160170
case .some(.interacPresent):

0 commit comments

Comments
 (0)