feat(admin): show which domain a payment came from
Several storefronts share one gateway — the city booking sites and the ClinicPro panel itself — so the payments report could not say where a transaction originated. The payment already stores the return address it was started with; the domain is derived from it. Lowercased and stripped of "www." so one domain is one value in the report, null when a payment has no return address. Exposed on both the list and the detail (which also carries the full address), and the list search now matches it, so filtering to a single site needs no new parameter. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tests\Payment;
|
||||
|
||||
use App\Payment\Entity\Payment;
|
||||
use App\Tests\ApiTestCase;
|
||||
|
||||
/**
|
||||
* Several storefronts (city booking sites, the ClinicPro panel) share one
|
||||
* gateway, so the payments report has to say which one a transaction came
|
||||
* from. The origin is derived from the return address stored on the payment.
|
||||
*/
|
||||
class PaymentOriginTest extends ApiTestCase
|
||||
{
|
||||
private function makePayment(string $frontendAddress): Payment
|
||||
{
|
||||
$payment = new Payment($this->createUser(), 100_000, 'mellat', Payment::TYPE_SUBSCRIPTION, $frontendAddress);
|
||||
$this->stampTenant($payment);
|
||||
$this->em->persist($payment);
|
||||
$this->em->flush();
|
||||
|
||||
return $payment;
|
||||
}
|
||||
|
||||
private function admin(): \App\Auth\Entity\User
|
||||
{
|
||||
return $this->createUser(['ROLE_USER', 'ROLE_ADMIN']);
|
||||
}
|
||||
|
||||
public function testListExposesTheOriginDomain(): void
|
||||
{
|
||||
$payment = $this->makePayment('https://nobat724.com/payment/result');
|
||||
|
||||
$body = $this->authJson('GET', '/api/v1/admin/payments?limit=100', $this->admin());
|
||||
$row = current(array_filter($body['data'], fn(array $r) => $r['uuid'] === $payment->getUuid()));
|
||||
|
||||
self::assertSame('nobat724.com', $row['origin']);
|
||||
}
|
||||
|
||||
public function testWwwAndCaseAreNormalisedSoOneDomainIsOneValue(): void
|
||||
{
|
||||
$payment = $this->makePayment('https://WWW.Nobat724.com/payment/result');
|
||||
|
||||
$body = $this->authJson('GET', '/api/v1/admin/payments/' . $payment->getUuid(), $this->admin());
|
||||
|
||||
self::assertSame('nobat724.com', $body['data']['origin']);
|
||||
self::assertSame('https://WWW.Nobat724.com/payment/result', $body['data']['frontend_address']);
|
||||
}
|
||||
|
||||
public function testPaymentWithoutAReturnAddressHasNoOrigin(): void
|
||||
{
|
||||
$payment = $this->makePayment('');
|
||||
|
||||
$body = $this->authJson('GET', '/api/v1/admin/payments/' . $payment->getUuid(), $this->admin());
|
||||
|
||||
self::assertNull($body['data']['origin']);
|
||||
}
|
||||
|
||||
public function testSearchMatchesTheOriginDomain(): void
|
||||
{
|
||||
$wanted = $this->makePayment('https://yasuj-nobat.ir/payment/result');
|
||||
$other = $this->makePayment('https://nobat724.com/payment/result');
|
||||
|
||||
$body = $this->authJson('GET', '/api/v1/admin/payments?limit=100&search=yasuj-nobat.ir', $this->admin());
|
||||
$uuids = array_column($body['data'], 'uuid');
|
||||
|
||||
self::assertContains($wanted->getUuid(), $uuids);
|
||||
self::assertNotContains($other->getUuid(), $uuids);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user