-
Notifications
You must be signed in to change notification settings - Fork 219
Experiment: Add available_payment_methods to the API and cart data #5442
Conversation
Size Change: +474 B (0%) Total Size: 819 kB
ℹ️ View Unchanged
|
I actually wrote a reply for
|
@senadir just to be clear, are you saying we need to remove support for the filtering on the PHP side (that this PR fixes)? |
I'm saying that this PR (along side |
For us yes. If we don't support Where does this leave us with issue 5388? |
I also see the issue of filtering using data that's only available in the frontend, which might not be a big issue since the data will get synced back to the client. You raise a good point, which is probably a good time for us to reconsider our filtering approach, assuming we go with this, you now can filter payments using:
Which is a bit excessive and at least 1 method too much. @ralucaStan how do you feel about the @mikejolley the main thing that's preventing me from going with
Assuming we continue with not exposing and filtering available payment methods on the frontend, we can just close that with a response that we use frontend filters. |
canMakePayment is actually the place where we call the callbacks that extensions might register with registerPaymentMethodExtensionCallbacks to filter payment methods, so removing it is not really an option. What do you thing that instead of adding a new If this availability is something we want to take into consideration we could also do a general check in the canMakePayment function just by checking that |
This attempts to solve the problem in #5388 by adding
available_payment_methods
to the cart response data with the current list of available payment method IDs.Payment methods are registered if
enabled
in settings. This enqueues the scripts for Blocks.This script is not aware of the
woocommerce_available_payment_gateways
filter, so to handle this we need to check if a method is available via itscanMakePayment
callback.So
canMakePayment
knows which methods are available, I've updated the cart data to include a list of available payment method IDs which are surfaced to gateways.Testing
Use a snippet like this:
Make a free shipping and flat rate shipping method costing $50. Add $60 of items to the cart. Toggle between free shipping and flat rate shipping so the totals change. BACS should only be available when free shipping is checked.