craftcms / commerce-stripe

Stripe payment gateway for Craft Commerce
https://plugins.craftcms.com/commerce-stripe
MIT License
30 stars 51 forks source link

Allow the bypass of `payment_method_types` #251

Closed mvanbeselaere closed 7 months ago

mvanbeselaere commented 11 months ago

Hey there,

The current default request by the CustomerController is set to ['bancontact', 'card', 'ideal'] as per https://github.com/craftcms/commerce-stripe/blob/e779b6f53ce3cd11ccdda9f71fbdbf04629af3ed/src/controllers/CustomersController.php#L129-L132

It would be cool to be able to select our own default payment_method_types in the settings. Or is there a way to tweak that via the params object of the {{ gateway.getPaymentFormHtml(params)|raw }}?

Thanks a lot

okolvik-avento commented 9 months ago

This wouldn't just be cool. It's absolutely necessary to be able to configure the payment methods

okolvik-avento commented 9 months ago

Found a way to override it:

use craft\commerce\stripe\base\Gateway as StripeGateway;
use craft\commerce\stripe\events\BuildSetupIntentRequestEvent;

Event::on(
    StripeGateway::class,
    StripeGateway::EVENT_BUILD_SETUP_INTENT_REQUEST,
    function(BuildSetupIntentRequestEvent $event) {
        $event->request["payment_method_types"] = ["card"];
    }
);
daniellelecomte commented 7 months ago

Hi @okolvik-avento - trying to implement something similar here. Can you share how you are implementing this override?

nfourtythree commented 7 months ago

Hi All

Thanks for highlighting this.

We have pushed a fix which means the payment method options shown to the user will now match those that are enabled in your Stripe dashboard.

As @okolvik-avento mentioned you can still alter/restrict these by using the Gateway::EVENT_BUILD_SETUP_INTENT_REQUEST event.

This fix will be included in the next release of the plugin.

Thanks!

nfourtythree commented 7 months ago

Hi All

Version 4.1.1 of the plugin has now been released which includes this update.

Thanks!