Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
148 changes: 4 additions & 144 deletions src/Api/Payments/CheckoutSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<string, mixed> $config
*
* @return $this
*/
public function setConfig(array $config)
{
$this->unresolvedOptions['config'] = $config;

return $this;
}

/**
* Configure options
*
Expand All @@ -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');
}

/**
Expand All @@ -157,17 +77,6 @@ protected function handleResponse(Request $request, ResponseInterface $response)
return ResponseSerializer::serialize(CheckoutSessionResponse::class, $xml->Body, $xml->Header);
}

/**
* @return array<string, string>
*/
protected function getBasicHeaders()
{
$headers = parent::getBasicHeaders();
$headers['Content-Type'] = 'application/x-www-form-urlencoded';

return $headers;
}

/**
* Url to api call
*
Expand All @@ -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, '', '&');
}
}
2 changes: 1 addition & 1 deletion src/Response/CheckoutSessionResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

use Altapay\Response\Embeds\Session;

class CheckoutSessionResponse extends AbstractResponse
class CheckoutSessionResponse extends PaymentRequestResponse
{
/**
* Children of the response
Expand Down
Loading