Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
coverage badge.

### Fixed
- **Zibal:** verification HTTP errors and unsuccessful gateway results throw `InvalidPaymentException` instead of
`PurchaseFailedException`, so the documented verification error handler catches them.
- SnappPay payment pages without a query string no longer trigger a PHP deprecation when building the redirect form.
- Zarinpal purchase failures consistently throw `PurchaseFailedException` in normal and sandbox modes, preserving
available gateway error codes and handling empty, non-JSON or missing-status responses without PHP warnings.
Expand Down
4 changes: 2 additions & 2 deletions src/Drivers/Zibal/Zibal.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public function verify(): ReceiptInterface
if ($response->getStatusCode() !== 200) {
// connection error
$message = $body['message'] ?? 'خطا در هنگام وریفای تراکنش رخ داده است.';
throw new PurchaseFailedException($message, (int) $response->getStatusCode());
throw new InvalidPaymentException($message, (int) $response->getStatusCode());
}
if ($body['result'] == 201) {
// transaction has been verified before
Expand All @@ -177,7 +177,7 @@ public function verify(): ReceiptInterface

if ($body['result'] != 100) {
// gateway errors
throw new PurchaseFailedException($this->translateStatus($body['result']), $body['result']);
throw new InvalidPaymentException($this->translateStatus($body['result']), $body['result']);
}

return new Receipt('Zibal', $body['refNumber'])->detail($body);
Expand Down
17 changes: 16 additions & 1 deletion tests/Drivers/ZibalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,23 @@ public function testVerifyFailsWhenTheGatewayReportsAnError(): void
$driver = $this->driver();
$this->fakeHttp($driver, [$this->jsonResponse(['result' => 202])]);

$this->expectException(PurchaseFailedException::class);
$this->expectException(InvalidPaymentException::class);
$this->expectExceptionMessage('سفارش پرداخت نشده یا ناموفق بوده است.');
$this->expectExceptionCode(202);

$driver->verify();
}

public function testVerifyFailsWhenTheGatewayIsNotReachable(): void
{
$this->fakeRequest(['success' => 1, 'trackId' => 1234567]);

$driver = $this->driver();
$this->fakeHttp($driver, [$this->jsonResponse(['message' => 'service unavailable'], 503)]);

$this->expectException(InvalidPaymentException::class);
$this->expectExceptionMessage('service unavailable');
$this->expectExceptionCode(503);

$driver->verify();
}
Expand Down
Loading