11import Foundation
22import Combine
33import Yosemite
4- import MessageUI
54import 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
153163private 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