diff --git a/src/Call/OneClick/InitOneClickPaymentRequest.php b/src/Call/OneClick/InitOneClickPaymentRequest.php index b0beb47..75de925 100644 --- a/src/Call/OneClick/InitOneClickPaymentRequest.php +++ b/src/Call/OneClick/InitOneClickPaymentRequest.php @@ -10,6 +10,7 @@ use SlevomatCsobGateway\Crypto\SignatureDataFormatter; use SlevomatCsobGateway\Price; use SlevomatCsobGateway\Validator; +use function base64_encode; class InitOneClickPaymentRequest { @@ -32,13 +33,17 @@ class InitOneClickPaymentRequest /** @var string */ private $clientIp; + /** @var string|null */ + private $merchantData; + public function __construct( string $merchantId, string $origPayId, string $orderId, string $clientIp, ?Price $price = null, - ?string $description = null + ?string $description = null, + ?string $merchantData = null ) { Validator::checkPayId($origPayId); @@ -46,6 +51,9 @@ public function __construct( if ($description !== null) { Validator::checkDescription($description); } + if ($merchantData !== null) { + Validator::checkMerchantData($merchantData); + } $this->merchantId = $merchantId; $this->origPayId = $origPayId; @@ -53,6 +61,7 @@ public function __construct( $this->clientIp = $clientIp; $this->price = $price; $this->description = $description; + $this->merchantData = $merchantData; } public function send(ApiClient $apiClient): PaymentResponse @@ -73,6 +82,10 @@ public function send(ApiClient $apiClient): PaymentResponse $requestData['description'] = $this->description; } + if ($this->merchantData !== null) { + $requestData['merchantData'] = base64_encode($this->merchantData); + } + $response = $apiClient->post( 'oneclick/init', $requestData, @@ -85,6 +98,7 @@ public function send(ApiClient $apiClient): PaymentResponse 'totalAmount' => null, 'currency' => null, 'description' => null, + 'merchantData' => null, ]), new SignatureDataFormatter([ 'payId' => null, diff --git a/src/RequestFactory.php b/src/RequestFactory.php index 7abe117..efd763a 100644 --- a/src/RequestFactory.php +++ b/src/RequestFactory.php @@ -150,7 +150,8 @@ public function createOneclickInitPayment( string $orderId, string $clientIp, ?Price $price = null, - ?string $description = null + ?string $description = null, + ?string $merchantData = null ): InitOneClickPaymentRequest { return new InitOneClickPaymentRequest( @@ -159,7 +160,8 @@ public function createOneclickInitPayment( $orderId, $clientIp, $price, - $description + $description, + $merchantData ); } diff --git a/tests/unit/Call/OneClick/InitOneClickPaymentRequestTest.php b/tests/unit/Call/OneClick/InitOneClickPaymentRequestTest.php index bcc6d27..1652900 100644 --- a/tests/unit/Call/OneClick/InitOneClickPaymentRequestTest.php +++ b/tests/unit/Call/OneClick/InitOneClickPaymentRequestTest.php @@ -12,6 +12,7 @@ use SlevomatCsobGateway\Call\ResultCode; use SlevomatCsobGateway\Currency; use SlevomatCsobGateway\Price; +use function base64_encode; class InitOneClickPaymentRequestTest extends TestCase { @@ -32,6 +33,7 @@ public function testSend(): void 'totalAmount' => 1789600, 'currency' => 'CZK', 'description' => 'Nákup na vasobchod.cz (Lenovo ThinkPad Edge E540, Doprava PPL)', + 'merchantData' => base64_encode('some-base64-encoded-merchant-data'), ]) ->willReturn( new Response(ResponseCode::get(ResponseCode::S200_OK), [ @@ -49,7 +51,8 @@ public function testSend(): void '5547', '127.0.0.1', new Price(1789600, Currency::get(Currency::CZK)), - 'Nákup na vasobchod.cz (Lenovo ThinkPad Edge E540, Doprava PPL)' + 'Nákup na vasobchod.cz (Lenovo ThinkPad Edge E540, Doprava PPL)', + 'some-base64-encoded-merchant-data' ); $paymentResponse = $initPaymentRequest->send($apiClient); diff --git a/tests/unit/RequestFactoryTest.php b/tests/unit/RequestFactoryTest.php index 0f8c20a..590ac46 100644 --- a/tests/unit/RequestFactoryTest.php +++ b/tests/unit/RequestFactoryTest.php @@ -116,7 +116,8 @@ public function testCreateOneclickInitPayment(): void '5547123', '127.0.0.1', new Price(1789600, Currency::get(Currency::CZK)), - 'Nákup na vasobchod.cz (Lenovo ThinkPad Edge E540, Doprava PPL)' + 'Nákup na vasobchod.cz (Lenovo ThinkPad Edge E540, Doprava PPL)', + 'some-base64-encoded-merchant-data' ); self::assertTrue(true);