Skip to content

Commit

Permalink
upd: Improve error handling, combine similar response classes into one
Browse files Browse the repository at this point in the history
  • Loading branch information
bozhidarampeco committed Dec 30, 2024
1 parent dd4c87d commit 7b5af11
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/Message/AuthorizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ public function getData(): array
];
}

protected function createResponse($data, int $statusCode): AuthorizeResponse
protected function createResponse($data, int $statusCode): TransactionResponse
{
return $this->response = new AuthorizeResponse($this, $data, $statusCode);
return $this->response = new TransactionResponse($this, $data, $statusCode);
}
}
4 changes: 2 additions & 2 deletions src/Message/PurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ public function getData(): array
];
}

protected function createResponse($data, int $statusCode): PurchaseResponse
protected function createResponse($data, int $statusCode): TransactionResponse
{
return $this->response = new PurchaseResponse($this, $data, $statusCode);
return $this->response = new TransactionResponse($this, $data, $statusCode);
}
}
21 changes: 0 additions & 21 deletions src/Message/PurchaseResponse.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Ampeco\OmnipayMonri\Message;

class AuthorizeResponse extends AbstractResponse
class TransactionResponse extends AbstractResponse
{
public function isSuccessful(): bool
{
Expand All @@ -16,6 +16,10 @@ public function getTransactionReference()

public function getMessage(): ?string
{
return isset($this->data['errors']) ? current($this->data['errors']) : null;
if (isset($this->data['errors'])) {
return current($this->data['errors']);
}

return $this->data['transaction']['response_message'] ?? null;
}
}
}

0 comments on commit 7b5af11

Please sign in to comment.