Skip to content

Commit

Permalink
Payir tests updated;
Browse files Browse the repository at this point in the history
  • Loading branch information
hans-thomas committed Sep 4, 2023
1 parent 4ef2a6f commit da8bf40
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 16 deletions.
35 changes: 19 additions & 16 deletions src/Gateways/Payir.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,27 +68,30 @@ public function verify(Invoice $invoice): bool
);
}

if ($this->isSandboxEnabled()) {
return true;
}

$data = [
'api' => $this->settings['api'],
'token' => $token,
];

$response = $this->client->post(
$this->apis()['verification'],
[
'json' => $data,
'headers' => [
'Accept' => 'application/json',
],
]
)
->getBody()
->getContents();
$result = json_decode($response, true);
if ($this->isSandboxEnabled()) {
$result = [
"status" => 1,
"transId" => 'fake-static-transId',
];
} else {
$response = $this->client->post(
$this->apis()['verification'],
[
'json' => $data,
'headers' => [
'Accept' => 'application/json',
],
]
)
->getBody()
->getContents();
$result = json_decode($response, true);
}

if ($result['status'] !== 1) {
return false;
Expand Down
27 changes: 27 additions & 0 deletions tests/Feature/Gateways/PayirTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,38 @@ public function pay(): void
public function verifyOnSuccess(): void
{
Lyra::setGateway(Payir::class, 10000, 'sandbox');
$invoice = Lyra::getInvoice();

$url = Lyra::pay(10000)->getRedirectUrl();
$token = Str::afterLast($url, '/');
request()->merge(['status' => 1, 'token' => $token]);

self::assertNull($invoice->transaction_id);

self::assertTrue(Lyra::verify());
$invoice->refresh();

self::assertIsString($invoice->transaction_id);
}

/**
* @test
*
* @return void
*/
public function verifyOnDuplicateVerification(): void
{
Lyra::setGateway(Payir::class, 10000, 'sandbox');

$url = Lyra::pay(10000)->getRedirectUrl();
$token = Str::afterLast($url, '/');
request()->merge(['status' => 1, 'token' => $token]);

self::assertTrue(Lyra::verify());

$this->expectException(\Exception::class);
$this->expectExceptionMessage('تراکنش تکراریست یا قبلا انجام شده');

self::assertTrue(Lyra::verify());
}

Expand Down

0 comments on commit da8bf40

Please sign in to comment.