Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Last module don't handle payment_declined #538

Open
kpitn opened this issue Nov 2, 2023 · 1 comment
Open

Last module don't handle payment_declined #538

kpitn opened this issue Nov 2, 2023 · 1 comment

Comments

@kpitn
Copy link

kpitn commented Nov 2, 2023

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
Copy link
Collaborator

Hi @kpitn

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

Thanks for the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants