diff --git a/CHANGELOG.md b/CHANGELOG.md index 93d7820..d7b502c 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.6.0] - 2026-05-22 +### Added +- Add support for new parameters in `cardWallet/session` and `cardWallet/authorize`. + ## [3.5.9] - 2026-05-08 ### Added - Refactor `checkoutSession` to extend `PaymentRequest` to enable support for all standard payment parameters. diff --git a/src/AbstractApi.php b/src/AbstractApi.php index 3a3a239..6c7083f 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.9'; + const PHP_API_VERSION = '3.6.0'; /** * Event dispatcher diff --git a/src/Api/Payments/CardWalletAuthorize.php b/src/Api/Payments/CardWalletAuthorize.php index b0c0dc6..b55cd7f 100644 --- a/src/Api/Payments/CardWalletAuthorize.php +++ b/src/Api/Payments/CardWalletAuthorize.php @@ -258,6 +258,18 @@ public function setProviderData($identifier) return $this; } + /** + * @param string $paymentId + * + * @return $this + */ + public function setPaymentId($paymentId) + { + $this->unresolvedOptions['payment_id'] = $paymentId; + + return $this; + } + /** * Configure options * @@ -285,7 +297,8 @@ protected function configureOptions(OptionsResolver $resolver) 'customer_created_date', 'shipping_method', 'organisation_number', - 'account_offer' + 'account_offer', + 'payment_id', ]); $resolver->addAllowedTypes('provider_data', 'string'); $resolver->setAllowedValues('language', Types\LanguageTypes::getAllowed()); @@ -313,6 +326,7 @@ protected function configureOptions(OptionsResolver $resolver) $resolver->setNormalizer('account_offer', function (Options $options, $value) { return $value ? 'required' : 'disabled'; }); + $resolver->addAllowedTypes('payment_id', 'string'); } /** diff --git a/src/Api/Payments/CardWalletSession.php b/src/Api/Payments/CardWalletSession.php index d670c0e..62d648a 100644 --- a/src/Api/Payments/CardWalletSession.php +++ b/src/Api/Payments/CardWalletSession.php @@ -23,44 +23,47 @@ namespace Altapay\Api\Payments; -use Altapay\AbstractApi; -use Altapay\Exceptions\ClientException; -use Altapay\Exceptions\ResponseHeaderException; -use Altapay\Exceptions\ResponseMessageException; +use Altapay\Api\Ecommerce\PaymentRequest; +use Altapay\Response\CardWalletSessionResponse; use Altapay\Serializer\ResponseSerializer; -use Altapay\Traits\TerminalTrait; -use Altapay\Response\PaymentRequestResponse; -use GuzzleHttp\Exception\ClientException as GuzzleHttpClientException; -use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\Psr7\Request; use Psr\Http\Message\ResponseInterface; use Symfony\Component\OptionsResolver\OptionsResolver; -class CardWalletSession extends AbstractApi +class CardWalletSession extends PaymentRequest { - use TerminalTrait; - /** - * @param string $identifier + * @param string $url The validation URL from the Apple Pay event * * @return $this */ - public function setValidationUrl($identifier) + public function setValidationUrl($url) { - $this->unresolvedOptions['validationUrl'] = $identifier; + $this->unresolvedOptions['validationUrl'] = $url; return $this; } /** + * @param string $domain The domain initializing the request * - * @param string $identifier + * @return $this + */ + public function setDomain($domain) + { + $this->unresolvedOptions['domain'] = $domain; + + return $this; + } + + /** + * @param array $applePayRequestData * * @return $this */ - public function setDomain($identifier) + public function setApplePayRequestData(array $applePayRequestData) { - $this->unresolvedOptions['domain'] = $identifier; + $this->unresolvedOptions['applePayRequestData'] = $applePayRequestData; return $this; } @@ -74,39 +77,30 @@ public function setDomain($identifier) */ protected function configureOptions(OptionsResolver $resolver) { - $resolver->setRequired(['terminal', 'validationUrl', 'domain']); + parent::configureOptions($resolver); + + $resolver->setDefined(['validationUrl', 'domain', 'applePayRequestData']); + $resolver->addAllowedTypes('validationUrl', 'string'); $resolver->addAllowedTypes('domain', 'string'); + $resolver->addAllowedTypes('applePayRequestData', 'array'); // validationUrl, domain, source } /** * Handle response * - * @param Request $request + * @param Request $request * @param ResponseInterface $response * - * @return PaymentRequestResponse + * @return CardWalletSessionResponse * @throws \Exception */ protected function handleResponse(Request $request, ResponseInterface $response) { $body = (string)$response->getBody(); - $xml = new \SimpleXMLElement($body); - - return ResponseSerializer::serialize(PaymentRequestResponse::class, $xml->Body, $xml->Header); - } - - /** - * @return array - */ - protected function getBasicHeaders() - { - $headers = parent::getBasicHeaders(); - if (mb_strtolower($this->getHttpMethod()) === 'post') { - $headers['Content-Type'] = 'application/x-www-form-urlencoded'; - } + $xml = new \SimpleXMLElement($body); - return $headers; + return ResponseSerializer::serialize(CardWalletSessionResponse::class, $xml->Body, $xml->Header); } /** @@ -118,62 +112,6 @@ protected function getBasicHeaders() */ protected function getUrl(array $options) { - $url = 'cardWallet/session'; - if (mb_strtolower($this->getHttpMethod()) === 'get') { - $query = $this->buildUrl($options); - $url = sprintf('%s/?%s', $url, $query); - } - - return $url; - } - - /** - * @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(); - $requestParameters = [$this->getHttpMethod(), $this->parseUrl(), $headers]; - if (mb_strtolower($this->getHttpMethod()) === 'post') { - $requestParameters[] = $this->getPostOptions(); - } - - $request = new Request(...$requestParameters); - $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() - { - $options = $this->options; - - return http_build_query($options, '', '&'); + return 'cardWallet/session'; } } diff --git a/src/Response/CardWalletSessionResponse.php b/src/Response/CardWalletSessionResponse.php new file mode 100644 index 0000000..d6ae0d9 --- /dev/null +++ b/src/Response/CardWalletSessionResponse.php @@ -0,0 +1,51 @@ +> + */ + protected $childs = [ + 'Transactions' => [ + 'class' => Transaction::class, + 'array' => 'Transaction' + ], + 'WalletData' => [ + 'class' => WalletData::class, + 'array' => false + ], + ]; + + /** + * @var WalletData|null + */ + public $WalletData = null; +} diff --git a/src/Response/Embeds/WalletData.php b/src/Response/Embeds/WalletData.php new file mode 100644 index 0000000..ef84a39 --- /dev/null +++ b/src/Response/Embeds/WalletData.php @@ -0,0 +1,34 @@ +