ethercreative / web-payments

Web Payments for Craft Commerce
Other
5 stars 7 forks source link

How to detect if visitor can make web payments? #13

Open billythekid opened 4 years ago

billythekid commented 4 years ago

Hi all,

Yeah like the title says, is there a way, preferably server side / twig but can be JS if that's the only way, to detect if the current visitor has the capability to use web payments (so not even show the option in the gateway select dropdown if they can't use it)

In one site I have we use a select dropdown for the html form code to be used for each option. if you select the credit card gateway for example you get the sagepay form, finance gives another gateway's form, paypal gives the paypal button and apple pay / google pay gives this plugin's rendered button. With the finance option I don't show the dropdown if the cart isn't "financable" (minimum price etc.) I'd like to do something similar for the web payments option, if the visitor's browser/device doesn't support it, don't give them the option to select it in the first place.

I found the docs for apple pay and the docs for google pay to check if each is supported by the current visitor's browser/device but not sure how this is handled in the plugin already (since I don't actually get a button in a browser that doesn't support it but is that because it doesn't support it (so it's failing) or because that's been checked by the plugin.)

Is there a test we can wrap the template code in to decide whether to show it or not?

davecosec commented 4 years ago

@billythekid there it window.ApplePaySession to check if the session exist for Apple Pay. For Google Pay, I can see the method in the code but it's not accessible to window, unless i'm mistaken so I've had to do a not so nice workaround

Adamascroft commented 4 years ago

This would be a great feature to have to be able to show a specific section if the button(s) are available.

davecosec commented 4 years ago

Some of these methods do need to exposed. We need to be able to refresh the button for single page checkouts, (when the user changes their location) and we need to be able to check properly if the user can pay via google pay