Skip to content

Commit 8375e1e

Browse files
committed
Update simple payments order with merchant details
1 parent 268a11c commit 8375e1e

File tree

2 files changed

+55
-5
lines changed

2 files changed

+55
-5
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,9 @@ private struct TakePaymentSection: View {
227227
Divider()
228228

229229
Button(SimplePaymentsSummary.Localization.takePayment(total: viewModel.total), action: {
230-
print("Take payment pressed")
230+
viewModel.updateOrder()
231231
})
232-
.buttonStyle(PrimaryButtonStyle())
232+
.buttonStyle(PrimaryLoadingButtonStyle(isLoading: viewModel.showLoadingIndicator))
233233
.padding()
234234

235235
}

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

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ final class SimplePaymentsSummaryViewModel: ObservableObject {
2525
///
2626
@Published var enableTaxes: Bool = false
2727

28+
/// Defines if a loading indicator should be shown.
29+
///
30+
@Published private(set) var showLoadingIndicator = false
31+
2832
/// Total to charge. With or without taxes.
2933
///
3034
var total: String {
@@ -45,6 +49,22 @@ final class SimplePaymentsSummaryViewModel: ObservableObject {
4549
///
4650
private let currencyFormatter: CurrencyFormatter
4751

52+
/// Store ID
53+
///
54+
private let siteID: Int64
55+
56+
/// Order ID to update.
57+
///
58+
private let orderID: Int64
59+
60+
/// Fee ID to update.
61+
///
62+
private let feeID: Int64
63+
64+
/// Stores Manager.
65+
///
66+
private let stores: StoresManager
67+
4868
/// ViewModel for the edit order note view.
4969
///
5070
lazy private(set) var noteViewModel = SimplePaymentsNoteViewModel()
@@ -53,8 +73,16 @@ final class SimplePaymentsSummaryViewModel: ObservableObject {
5373
totalWithTaxes: String,
5474
taxAmount: String,
5575
noteContent: String? = nil,
56-
currencyFormatter: CurrencyFormatter = CurrencyFormatter(currencySettings: ServiceLocator.currencySettings)) {
76+
siteID: Int64 = 0,
77+
orderID: Int64 = 0,
78+
feeID: Int64 = 0,
79+
currencyFormatter: CurrencyFormatter = CurrencyFormatter(currencySettings: ServiceLocator.currencySettings),
80+
stores: StoresManager = ServiceLocator.stores) {
81+
self.siteID = siteID
82+
self.orderID = orderID
83+
self.feeID = feeID
5784
self.currencyFormatter = currencyFormatter
85+
self.stores = stores
5886
self.providedAmount = currencyFormatter.formatAmount(providedAmount) ?? providedAmount
5987
self.totalWithTaxes = currencyFormatter.formatAmount(totalWithTaxes) ?? totalWithTaxes
6088
self.taxAmount = currencyFormatter.formatAmount(taxAmount) ?? taxAmount
@@ -81,16 +109,38 @@ final class SimplePaymentsSummaryViewModel: ObservableObject {
81109

82110
convenience init(order: Order,
83111
providedAmount: String,
84-
currencyFormatter: CurrencyFormatter = CurrencyFormatter(currencySettings: ServiceLocator.currencySettings)) {
112+
currencyFormatter: CurrencyFormatter = CurrencyFormatter(currencySettings: ServiceLocator.currencySettings),
113+
stores: StoresManager = ServiceLocator.stores) {
85114
self.init(providedAmount: providedAmount,
86115
totalWithTaxes: order.total,
87116
taxAmount: order.totalTax,
88-
currencyFormatter: currencyFormatter)
117+
siteID: order.siteID,
118+
orderID: order.orderID,
119+
feeID: order.fees.first?.feeID ?? 0,
120+
currencyFormatter: currencyFormatter,
121+
stores: stores)
89122
}
90123

91124
/// Sends a signal to reload the view. Needed when coming back from the `EditNote` view.
92125
///
93126
func reloadContent() {
94127
objectWillChange.send()
95128
}
129+
130+
/// Updates the order remotely with the information entered by the merchant.
131+
///
132+
func updateOrder() {
133+
showLoadingIndicator = true
134+
let action = OrderAction.updateSimplePaymentsOrder(siteID: siteID,
135+
orderID: orderID,
136+
feeID: feeID,
137+
amount: providedAmount,
138+
taxable: enableTaxes,
139+
orderNote: noteContent,
140+
email: email) { [weak self] result in
141+
guard let self = self else { return }
142+
self.showLoadingIndicator = false
143+
}
144+
stores.dispatch(action)
145+
}
96146
}

0 commit comments

Comments
 (0)