diff --git a/CHANGELOG.md b/CHANGELOG.md index efbf652..93d7820 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-08 +### Added +- Refactor `checkoutSession` to extend `PaymentRequest` to enable support for all standard payment parameters. + ## [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..d466ab9 100644 --- a/src/Api/Payments/CheckoutSession.php +++ b/src/Api/Payments/CheckoutSession.php @@ -23,19 +23,14 @@ 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 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 { /** * Set the list of terminals available for the user @@ -51,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 * @@ -130,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']); $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'); } /** @@ -157,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 * @@ -179,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, '', '&'); - } } 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