Skip to content

Commit 779a012

Browse files
committed
Adapt Order Details to new card eligibility approach.
1 parent 870a0e7 commit 779a012

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,7 @@ final class OrderDetailsDataSource: NSObject {
4646

4747
/// Whether the order is eligible for card present payment.
4848
///
49-
var isEligibleForCardPresentPayment: Bool {
50-
return cardPresentPaymentsConfiguration.isSupportedCountry &&
51-
order.isEligibleForCardPresentPayment(cardPresentPaymentsConfiguration: cardPresentPaymentsConfiguration,
52-
products: resultsControllers.products)
53-
}
49+
var isEligibleForCardPresentPayment: Bool = false
5450

5551
var isEligibleForRefund: Bool {
5652
guard !isRefundedStatus,

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

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,13 @@ extension OrderDetailsViewModel {
233233
}
234234

235235
group.enter()
236-
refreshCardPresentPaymentEligibility()
236+
checkCardPresentPaymentEligibility() {
237+
onReloadSections?()
238+
group.leave()
239+
}
240+
241+
group.enter()
242+
loadPaymentGatewayAccounts()
237243
group.leave()
238244

239245
group.enter()
@@ -601,7 +607,33 @@ extension OrderDetailsViewModel {
601607
stores.dispatch(action)
602608
}
603609

604-
func refreshCardPresentPaymentEligibility() {
610+
func checkCardPresentPaymentEligibility(onCompletion: (() -> Void)? = nil) {
611+
let configuration = configurationLoader.configuration
612+
613+
guard configuration.isSupportedCountry else {
614+
dataSource.isEligibleForCardPresentPayment = false
615+
onCompletion?()
616+
return
617+
}
618+
619+
let action = OrderCardPresentPaymentEligibilityAction
620+
.orderIsEligibleForCardPresentPayment(orderID: order.orderID,
621+
siteID: order.siteID,
622+
cardPresentPaymentsConfiguration: configurationLoader.configuration) { [weak self] result in
623+
switch result {
624+
case .success(let eligible):
625+
self?.dataSource.isEligibleForCardPresentPayment = eligible
626+
case .failure(_):
627+
self?.dataSource.isEligibleForCardPresentPayment = false
628+
}
629+
630+
onCompletion?()
631+
}
632+
633+
stores.dispatch(action)
634+
}
635+
636+
func loadPaymentGatewayAccounts() {
605637
/// No need for a completion here. The VC will be notified of changes to the stored paymentGatewayAccounts
606638
/// by the viewModel (after passing up through the dataSource and originating in the resultsControllers)
607639
///

WooCommerce/Classes/ViewRelated/Orders/Order Details/OrderDetailsViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ private extension OrderDetailsViewController {
600600
// Refresh date & view once payment has been collected.
601601
if result.isSuccess {
602602
self.viewModel.syncOrderAfterPaymentCollection {
603-
self.viewModel.refreshCardPresentPaymentEligibility()
603+
self.viewModel.loadPaymentGatewayAccounts()
604604
}
605605
}
606606
}

0 commit comments

Comments
 (0)