wagnerwagner / merx

Merx is a plugin to create online shops with Kirby.
https://merx.wagnerwagner.de
102 stars 10 forks source link

Adding iDeal (request) #19

Closed bartvandebiezen closed 3 months ago

bartvandebiezen commented 3 years ago

Is it possible to add iDeal support? After a lot of 'Gateway not supported' messages I discovered Merx has to support a payment method before it can redirect to Stripe, even if Stripe supports it already.

Kind regards, Bart

bartvandebiezen commented 3 years ago

I added this to gateways.php and all seems to work correctly:


Gateways::$gateways['ideal'] = [
    'initializePayment' => function (OrderPage $virtualOrderPage): OrderPage
    {
        $data = [
        ];
        $source = Payment::createStripeSource($virtualOrderPage->cart()->getSum(), 'ideal', $data);
        $virtualOrderPage->content()->update([
            'redirect' => $source->redirect->url,
        ]);
        return $virtualOrderPage;
    },
    'completePayment' => function (OrderPage $virtualOrderPage, array $data): OrderPage
    {
        return completeStripePayment($virtualOrderPage, $data);
    },
];
Tazi0 commented 1 year ago

With previous comment, so you can add them without editing the merx submodule: put this in your config.php

'ww.merx.gateways' => [
        'ideal' => [
            'initializePayment' => function (OrderPage $virtualOrderPage): OrderPage {
                $data = [];
                $source = Payment::createStripeSource($virtualOrderPage->cart()->getSum(), 'ideal', $data);
                $virtualOrderPage->content()->update([
                    'redirect' => $source->redirect->url,
                ]);
                return $virtualOrderPage;
            },
            'completePayment' => function (OrderPage $virtualOrderPage, array $data): OrderPage {
                // check if user canceled payment
                if (isset($data['source']) && Payment::getStatusOfSource($data['source']) === 'failed') {
                    throw new Exception([
                        'key' => 'merx.paymentCanceled',
                        'httpCode' => 400,
                    ]);
                }
                // charge payment
                $sourceString = $data['source'] ?? $virtualOrderPage->stripeToken()->toString();
                $stripeCharge = Payment::createStripeCharge($virtualOrderPage->cart()->getSum(), $sourceString);
                $virtualOrderPage->content()->update([
                    'paymentDetails' => (array)$stripeCharge,
                    'paymentComplete' => true,
                    'paidDate' => date('c'),
                ]);
                return $virtualOrderPage;
            },
        ]
    ],
tobiasfabian commented 3 months ago

A gateway for iDeal is added to 1.9.0-beta.1.

The new gateway uses Stripe Payment Intents instead of the deprecated Stripe Sources.