white-nl / commerce-mollie-plus

Mollie Klarna integration for Craft Commerce
Other
3 stars 5 forks source link

Selecting the Klarna 'Slice It' or in3 payment methods redirects to payment form #14

Closed nilsenpaul closed 1 year ago

nilsenpaul commented 1 year ago

Description

We have a working payment form, from which we can request payments for iDeal, Klarna Pay Now and Sofort. Then, we activated in3 and Klarna Slice It payment options in Mollie. Those appear in the payment methods, but if we select one of those, we get redirected to the payment form without ever being redirected to Mollie.

Steps to reproduce

  1. Add in3 or Klarna Slice it payment method
  2. Try to create a payment with one of the above

Additional info

WHITE-developer commented 1 year ago

Hi @nilsenpaul, Thank you for contacting us.

I just tried to replicate it on a clean craft 4 install, but are unable to replicate this. Could you maybe share you payment form code?

nilsenpaul commented 1 year ago

Jup:


<input x-model="cart.gatewayId" type="hidden" name="gatewayId" value="{{ mollieGateway.id }}" />
{% if paymentMethods %}
    <div class="relative w-full mb-6 md:w-1/3">
        <select x-model="cart.paymentMethod" name="{{ namespace }}[paymentMethod]">
            <option value="">Kies een betaalmethode</option>
                {% for method in paymentMethods %}
                    <option value="{{ method.id }}">{{ method.name }}</option>
                {% endfor %}
        </select>
    </div>
{% endif %}```
WHITE-developer commented 1 year ago

hmm, at a first sight that looks ok, I guess your {{ namespace }} is equal to paymentForm[gatewayhandle]? And other methods (iDeal, Pay Now, ...) are working fine?

Is there a transaction getting added in Craft commerce, or do you see a console error/network request in your browser when submitting the form?

nilsenpaul commented 1 year ago

Hm, I seem to have been wasting your time. Upon closer inspecting of the transactions, they get a 422 error, because the cart total is higher than maximum:

"Client error:POST https:\/\/api.mollie.com\/v2\/ordersresulted in a422 Unprocessable Entityresponse:\n{\u0022status\u0022:422,\u0022title\u0022:\u0022Unprocessable Entity\u0022,\u0022detail\u0022:\u0022The amount is higher than the maximum\u0022,\u0022field\u0022:\u0022payment.amount\u0022,\u0022 (truncated...)\n"

Now to find out what the maximum is ...

WHITE-developer commented 1 year ago
{% set paymentMethods = gateway.fetchPaymentMethods({
    'resource': 'orders',
    'locale': cart.orderLanguage,
    'amount': cart.total,
    'currency': cart.paymentCurrency,
    'billingCountry': cart.billingAddress.countryCode,
}) %}

This will only return the payment methods that match your order https://docs.mollie.com/reference/v2/methods-api/list-methods