Skip to content
Open
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.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.
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.9';
const PHP_API_VERSION = '3.6.0';

/**
* Event dispatcher
Expand Down
16 changes: 15 additions & 1 deletion src/Api/Payments/CardWalletAuthorize.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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');
}

/**
Expand Down
122 changes: 30 additions & 92 deletions src/Api/Payments/CardWalletSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> $applePayRequestData
*
* @return $this
*/
public function setDomain($identifier)
public function setApplePayRequestData(array $applePayRequestData)
{
$this->unresolvedOptions['domain'] = $identifier;
$this->unresolvedOptions['applePayRequestData'] = $applePayRequestData;

return $this;
}
Expand All @@ -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<string, string>
*/
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);
}

/**
Expand All @@ -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';
}
}
51 changes: 51 additions & 0 deletions src/Response/CardWalletSessionResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* Copyright (c) 2026 AltaPay
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

namespace Altapay\Response;

use Altapay\Response\Embeds\WalletData;
use Altapay\Response\Embeds\Transaction;

class CardWalletSessionResponse extends PaymentRequestResponse
{
/**
* Children of the response
*
* @var array<string, array<string, mixed>>
*/
protected $childs = [
'Transactions' => [
'class' => Transaction::class,
'array' => 'Transaction'
],
'WalletData' => [
'class' => WalletData::class,
'array' => false
],
];

/**
* @var WalletData|null
*/
public $WalletData = null;
}
34 changes: 34 additions & 0 deletions src/Response/Embeds/WalletData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* Copyright (c) 2026 AltaPay
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

namespace Altapay\Response\Embeds;

use Altapay\Response\AbstractResponse;

class WalletData extends AbstractResponse
{
/**
* @var string
*/
public $Session;
}
Loading