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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 15 additions & 10 deletions src/AbstractApi.php
Original file line number Diff line number Diff line change
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
15 changes: 2 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,10 @@ 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) {
assert($object instanceof OrderLine);
$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
4 changes: 2 additions & 2 deletions src/Types/SelectedSchemes.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SelectedSchemes implements TypeInterface
/**
* Allowed selected schemes
*
* @var array<int, string>
* @var list<string>
*/
private static $schemes = [
'VISA',
Expand All @@ -51,7 +51,7 @@ class SelectedSchemes 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/ShippingMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ShippingMethods implements TypeInterface
/**
* Allowed payment types
*
* @var array<int, string>
* @var list<string>
*/
private static $types = [
'LowCost',
Expand All @@ -45,7 +45,7 @@ class ShippingMethods implements TypeInterface
/**
* Get allowed values
*
* @return array<int, string>
* @return list<string>
*/
public static function getAllowed()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Types/TypeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface TypeInterface
/**
* Get allowed values
*
* @return array<int, string>
* @return list<string>
*/
public static function getAllowed();

Expand Down
1 change: 0 additions & 1 deletion tests/Api/CallbackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ public function test_can_handle_callback(): void
{
$call = new Callback($this->data);
$response = $call->call();
$this->assertInstanceOf(CallbackResponse::class, $response);
$this->assertSame('d28df6b4-122d-49e2-add0-19c8271260b0', $response->paymentId);
$this->assertSame('000000022', $response->shopOrderId);
$this->assertSame('incomplete', $response->status);
Expand Down
1 change: 0 additions & 1 deletion tests/Api/CaptureReservationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public function test_capture_reservation_transactions_data(): void
$response = $api->call();
$this->assertInstanceOf(CaptureReservationResponse::class, $response);
$transaction = $response->Transactions[0];
$this->assertInstanceOf(Transaction::class, $transaction);
$this->assertSame('1', $transaction->TransactionId);
$this->assertSame('978', $transaction->MerchantCurrency);
$this->assertSame(13.37, $transaction->FraudRiskScore);
Expand Down
2 changes: 1 addition & 1 deletion tests/Api/CreditTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function test_creditcardtoken_options(): void
}

/**
* @return array<int, array<int, string>>
* @return list<list<string>>
*/
public function paymentSourceDataProvider()
{
Expand Down
Loading