diff --git a/CHANGELOG.md b/CHANGELOG.md index c998713..efbf652 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.8] - 2026-02-23 +### Added +- Add support for `checkoutSession` API method. + ## [3.5.7] - 2025-11-24 ### Added - Add option to use `transaction_info` for `captureReservation`, `refundCapturedReservation` and `updateOrder/{id}/reconciliationIdentifier`. diff --git a/sonar-project.properties b/sonar-project.properties index 6921e39..ed263d1 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,3 +1,7 @@ sonar.projectKey=AltaPay_api-php_90804e1e-91c4-43f6-a024-51f03ac0e4e8 sonar.projectBaseDir=src sonar.coverage.exclusions=** +# Ignore Sonar rule: Property names should match ^[a-z][a-zA-Z0-9]*$ +sonar.issue.ignore.multicriteria=e1 +sonar.issue.ignore.multicriteria.e1.ruleKey=php:S116 +sonar.issue.ignore.multicriteria.e1.resourceKey=**/*.php diff --git a/src/AbstractApi.php b/src/AbstractApi.php index 23a4e4e..e415c70 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.7'; + const PHP_API_VERSION = '3.5.8'; /** * Event dispatcher diff --git a/src/Api/Ecommerce/PaymentRequest.php b/src/Api/Ecommerce/PaymentRequest.php index 75849b5..cb41a40 100644 --- a/src/Api/Ecommerce/PaymentRequest.php +++ b/src/Api/Ecommerce/PaymentRequest.php @@ -284,6 +284,20 @@ public function setFormTemplate($formTemplate) return $this; } + /** + * Set the session_id to the Payment Request. + * + * @param string $sessionId + * + * @return $this + */ + public function setSessionId($sessionId) + { + $this->unresolvedOptions['session_id'] = $sessionId; + + return $this; + } + /** * Configure options * @@ -314,7 +328,8 @@ protected function configureOptions(OptionsResolver $resolver) 'account_offer', 'orderLines', 'extra_merchant_data', - 'form_template' + 'form_template', + 'session_id', ]); $resolver->setAllowedValues('language', Types\LanguageTypes::getAllowed()); diff --git a/src/Api/Payments/CheckoutSession.php b/src/Api/Payments/CheckoutSession.php new file mode 100644 index 0000000..36dbc7b --- /dev/null +++ b/src/Api/Payments/CheckoutSession.php @@ -0,0 +1,231 @@ + $terminals + * + * @return $this + */ + public function setTerminals(array $terminals) + { + $this->unresolvedOptions['terminals'] = $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 + * + * @param OptionsResolver $resolver + * + * @return void + */ + protected function configureOptions(OptionsResolver $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'); + } + + /** + * Handle response + * + * @param Request $request + * @param ResponseInterface $response + * + * @return CheckoutSessionResponse + * @throws \Exception + */ + protected function handleResponse(Request $request, ResponseInterface $response) + { + $body = (string)$response->getBody(); + $xml = new \SimpleXMLElement($body); + + 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 + * + * @param array $options Resolved options + * + * @return string + */ + 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 new file mode 100644 index 0000000..cc4544a --- /dev/null +++ b/src/Response/CheckoutSessionResponse.php @@ -0,0 +1,46 @@ +> + */ + protected $childs = [ + 'Session' => [ + 'class' => Session::class, + 'array' => false + ], + ]; + + /** + * @var Session + */ + public $Session; +} diff --git a/src/Response/Embeds/Session.php b/src/Response/Embeds/Session.php new file mode 100644 index 0000000..0efd97a --- /dev/null +++ b/src/Response/Embeds/Session.php @@ -0,0 +1,39 @@ +