91 lines
2.9 KiB
PHP
91 lines
2.9 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Esun\Oceanpayment\Test\Unit\Model;
|
|
|
|
use Esun\Oceanpayment\Model\Signature;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class SignatureTest extends TestCase
|
|
{
|
|
private Signature $signature;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->signature = new Signature();
|
|
}
|
|
|
|
public function testCreatesHostedCheckoutRequestSignatureInDocumentedOrder(): void
|
|
{
|
|
$data = [
|
|
'account' => '995149',
|
|
'terminal' => '99514901',
|
|
'backUrl' => 'https://example.test/payment/back',
|
|
'order_number' => '100000001',
|
|
'order_currency' => 'USD',
|
|
'order_amount' => '1.00',
|
|
'billing_firstName' => 'Jane',
|
|
'billing_lastName' => 'Doe',
|
|
'billing_email' => 'jane@example.test',
|
|
];
|
|
|
|
self::assertSame(
|
|
'cb5715d1d66a44352b811b1d5c9aa74752244cb7c7304e9d2f0bc7fa18a820bf',
|
|
$this->signature->createRequest($data, 'test-secure-code')
|
|
);
|
|
}
|
|
|
|
public function testVerifiesCallbackAndRejectsTampering(): void
|
|
{
|
|
$data = [
|
|
'account' => '995149',
|
|
'terminal' => '99514901',
|
|
'order_number' => '100000001',
|
|
'order_currency' => 'USD',
|
|
'order_amount' => '1.00',
|
|
'order_notes' => '',
|
|
'card_number' => '411111***1111',
|
|
'payment_id' => 'PAY-123',
|
|
'payment_authType' => '0',
|
|
'payment_status' => '1',
|
|
'payment_details' => '80000:Transaction Approved',
|
|
'payment_risk' => '',
|
|
];
|
|
$data['signValue'] = hash(
|
|
'sha256',
|
|
implode('', array_values($data)) . 'test-secure-code'
|
|
);
|
|
|
|
self::assertSame($data['signValue'], $this->signature->createCallback($data, 'test-secure-code'));
|
|
self::assertTrue($this->signature->verifyCallback($data, 'test-secure-code'));
|
|
|
|
$data['order_amount'] = '100.00';
|
|
self::assertFalse($this->signature->verifyCallback($data, 'test-secure-code'));
|
|
}
|
|
|
|
public function testCreatesEmbeddedRequestSignatureWithoutBackUrl(): void
|
|
{
|
|
$data = [
|
|
'account' => '995149',
|
|
'terminal' => '99514901',
|
|
'backUrl' => 'https://example.test/payment/back',
|
|
'order_number' => '100000001',
|
|
'order_currency' => 'USD',
|
|
'order_amount' => '1.00',
|
|
'billing_firstName' => 'Jane',
|
|
'billing_lastName' => 'Doe',
|
|
'billing_email' => 'jane@example.test',
|
|
];
|
|
|
|
self::assertSame(
|
|
hash('sha256', '99514999514901100000001USD1.00JaneDoejane@example.testtest-secure-code'),
|
|
$this->signature->createEmbeddedRequest($data, 'test-secure-code')
|
|
);
|
|
}
|
|
|
|
public function testSanitizesCharactersThatBreakOceanpaymentSignatures(): void
|
|
{
|
|
self::assertSame('John Test ', $this->signature->sanitize(' John <Test>\'" '));
|
|
}
|
|
}
|