craftcms / commerce-mollie

Mollie payment gateway for Craft Commerce.
https://plugins.craftcms.com/commerce-mollie
MIT License
5 stars 10 forks source link

Add expiration date property for payments #60

Closed MatthiasBrodelet closed 1 month ago

MatthiasBrodelet commented 1 month ago

I want to change the default expire time of the SEPA bank transfers. By default this is 14 days. (https://docs.mollie.com/docs/bank-transfer)

Mollie has a property with which you can set the expire date for the payment called expiresAt. (https://docs.mollie.com/reference/create-payment) Unfortunately it does not seem like this plugin lets me edit this property.

I found the EVENT_BEFORE_SEND_PAYMENT_REQUEST event in the omnipay plugin which I used to do the following.

        Event::on(
            \craft\commerce\omnipay\base\Gateway::class,
            \craft\commerce\omnipay\base\Gateway::EVENT_BEFORE_SEND_PAYMENT_REQUEST,
            function(SendPaymentRequestEvent $event) {
                $event->modifiedRequestData = $event->requestData;
                $event->modifiedRequestData['expiresAt'] = "2024-09-28T09:28:37+00:00";
            }
        );

However this does not work. The description property is editable but not the expiresAt property. Can this be added please?

linear[bot] commented 1 month ago

PT-2168 Add expiration date property for payments

nfourtythree commented 1 month ago

Hi @MatthiasBrodelet

Thank you for your feedback.

We have just released version 4.2.0 of the commerce-omnipay library which this plugin uses.

In that release we have included a new event EVENT_BUILD_GATEWAY_REQUEST. This falls in line with other gateway plugin and gives developers the opportunity to modify the request data that will be sent to the payment provider.

You should be able to run composer update in your project to get the latest version of the library.

With that you will be able to adjust your code as follows:

Event::on(
    \craft\commerce\omnipay\base\Gateway::class,
    \craft\commerce\omnipay\base\Gateway::EVENT_BUILD_GATEWAY_REQUEST,
    function(\craft\commerce\omnipay\events\BuildGatewayRequestEvent $event) {
        $event->request['expiresAt'] = "2024-09-28T09:28:37+00:00";
    }
);

Hope this helps, thanks!