File tree Expand file tree Collapse file tree 3 files changed +36
-8
lines changed
ViewRelated/Orders/Order Details Expand file tree Collapse file tree 3 files changed +36
-8
lines changed Original file line number Diff line number Diff 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,
Original file line number Diff line number Diff 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 ///
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments