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
10 changes: 0 additions & 10 deletions .github/workflows/code-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,4 @@ jobs:
uses: StephaneBour/actions-php-lint@7.4
with:
dir: './src'

- name: Install PHP 5.6
uses: shivammathur/setup-php@v2
with:
php-version: '5.6'

- name: Run Linter for PHP5.6
uses: StephaneBour/actions-php-lint@5.6
with:
dir: './src'

8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ 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.1] - 2025-06-11
### Added
- Improve type hinting.
- Improve return type annotations for better type clarity.
- Improve error handling by validating error message types.
- Add null check before setting the User-Agent header.
- Restrict supported PHP versions to 7.0 and above.

## [3.5.0] - 2025-05-12
### Added
- Make billing and shipping address optional for Customer Info
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ try {

## Requirements

The AltaPay API PHP requires PHP 5.6.0 or greater with the following extensions installed:
The AltaPay API PHP requires PHP 7.0.0 or greater with the following extensions installed:

- date
- filter
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
]
},
"require": {
"php": "^5.6 || ^7.0 || ^8.0",
"php": "^7.0 || ^8.0",
"ext-date": "*",
"ext-filter": "*",
"ext-mbstring": "*",
Expand All @@ -37,7 +37,7 @@
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0",
"fzaninotto/faker": "^1.6",
"phpstan/phpstan": "^1.8",
"phpstan/phpstan": "^2.1",
"phpstan/phpstan-phpunit": "*",
"phpstan/phpstan-strict-rules": "*",
"phpunit/phpunit": "^7.0 || ^8.0 || ^9.0"
Expand Down
27 changes: 16 additions & 11 deletions 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.0';
const PHP_API_VERSION = '3.5.1';

/**
* Event dispatcher
Expand Down Expand Up @@ -128,7 +128,7 @@ abstract protected function configureOptions(OptionsResolver $resolver);
* @param Request $request
* @param ResponseInterface $response
*
* @return AbstractResponse|string|array<Transaction>
* @return AbstractResponse|string|list<Transaction>
*/
abstract protected function handleResponse(Request $request, ResponseInterface $response);

Expand Down Expand Up @@ -157,7 +157,7 @@ public function __construct(Authentication $authentication)
/**
* Generate the response
*
* @return AbstractResponse|string|array<Transaction>
* @return AbstractResponse|string|list<Transaction>
* @throws GuzzleException
* @throws ResponseHeaderException
* @throws ResponseMessageException
Expand Down Expand Up @@ -233,7 +233,9 @@ protected function doConfigureOptions()
$this->setCustomerInfoResolver($resolver);
$this->setValidationUrlResolver($resolver);
$this->setAppleDomainResolver($resolver);
$this->options = $resolver->resolve($this->unresolvedOptions);
/** @var array<string, mixed> */
$options = $resolver->resolve($this->unresolvedOptions);
$this->options = $options;
}

/**
Expand All @@ -253,13 +255,13 @@ protected function validateResponse($response)
}

if (property_exists($response, 'MerchantErrorMessage')) {
if ($response->MerchantErrorMessage) {
if ($response->MerchantErrorMessage && is_string($response->MerchantErrorMessage)) {
throw new Exceptions\ResponseMessageException($response->MerchantErrorMessage);
}
}

if (property_exists($response, 'CardHolderErrorMessage') && property_exists($response, 'CardHolderMessageMustBeShown')) {
if ($response->CardHolderMessageMustBeShown) {
if ($response->CardHolderMessageMustBeShown && is_string($response->CardHolderErrorMessage)) {
throw new Exceptions\ResponseMessageException($response->CardHolderErrorMessage);
}
}
Expand All @@ -268,7 +270,7 @@ protected function validateResponse($response)
/**
* Generate the response
*
* @return AbstractResponse|string|array<Transaction>
* @return AbstractResponse|string|list<Transaction>
* @throws GuzzleException
* @throws ClientException
* @throws ResponseHeaderException
Expand Down Expand Up @@ -318,7 +320,7 @@ protected function parseUrl()
/**
* Get User Agent details
*
* @return string
* @return ?string
*/
protected function getUserAgent()
{
Expand All @@ -328,14 +330,14 @@ protected function getUserAgent()
$userAgent = 'api-php/' . self::PHP_API_VERSION;
if (extension_loaded('curl') && function_exists('curl_version')) {
$curlInfo = \curl_version();
if (is_array($curlInfo) && array_key_exists("version", $curlInfo)) {
if (is_array($curlInfo) && array_key_exists("version", $curlInfo) && is_string($curlInfo["version"])) {
$userAgent .= ' curl/' . $curlInfo["version"];
}
}
$userAgent .= ' PHP/' . PHP_VERSION;
}

return $userAgent;
return is_string($userAgent) ? $userAgent : null;
}

/**
Expand Down Expand Up @@ -380,7 +382,10 @@ protected function getBasicHeaders()
);
}

$headers['User-Agent'] = $this->getUserAgent();
$userAgen = $this->getUserAgent();
if ($userAgen) {
$headers['User-Agent'] = $userAgen;
}

return $headers;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Api/Ecommerce/PaymentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,10 @@ protected function configureOptions(OptionsResolver $resolver)
$resolver->setAllowedValues('language', Types\LanguageTypes::getAllowed());
$resolver->setDefault('type', 'payment');
$resolver->setAllowedValues('type', Types\PaymentTypes::getAllowed());
$resolver->setAllowedValues('sale_reconciliation_identifier', function ($value) {
$resolver->setAllowedValues('sale_reconciliation_identifier', function (string $value) {
return mb_strlen($value) <= 100;
});
$resolver->setAllowedValues('sale_invoice_number', function ($value) {
$resolver->setAllowedValues('sale_invoice_number', function (string $value) {
return mb_strlen($value) <= 100;
});
$resolver->setAllowedTypes('sales_tax', ['int', 'float']);
Expand All @@ -320,7 +320,7 @@ protected function configureOptions(OptionsResolver $resolver)
$resolver->setNormalizer('config', function (Options $options, Config $value) {
return $value->serialize();
});
$resolver->setAllowedValues('organisation_number', function ($value) {
$resolver->setAllowedValues('organisation_number', function (string $value) {
return mb_strlen($value) <= 20;
});
$resolver->setAllowedTypes('account_offer', 'bool');
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Others/Payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ protected function configureOptions(OptionsResolver $resolver)
* @param Request $request
* @param ResponseInterface $response
*
* @return Transaction[]
* @return list<Transaction>
* @throws \Exception
*/
protected function handleResponse(Request $request, ResponseInterface $response)
Expand Down
6 changes: 3 additions & 3 deletions src/Api/Payments/CardWalletAuthorize.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,10 @@ protected function configureOptions(OptionsResolver $resolver)
$resolver->setAllowedValues('language', Types\LanguageTypes::getAllowed());
$resolver->setDefault('type', 'payment');
$resolver->setAllowedValues('type', Types\PaymentTypes::getAllowed());
$resolver->setAllowedValues('sale_reconciliation_identifier', function ($value) {
$resolver->setAllowedValues('sale_reconciliation_identifier', function (string $value) {
return mb_strlen($value) <= 100;
});
$resolver->setAllowedValues('sale_invoice_number', function ($value) {
$resolver->setAllowedValues('sale_invoice_number', function (string $value) {
return mb_strlen($value) <= 100;
});
$resolver->setAllowedTypes('sales_tax', ['int', 'float']);
Expand All @@ -305,7 +305,7 @@ protected function configureOptions(OptionsResolver $resolver)
$resolver->setNormalizer('config', function (Options $options, Config $value) {
return $value->serialize();
});
$resolver->setAllowedValues('organisation_number', function ($value) {
$resolver->setAllowedValues('organisation_number', function (string $value) {
return mb_strlen($value) <= 20;
});
$resolver->setAllowedTypes('account_offer', 'bool');
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Payments/ReservationOfFixedAmount.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ protected function configureOptions(OptionsResolver $resolver)
return $value->serialize();
});
$resolver->setAllowedTypes('surcharge', ['int', 'float']);
$resolver->setAllowedValues('sale_invoice_number', function ($value) {
$resolver->setAllowedValues('sale_invoice_number', function (string $value) {
return mb_strlen($value) <= 100;
});
$resolver->setNormalizer('cardnum', function (Options $options, $value) {
Expand Down
4 changes: 2 additions & 2 deletions src/Request/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -841,11 +841,11 @@ public function serialize()
}

if ($this->clientJavascriptEnabled !== null) {
$output['client_javascript_enabled'] = $this->clientJavascriptEnabled;
$output['client_javascript_enabled'] = (string)$this->clientJavascriptEnabled;
}

if ($this->clientJavaEnabled !== null) {
$output['client_java_enabled'] = $this->clientJavaEnabled;
$output['client_java_enabled'] = (string)$this->clientJavaEnabled;
}

if ($this->clientColorDepth) {
Expand Down
2 changes: 1 addition & 1 deletion src/Request/OrderLine.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

class OrderLine extends AbstractSerializer
{
/** @var array<int, string> */
/** @var list<string> */
private static $goodsTypes = [
'shipment',
'handling',
Expand Down
4 changes: 2 additions & 2 deletions src/Serializer/ResponseSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static function serialize(
* @param \SimpleXMLElement $data
* @param string $childKey
*
* @return array<int, T>
* @return list<T>
* @throws \InvalidArgumentException
*/
public static function serializeChildren(
Expand All @@ -72,7 +72,7 @@ public static function serializeChildren(
) {
$documents = [];

if (! empty($data) && ! empty($data->{$childKey})) {
if (! empty($data) && ! empty($data->{$childKey}) && $data->{$childKey} instanceof \SimpleXMLElement) {
foreach ($data->{$childKey} as $d) {
$object = new $objectName();
$documents[] = $object->deserialize($d);
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/CsvToArrayTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ trait CsvToArrayTrait
*
* @param bool $includeHeader
*
* @return array<int, array<int, string|null>>
* @return list<list<string|null>>
*/
public function __toArray($includeHeader = false)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/CurrencyTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function setCurrency($currency)
protected function setCurrencyResolver(OptionsResolver $resolver)
{
$resolver->setAllowedTypes('currency', ['string', 'int']);
$resolver->setAllowedValues('currency', function ($value) {
$resolver->setAllowedValues('currency', function (string $value) {
return CurrencyTypes::currencyCodeExists($value) || CurrencyTypes::currencyNumberExists($value);
});
}
Expand Down
23 changes: 10 additions & 13 deletions src/Traits/OrderlinesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,6 @@ public function setOrderLines($orderLines)
}

if (is_array($orderLines)) {
foreach ($orderLines as $orderLine) {
if (!$orderLine instanceof OrderLine) {
throw new \InvalidArgumentException(
sprintf(
'orderLines should all be a instance of "%s"',
OrderLine::class
)
);
}
}

$this->unresolvedOptions['orderLines'] = $orderLines;
}

Expand All @@ -68,10 +57,18 @@ protected function setOrderLinesResolver(OptionsResolver $resolver)
{
$resolver->addAllowedTypes('orderLines', 'array');
/** @noinspection PhpUnusedParameterInspection */
$resolver->setNormalizer('orderLines', function (Options $options, $value) {
$resolver->setNormalizer('orderLines', function (Options $options, array $value) {
$output = [];
/** @var OrderLine $object */
foreach ($value as $object) {
if (!$object instanceof OrderLine) {
throw new \InvalidArgumentException(
sprintf(
'orderLines should all be a instance of "%s"',
OrderLine::class
)
);
}

$output[] = $object->serialize();
}
return $output;
Expand Down
4 changes: 2 additions & 2 deletions src/Types/FraudServices.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class FraudServices implements TypeInterface
/**
* Allowed fraud services
*
* @var array<int, string>
* @var list<string>
*/
private static $services = [
'none',
Expand All @@ -43,7 +43,7 @@ class FraudServices implements TypeInterface
/**
* Get allowed values
*
* @return array<int, string>
* @return list<string>
*/
public static function getAllowed()
{
Expand Down
4 changes: 2 additions & 2 deletions src/Types/LanguageTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class LanguageTypes implements TypeInterface
* nb, nn will be converted to no.
* ee will be converted to et
*
* @var array<int, string>
* @var list<string>
*/
private static $languages = [
'br', 'ca', 'cs', 'cy', 'da', 'de', 'el', 'en', 'es', 'fi', 'fr', 'hr', 'hu', 'is', 'ja',
Expand All @@ -41,7 +41,7 @@ class LanguageTypes implements TypeInterface
/**
* Get allowed values
*
* @return array<int, string>
* @return list<string>
*/
public static function getAllowed()
{
Expand Down
4 changes: 2 additions & 2 deletions src/Types/PaymentSources.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class PaymentSources implements TypeInterface
/**
* Allowed payment sources
*
* @var array<int, string>
* @var list<string>
*/
private static $sources = [
'eCommerce',
Expand All @@ -44,7 +44,7 @@ class PaymentSources implements TypeInterface
/**
* Get allowed values
*
* @return array<int, string>
* @return list<string>
*/
public static function getAllowed()
{
Expand Down
4 changes: 2 additions & 2 deletions src/Types/PaymentTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class PaymentTypes implements TypeInterface
/**
* Allowed payment types
*
* @var array<int, string>
* @var list<string>
*/
private static $types = [
'payment',
Expand All @@ -45,7 +45,7 @@ class PaymentTypes implements TypeInterface
/**
* Get allowed values
*
* @return array<int, string>
* @return list<string>
*/
public static function getAllowed()
{
Expand Down
Loading