From c76a2bb2f09aaad54d8141351cb9cfac08cfc041 Mon Sep 17 00:00:00 2001 From: Shahbaz Date: Mon, 4 May 2026 19:08:15 +0500 Subject: [PATCH 1/4] Allow setting the terminal using checkoutSession --- CHANGELOG.md | 4 ++++ src/AbstractApi.php | 2 +- src/Api/Payments/CheckoutSession.php | 4 +++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index efbf652..c34731c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [3.5.9] - 2026-05-04 +### Added +- Allow setting the terminal using `checkoutSession`. + ## [3.5.8] - 2026-02-23 ### Added - Add support for `checkoutSession` API method. diff --git a/src/AbstractApi.php b/src/AbstractApi.php index e415c70..3a3a239 100644 --- a/src/AbstractApi.php +++ b/src/AbstractApi.php @@ -55,7 +55,7 @@ abstract class AbstractApi /** * PHP API version */ - const PHP_API_VERSION = '3.5.8'; + const PHP_API_VERSION = '3.5.9'; /** * Event dispatcher diff --git a/src/Api/Payments/CheckoutSession.php b/src/Api/Payments/CheckoutSession.php index 36dbc7b..ac0edc4 100644 --- a/src/Api/Payments/CheckoutSession.php +++ b/src/Api/Payments/CheckoutSession.php @@ -29,6 +29,7 @@ use Altapay\Exceptions\ResponseMessageException; use Altapay\Serializer\ResponseSerializer; use Altapay\Response\CheckoutSessionResponse; +use Altapay\Traits\TerminalTrait; use GuzzleHttp\Exception\ClientException as GuzzleHttpClientException; use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\Psr7\Request; @@ -37,6 +38,7 @@ class CheckoutSession extends AbstractApi { + use TerminalTrait; /** * Set the list of terminals available for the user * @@ -131,7 +133,7 @@ public function setConfig(array $config) protected function configureOptions(OptionsResolver $resolver) { $resolver->setRequired(['terminals']); - $resolver->setDefined(['session_id', 'shop_orderid', 'amount', 'currency', 'config']); + $resolver->setDefined(['session_id', 'shop_orderid', 'amount', 'currency', 'config', 'terminal']); $resolver->addAllowedTypes('terminals', 'array'); $resolver->addAllowedTypes('session_id', 'string'); $resolver->addAllowedTypes('shop_orderid', 'string'); From d07aa6762200bea9621e89c5dba54f15198bc3f0 Mon Sep 17 00:00:00 2001 From: Shahbaz Date: Fri, 8 May 2026 10:57:03 +0500 Subject: [PATCH 2/4] Refactor CheckoutSession to extend PaymentRequest and remove unused methods --- src/Api/Payments/CheckoutSession.php | 150 +-------------------------- 1 file changed, 4 insertions(+), 146 deletions(-) diff --git a/src/Api/Payments/CheckoutSession.php b/src/Api/Payments/CheckoutSession.php index ac0edc4..d466ab9 100644 --- a/src/Api/Payments/CheckoutSession.php +++ b/src/Api/Payments/CheckoutSession.php @@ -23,22 +23,15 @@ namespace Altapay\Api\Payments; -use Altapay\AbstractApi; -use Altapay\Exceptions\ClientException; -use Altapay\Exceptions\ResponseHeaderException; -use Altapay\Exceptions\ResponseMessageException; -use Altapay\Serializer\ResponseSerializer; +use Altapay\Api\Ecommerce\PaymentRequest; use Altapay\Response\CheckoutSessionResponse; -use Altapay\Traits\TerminalTrait; -use GuzzleHttp\Exception\ClientException as GuzzleHttpClientException; -use GuzzleHttp\Exception\GuzzleException; +use Altapay\Serializer\ResponseSerializer; use GuzzleHttp\Psr7\Request; use Psr\Http\Message\ResponseInterface; use Symfony\Component\OptionsResolver\OptionsResolver; -class CheckoutSession extends AbstractApi +class CheckoutSession extends PaymentRequest { - use TerminalTrait; /** * Set the list of terminals available for the user * @@ -53,76 +46,6 @@ public function setTerminals(array $terminals) return $this; } - /** - * Set optional session identifier - * - * @param string $sessionId - * - * @return $this - */ - public function setSessionId($sessionId) - { - $this->unresolvedOptions['session_id'] = $sessionId; - - return $this; - } - - /** - * Set shop order ID - * - * @param string $shopOrderId - * - * @return $this - */ - public function setShopOrderId($shopOrderId) - { - $this->unresolvedOptions['shop_orderid'] = $shopOrderId; - - return $this; - } - - /** - * Set amount - * - * @param float $amount - * - * @return $this - */ - public function setAmount($amount) - { - $this->unresolvedOptions['amount'] = $amount; - - return $this; - } - - /** - * Set currency - * - * @param string $currency - * - * @return $this - */ - public function setCurrency($currency) - { - $this->unresolvedOptions['currency'] = $currency; - - return $this; - } - - /** - * Set config parameters - * - * @param array $config - * - * @return $this - */ - public function setConfig(array $config) - { - $this->unresolvedOptions['config'] = $config; - - return $this; - } - /** * Configure options * @@ -132,14 +55,9 @@ public function setConfig(array $config) */ protected function configureOptions(OptionsResolver $resolver) { + parent::configureOptions($resolver); $resolver->setRequired(['terminals']); - $resolver->setDefined(['session_id', 'shop_orderid', 'amount', 'currency', 'config', 'terminal']); $resolver->addAllowedTypes('terminals', 'array'); - $resolver->addAllowedTypes('session_id', 'string'); - $resolver->addAllowedTypes('shop_orderid', 'string'); - $resolver->addAllowedTypes('amount', ['int', 'float']); - $resolver->addAllowedTypes('currency', 'string'); - $resolver->addAllowedTypes('config', 'array'); } /** @@ -159,17 +77,6 @@ protected function handleResponse(Request $request, ResponseInterface $response) return ResponseSerializer::serialize(CheckoutSessionResponse::class, $xml->Body, $xml->Header); } - /** - * @return array - */ - protected function getBasicHeaders() - { - $headers = parent::getBasicHeaders(); - $headers['Content-Type'] = 'application/x-www-form-urlencoded'; - - return $headers; - } - /** * Url to api call * @@ -181,53 +88,4 @@ protected function getUrl(array $options) { return 'checkoutSession'; } - - /** - * @return string - */ - protected function getHttpMethod() - { - return 'POST'; - } - - /** - * Generate the response - * - * @throws \Exception - * @throws ClientException - * @throws GuzzleException - * @throws ResponseHeaderException - * @throws ResponseMessageException - */ - protected function doResponse() - { - $this->doConfigureOptions(); - $headers = $this->getBasicHeaders(); - $request = new Request( - $this->getHttpMethod(), - $this->parseUrl(), - $headers, - $this->getPostOptions() - ); - $this->request = $request; - - try { - $response = $this->getClient()->send($request); - $this->response = $response; - $output = $this->handleResponse($request, $response); - $this->validateResponse($output); - - return $output; - } catch (GuzzleHttpClientException $e) { - throw new ClientException($e->getMessage(), $e->getRequest(), $e->getResponse(), $e); - } - } - - /** - * @return string - */ - protected function getPostOptions() - { - return http_build_query($this->options, '', '&'); - } } From 2f261befce0931db7fc790c7d4635be6f9304ff2 Mon Sep 17 00:00:00 2001 From: Shahbaz Date: Fri, 8 May 2026 11:16:40 +0500 Subject: [PATCH 3/4] Change CheckoutSessionResponse to extend PaymentRequestResponse --- src/Response/CheckoutSessionResponse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Response/CheckoutSessionResponse.php b/src/Response/CheckoutSessionResponse.php index cc4544a..2b6e39b 100644 --- a/src/Response/CheckoutSessionResponse.php +++ b/src/Response/CheckoutSessionResponse.php @@ -25,7 +25,7 @@ use Altapay\Response\Embeds\Session; -class CheckoutSessionResponse extends AbstractResponse +class CheckoutSessionResponse extends PaymentRequestResponse { /** * Children of the response From 76e9da42d2abb8b88b957c94f2402f0c2c6cd66a Mon Sep 17 00:00:00 2001 From: Shahbaz Date: Fri, 8 May 2026 11:23:05 +0500 Subject: [PATCH 4/4] Update release notes --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c34731c..93d7820 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [3.5.9] - 2026-05-04 +## [3.5.9] - 2026-05-08 ### Added -- Allow setting the terminal using `checkoutSession`. +- Refactor `checkoutSession` to extend `PaymentRequest` to enable support for all standard payment parameters. ## [3.5.8] - 2026-02-23 ### Added