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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
},
"files": [
"./src/Resources/functions/text.php",
"./src/Resources/functions/vat.php"
"./src/Resources/functions/vat.php",
"./src/Resources/functions/misc.php"
]
},
"autoload-dev": {
Expand Down
24 changes: 12 additions & 12 deletions src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
*/
class Config implements Countable, Iterator, ArrayAccess
{
protected const TGU1 = 'https://connect.pay.nl';
protected const TGU2 = 'https://connect.payments.nl';
protected const TGU3 = 'https://connect.achterelkebetaling.nl';
public const TGU1 = 'https://connect.pay.nl';
public const TGU2 = 'https://connect.payments.nl';
public const TGU3 = 'https://connect.achterelkebetaling.nl';

protected array $data = [];
private static Config $configObject;
Expand Down Expand Up @@ -70,7 +70,7 @@ public function get(mixed $key, mixed $default = null)
* @param string|integer $key
* @return mixed|null
*/
public function __get($key) // phpcs:ignore
public function __get(string|int $key)
{
return $this->get($key);
}
Expand All @@ -94,7 +94,7 @@ public function set(mixed $key, mixed $value): void
* @param mixed $value
* @return void
*/
public function __set($key, $value): void // phpcs:ignore
public function __set(mixed $key, mixed $value): void
{
$this->set($key, $value);
}
Expand All @@ -104,7 +104,7 @@ public function __set($key, $value): void // phpcs:ignore
*
* @return void
*/
public function remove($key): void
public function remove(string|int $key): void
{
if (true === $this->has($key)) {
unset($this->data[$key]);
Expand All @@ -116,7 +116,7 @@ public function remove($key): void
*
* @return void
*/
public function __unset($key): void
public function __unset(string|int $key): void
{
$this->remove($key);
}
Expand All @@ -126,7 +126,7 @@ public function __unset($key): void
*
* @return boolean
*/
public function has($key): bool
public function has(string|int $key): bool
{
return isset($this->data[$key]);
}
Expand All @@ -136,7 +136,7 @@ public function has($key): bool
*
* @return boolean
*/
public function __isset($key): bool
public function __isset(string|int $key): bool
{
return $this->has($key);
}
Expand Down Expand Up @@ -209,7 +209,7 @@ public function rewind(): void
* @param mixed $offset
* @return boolean
*/
public function offsetExists($offset): bool // phpcs:ignore
public function offsetExists(mixed $offset): bool
{
return $this->has($offset);
}
Expand All @@ -228,7 +228,7 @@ public function offsetGet(mixed $offset): mixed
* @param mixed $value
* @return void
*/
public function offsetSet($offset, $value): void // phpcs:ignore
public function offsetSet(mixed $offset, mixed $value): void
{
$this->set($offset, $value);
}
Expand All @@ -237,7 +237,7 @@ public function offsetSet($offset, $value): void // phpcs:ignore
* @param mixed $offset
* @return void
*/
public function offsetUnset($offset): void // phpcs:ignore
public function offsetUnset(mixed $offset): void
{
$this->remove($offset);
}
Expand Down
10 changes: 10 additions & 0 deletions src/Model/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,16 @@ public function setDeliveryAddress(Address $deliveryAddress): self
return $this;
}

/**
* Alias for setDeliveryAddress
* @param Address $shippingAddress
* @return $this
*/
public function setShippingAddress(Address $shippingAddress): self
{
return $this->setDeliveryAddress($shippingAddress);
}

/**
* @return Address
*/
Expand Down
30 changes: 30 additions & 0 deletions src/Resources/functions/misc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

use PayNL\Sdk\Util\Misc;

if (false === function_exists('paynl_split_address')) {
/**
* @param string $address
*
* @return array
*/
function paynl_split_address(string $address): array
{
return (new Misc())->splitAddress($address);
}
}

if (false === function_exists('paynl_get_ip')) {
/**
* @param string $address
*
* @return array
*/
function paynl_get_ip(): array
{
return (new Misc())->getIp();
}
}

13 changes: 0 additions & 13 deletions src/Resources/functions/text.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,6 @@

use PayNL\Sdk\Util\Text;

if (false === function_exists('paynl_split_address')) {
/**
* @param string $address
*
* @return array
*/
function paynl_split_address(string $address): array
{
return (new Text())->splitAddress($address);
}
}


if (false === function_exists('dbg')) {
/**
* @param string $message
Expand Down
2 changes: 1 addition & 1 deletion src/Util/Exchange.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function getPayLoad()
throw new Exception('Empty payload', 8002);
}

$tguData = json_decode($rawBody, true, 512, 4194304);
$tguData = json_decode($rawBody, true, 512, JSON_BIGINT_AS_STRING);

$exchangeType = $tguData['type'] ?? null;
if ($exchangeType != 'order') {
Expand Down
65 changes: 61 additions & 4 deletions src/Util/Misc.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ class Misc
/**
* @param string $file
*
* @throws InvalidArgumentException when given file can not be found or read
* @return string
* @throws LogicException when the class name is not the same as the terminating class file name
* (PSR-4 3.3 - https://www.php-fig.org/psr/psr-4/)
*
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
* @return string
* @throws InvalidArgumentException when given file can not be found or read
*/
public static function getClassNameByFile(string $file): string
{
Expand Down Expand Up @@ -73,9 +73,9 @@ public static function getClassNameByFile(string $file): string
}

if ($tokens[$counter][0] === T_CLASS) {
for ($nextCounter = $counter+1; $nextCounter < $tokenCount; $nextCounter++) {
for ($nextCounter = $counter + 1; $nextCounter < $tokenCount; $nextCounter++) {
if ($tokens[$nextCounter] === '{') {
$class = $tokens[$counter+2][1];
$class = $tokens[$counter + 2][1];
}
}
}
Expand Down Expand Up @@ -107,4 +107,61 @@ public static function getClassNameByFQN(string $fqn): string
$parts = explode($namespaceSeparator, $fqn);
return array_pop($parts) ?? '';
}

/**
* Get the IP of the user
*
* @return mixed
*/
public function getIp()
{
// Use $_SERVER or get the headers if we can
$headers = $_SERVER;
if (function_exists('apache_request_headers')) {
$headers = apache_request_headers();
}

// Get the forwarded IP if it exists
$the_ip = $_SERVER['REMOTE_ADDR'];
if (array_key_exists('X-Forwarded-For', $headers)) {
$the_ip = $headers['X-Forwarded-For'];
} elseif (array_key_exists('HTTP_X_FORWARDED_FOR', $headers)) {
$the_ip = $headers['HTTP_X_FORWARDED_FOR'];
}
$arrIp = explode(',', $the_ip);

return filter_var(trim(trim(!empty($arrIp[0]) ? $arrIp[0] : ''), '[]'), FILTER_VALIDATE_IP);
}

/**
* @param string $address
*
* @return array
*/
public function splitAddress(string $address): array
{
$street = $number = '';

$address = trim($address);
$addressParts = preg_split('/(\s+)(\d+)/', $address, 2, PREG_SPLIT_DELIM_CAPTURE);

if (true === is_array($addressParts)) {
$street = trim(array_shift($addressParts) ?? '');
$number = trim(implode('', $addressParts));
}

if (true === empty($street) || true === empty($number)) {
$addressParts = preg_split('/([A-z]{2,})/', $address, 2, PREG_SPLIT_DELIM_CAPTURE);

if (true === is_array($addressParts)) {
$number = trim(array_shift($addressParts) ?? '');
$street = trim(implode('', $addressParts));
}
}

$number = substr($number, 0, 45);

return compact('street', 'number');
}

}
32 changes: 0 additions & 32 deletions src/Util/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,6 @@
*/
class Text
{


/**
* @param string $address
*
* @return array
*/
public function splitAddress(string $address): array
{
$street = $number = '';

$address = trim($address);
$addressParts = preg_split('/(\s+)(\d+)/', $address, 2, PREG_SPLIT_DELIM_CAPTURE);

if (true === is_array($addressParts)) {
$street = trim(array_shift($addressParts) ?? '');
$number = trim(implode('', $addressParts));
}

if (true === empty($street) || true === empty($number)) {
$addressParts = preg_split('/([A-z]{2,})/', $address, 2, PREG_SPLIT_DELIM_CAPTURE);

if (true === is_array($addressParts)) {
$number = trim(array_shift($addressParts) ?? '');
$street = trim(implode('', $addressParts));
}
}

$number = substr($number, 0, 45);

return compact('street', 'number');
}

/**
* @param $errorMessage
Expand Down