eileenmcnaughton / nz.co.fuzion.omnipaymultiprocessor

Omnipay Multi Processor Payment Processor For CiviCRM
Other
13 stars 44 forks source link

Cannot change contribution status Completed to Failed #43

Open magnolia61 opened 6 years ago

magnolia61 commented 6 years ago

Ran into something I think is related to https://github.com/eileenmcnaughton/nz.co.fuzion.omnipaymultiprocessor/issues/25. When refunding a payment from the Mollie backend, I get the message "Cannot change contribution status from Completed to Failed." (it should be changed to refunded)

Mollie does suport handling refunds, both to and from Mollie. I mean they could be handled by CiviCRM or from Mollies side and the omnipay module could handle the administration.

In omnipay-mollie src/Message/FetchTransactionResponse.php it handles the refunded status

public function isRefunded()
 +    {
 +        return isset($this->data['status']) && 'refunded' === $this->data['status'];
 +    }
 +
 +    public function isPartialRefunded()
 +    {
 +        return $this->isRefunded() && isset($this->data['amountRemaining']) && $this->data['amountRemaining'] > 0;
 +    }

When Mollie updates a status it performs a knock-knock after which the payment method should fetch the payment information from Mollie:

The webhook will be called with a single POST-parameter named id, which for example will contain the value tr_d0b0E3EA3v. You should use that id to actively fetch the payment to find out about it's status. This step seems a little cumbersome but proper security dictates this flow. Since the status is not transmitted in the webhook, fake calls to your webhook will never result in orders being processed without being actually paid.

That is why the status itself is not sent in the webhook url is only known after FetchTransactionResponse.php retrieves it.

That being said, I'm not sure why omnipaymultiprocessor wants to try to change the status from completed to failed. At Mollies side the payment status is 'refunded'. What could be the problem? Better: the solution ;-)

eileenmcnaughton commented 6 years ago

I think this would be a nice improvement but realistically I'm not going to get to it any time soon

magnolia61 commented 6 years ago

I think https://github.com/eileenmcnaughton/nz.co.fuzion.omnipaymultiprocessor/commit/f74355ac18c6a5790c1327eea9ffa4126b7cf34b solves the error, but still the real solution would be to have the status change to 'refunded'. Just a quick update on this reference. More work needed.

eileenmcnaughton commented 6 years ago

Right - I think that change is not intentionally directed at your issue (although it tangentally affects it)