checkout / checkout-magento2-plugin

Checkout.com Magento 2 official extension
MIT License
32 stars 32 forks source link

Last module don't handle payment_declined #538

Open kpitn opened 9 months ago

kpitn commented 9 months ago

I just update module to last version : 5.5

Before (in 4.3.0) : In Callback.php

if ($api->isValidResponse($response)) { 
} else {
      $this->paymentErrorHandler->logError(
              $payload,
              $order
          );
}
    public function isValidResponse($response): bool
    {
        $this->logger->additional($this->utilities->objectToArray($response), 'api');

        return $response instanceof Model && $response->isSuccessful();
    }
    public function isSuccessful()
    {
        return parent::isSuccessful() && static::isApproved();
    }
    public function isApproved()
    {
        $approved = true;
        if ($this->getValue('approved') !== null) {
            $approved = $this->getValue('approved');
        }

        return $approved;
    }

declined

When you have isValidResponse = false, module execute logError, and your order was cancel with the message.


Now with 5.5 isValidResponse was change to :

    public function isValidResponse(array $response): bool
    {
        if (!isset($response['http_metadata'])) {
            return false;
        }

        $response = $response['http_metadata'];

        $this->logger->additional($this->utilities->objectToArray($response), 'api');

        return $response instanceof HttpMetadata && in_array($response->getStatusCode(), self::VALID_RESPONSE_CODE);
    }

Even if you have an payment_declined isValidResponse is always true. When you process the callback you don't handle payment_declined :

    public function setOrderStatus(OrderInterface $order, array $webhook): void
    {
        // Initialise state, status & order
        $this->state = null;
        $this->status = null;
        $this->order = $order;

        switch ($webhook['event_type']) {
            case 'payment_approved':
                $this->approved($webhook);
                break;
            case 'payment_captured':
                $this->captured();
                break;
            case 'payment_voided':
                $this->void();
                break;
            case 'payment_refunded':
                $this->refund($webhook);
                break;
            case 'payment_capture_pending':
                $this->capturePending($webhook);
                break;
            case 'payment_expired':
                $this->paymentExpired();
                break;
            case 'payment_authentication_failed':
                $this->paymentAuthenticationFailed();
            break;
        }

With the last version, order stay in pending status, callback don't do anything ...

DnD-Behou commented 9 months ago

Hi @kpitn

We are working on a fix and it is planned for the next release.

Thanks for the issue.