@@ -93,15 +93,6 @@ final class SimplePaymentsMethodsViewModel: ObservableObject {
9393 return controller
9494 } ( )
9595
96- /// Product ResultsController.
97- ///
98- private lazy var productResultsController : ResultsController < StorageProduct > = {
99- let predicate = NSPredicate ( format: " siteID == %lld " , siteID)
100- let descriptor = NSSortDescriptor ( key: " name " , ascending: true )
101-
102- return ResultsController < StorageProduct > ( storageManager: storage, matching: predicate, sortedBy: [ descriptor] )
103- } ( )
104-
10596 /// Retains the use-case so it can perform all of its async tasks.
10697 ///
10798 private var collectPaymentsUseCase : CollectOrderPaymentProtocol ?
@@ -270,20 +261,29 @@ private extension SimplePaymentsMethodsViewModel {
270261 ///
271262 func bindStoreCPPState( ) {
272263 ordersResultController. onDidChangeContent = updateCardPaymentVisibility
273- productResultsController. onDidChangeContent = updateCardPaymentVisibility
274264 try ? ordersResultController. performFetch ( )
275- try ? productResultsController. performFetch ( )
276265 }
277266
278267 func updateCardPaymentVisibility( ) {
279- guard let order = ordersResultController . fetchedObjects . first else {
268+ guard cardPresentPaymentsConfiguration . isSupportedCountry else {
280269 showPayWithCardRow = false
270+
281271 return
282272 }
283273
284- showPayWithCardRow = cardPresentPaymentsConfiguration. isSupportedCountry && order. isEligibleForCardPresentPayment (
285- cardPresentPaymentsConfiguration: cardPresentPaymentsConfiguration,
286- products: productResultsController. fetchedObjects)
274+ let action = OrderCardPresentPaymentEligibilityAction
275+ . orderIsEligibleForCardPresentPayment ( orderID: orderID,
276+ siteID: siteID,
277+ cardPresentPaymentsConfiguration: cardPresentPaymentsConfiguration) { [ weak self] result in
278+ switch result {
279+ case . success( let eligible) :
280+ self ? . showPayWithCardRow = eligible
281+ case . failure( _) :
282+ self ? . showPayWithCardRow = false
283+ }
284+ }
285+
286+ stores. dispatch ( action)
287287 }
288288
289289 func updateOrderAsynchronously( ) {
0 commit comments