white-nl / commerce-mollie-plus

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

Doesn't work with Klarna due due to different response status #5

Closed lenvanessen closed 2 years ago

lenvanessen commented 2 years ago

When Klarna is chosen as a payment option, the status that is returned when succesful is authorized, not paid.

Mollie documentation: https://help.mollie.com/hc/nl/articles/360009912694-Wat-zijn-de-mogelijke-statussen-voor-een-order-

"Wanneer de betaling voor de bestelling succesvol is afgerond met een betaalmethode waar autorisaties voor zijn vereist wordt deze status geactiveerd. Het bedrag wordt in dit geval pas overgeschreven op het moment dat er een verzending is aangemaakt voor de order. Momenteel wordt deze status alleen gebruikt voor Klarna Pay later en Klarna Slice it."

But since The default RequestResponse from omnipay evaluates a succesfull payment as follows follows: https://github.com/thephpleague/omnipay-mollie/blob/master/src/Message/Response/CompleteOrderResponse.php#L13-L16

It's marked as failed, when it should have been successful (since authorized is actually a successful payment. It can be fixed by a small workaround in the plug-in, pull-request is incoming.

WHITE-developer commented 2 years ago

Hi @lenvanessen

Thank you for your message.

It's marked as failed, when it should have been successful

Do you mean the transaction fails or do you mean the order status is "Unpaid"? If you mean the order status, you can see this in 2 ways.

  1. For the customer the order is paid, so the status should be "Paid"
  2. For the shop owner the order isn't paid yet. Once he captures the transaction the order will be marked as paid. Klarna requires a confirmation that the order is shipped before they pay out. So for the shop owner it is good to see that it is "Unpaid".

Therefor we think it is better to leave it like it is. If you want to show a pay status in the frontend you are free to do that.

If you mean the transaction does fail we would like to get some more info (like Craft and Commerce version) as we don't see that happen in the shops were we are using the plugin.

lenvanessen commented 2 years ago

@WHITE-developer ,

I understand. your explanation. What I mean is the following:

When A payment is succesfull, Craft will mark the order as being complete. This way, the cart is emptied and the user is redirected to the thank you page, which is defined by the hashed input param. However, since the response status from Mollie is 'authorized', and the mollie-omnipay specifically adds the additional check on the status 'paid', Craft never completes this process, and the user is redirected back to the cart, which is still there (even though a payment has bene authorized with Klarna), instead of being redirected to the thank-you page.

You can see Craft checking it here: https://github.com/craftcms/commerce/blob/develop/src/services/Payments.php#L430

And here is the part where Craft is supposed to mark the order as complete: https://github.com/craftcms/commerce/blob/develop/src/services/Payments.php#L437-L439

I understand your logic, perhaps is better than to overwrite the isProcessing method. But if I understand correctly, in your installations, Craft actually marks the order as ready and empties the cart when someone has paid trough Klarna? i don't see how this would be possible, given the response and handeling..

We're running craft 3.7.34 and commerce 3.4.11

WHITE-developer commented 2 years ago

Thanks for your info. Yes, in our setups the order gets completed, success page is shown and so the cart is emptied. See the following screenshot which is a completed order from this morning https://nimb.ws/3ykcAF The transaction is successfully authorized and so the order is completed with payment status "Unpaid".

lenvanessen commented 2 years ago

@WHITE-developer this is a klarna payment?

can you check the status that is capitured in the response? Was it ‘authorized’? (The debug info should be behind the i)

WHITE-developer commented 2 years ago

Sure it is ;) Response is authorized https://nimb.ws/3N9KOi

lenvanessen commented 2 years ago

@WHITE-developer that's very strange, i'll do some more debugging in the morning to see what's different with our response