Skip to content

Commit

Permalink
Merge branch 'master' into update-validation
Browse files Browse the repository at this point in the history
  • Loading branch information
daanrijpkemacb authored Jun 12, 2024
2 parents 04a376f + a541d1f commit 54c718d
Show file tree
Hide file tree
Showing 9 changed files with 347 additions and 962 deletions.
7 changes: 7 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: "composer"
directory: "/"
schedule:
interval: "weekly"
open-pull-requests-limit: 10
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,14 @@ Utilized by other applications as well:
* [Appendices](#appendices)
+ [List of all supported BICs per context](#list-of-all-supported-bics-per-context)

## 2.4 is coming soon
A new version of the PHP library will be released in the coming 1-2 months.
Starting this release, **PHP 8.1** is the minimum required version for this library.

## Requirements
- Since our release >= 2.3, **PHP 8.0** is the minimum required version for this library. Previous releases requires **PHP 7.4**.
- 2024: Starting at our release >= 2.4, **PHP 8.1** is the minimum required version for this library. Previous releases requires **PHP 8.0**.
- Update April 2023: Since our release >= 2.3, **PHP 8.0** is the minimum required version for this library. Previous releases requires **PHP 7.4**.

- Please use the [major git releases](https://github.com/bluem-development/bluem-php/releases) for the stable versions of this plugin.
- Refer to the `composer.json` requirements for any other dependencies

Expand Down
2 changes: 0 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,10 @@
"phpunit/phpunit": "^9.5",
"phpspec/prophecy": "~1.0",
"vlucas/phpdotenv": "^5.4",
"roave/security-advisories": "dev-latest",
"rector/rector": "^0.15.10",
"squizlabs/php_codesniffer": "^3.7",
"magento/magento-coding-standard": "^31.0",
"phpcompatibility/php-compatibility": "^9.3"

},
"prefer-stable" : true,
"scripts": {
Expand Down
1,181 changes: 264 additions & 917 deletions composer.lock

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions src/Exceptions/InvalidBluemRequestException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* (c) 2023 - Bluem Plugin Support <pluginsupport@bluem.nl>
*
* This source file is subject to the license that is bundled
* with this source code in the file LICENSE.
*/


namespace Bluem\BluemPHP\Exceptions;

use Exception;

class InvalidBluemRequestException extends Exception
{

}
32 changes: 16 additions & 16 deletions src/Helpers/Now.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,29 @@ public function addDay(int $days): static
$this->dateTime = $this->dateTime->add(new DateInterval("P{$days}D"));
return $this;
}


/**
* @throws Exception
*/
public function fromDate(string $dateTimeString): static
{
try {
$this->dateTime = new DateTimeImmutable(
datetime: $dateTimeString,
timezone: new DateTimeZone(self::DEFAULT_TIMEZONE)
);
} catch (Exception $e) {
throw $e;
}
$this->dateTime = new DateTimeImmutable(
datetime: $dateTimeString,
timezone: new DateTimeZone(self::DEFAULT_TIMEZONE)
);

return $this;
}

/**
* @throws Exception
*/
public function fromTimestamp(string $timestamp): static
{
try {
$this->dateTime = (new DateTimeImmutable())
->setTimestamp($timestamp)
->setTimezone(new DateTimeZone(self::DEFAULT_TIMEZONE));
} catch (Exception $e) {
throw $e;
}
$this->dateTime = (new DateTimeImmutable())
->setTimestamp($timestamp)
->setTimezone(new DateTimeZone(self::DEFAULT_TIMEZONE));

return $this;
}
}
9 changes: 5 additions & 4 deletions src/Requests/BluemRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Bluem\BluemPHP\Requests;

use Bluem\BluemPHP\Exceptions\InvalidBluemRequestException;
use Bluem\BluemPHP\Helpers\BluemConfiguration;
use Bluem\BluemPHP\Helpers\Now;
use Bluem\BluemPHP\Interfaces\BluemRequestInterface;
Expand Down Expand Up @@ -81,6 +82,7 @@ class BluemRequest implements BluemRequestInterface

private array $_debtorAdditionalData = [];

private const TYPE_IDENTIFIERS = [ 'createTransaction', 'requestStatus' ];
/**
* @var string[]
*/
Expand Down Expand Up @@ -108,16 +110,15 @@ class BluemRequest implements BluemRequestInterface
*
* @param BluemConfiguration|object $config
*
* @throws Exception
* @throws InvalidBluemRequestException
*/
public function __construct(
$config,
string $entranceCode = "",
string $expectedReturn = ""
) {
$possibleTypeIdentifiers = [ 'createTransaction', 'requestStatus' ];
if (! in_array($this->typeIdentifier, $possibleTypeIdentifiers)) {
throw new Exception("Invalid transaction type called for", 1);
if (!in_array($this->typeIdentifier, self::TYPE_IDENTIFIERS, true)) {
throw new InvalidBluemRequestException("Invalid transaction type called for", 1);
}
// @todo: move to request validation class?
Expand Down
2 changes: 1 addition & 1 deletion src/Requests/IdentityBluemRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public function XmlString(): string
}

/**
* EntranceCodes for iDIN starting with the prefix 'showConsumerGui,
* EntranceCodes for iDIN starting with the prefix `showConsumerGui`,
* will always get to a test status page
* of the bank where you can choose which status you want to receive back.
*
Expand Down
51 changes: 30 additions & 21 deletions src/Requests/PaymentBluemRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace Bluem\BluemPHP\Requests;

use Bluem\BluemPHP\Contexts\PaymentsContext;
use Bluem\BluemPHP\Exceptions\InvalidBluemRequestException;
use Bluem\BluemPHP\Helpers\BluemConfiguration;
use Bluem\BluemPHP\Helpers\Now;
use Exception;
Expand All @@ -34,6 +35,7 @@ class PaymentBluemRequest extends BluemRequest
private float $amount;

/**
* @throws InvalidBluemRequestException
* @throws Exception
*/
public function __construct(
Expand All @@ -56,22 +58,7 @@ public function __construct(
// Default Currency EUR
$this->currency = $this->validateCurrency($currency);

$now = new Now();

if ($dueDateTime === null) {
$this->dueDateTime = $now->tomorrow()->getCreateDateTimeForRequest();
} else {
try {
if (is_int($dueDateTime)) {
$then = ($now->fromTimestamp($dueDateTime));
} else {
$then = ($now->fromDate($dueDateTime));
}
} catch (Exception $e) {
throw $e;
}
$this->dueDateTime = $then->getCreateDateTimeForRequest();
}
$this->dueDateTime = $this->getDueDateTime($dueDateTime);

// @todo: validate DebtorReference : [0-9a-zA-Z]{1,35}
// $sanitizedDebtorReferenceParts = [];
Expand Down Expand Up @@ -135,16 +122,16 @@ private function sanitizeTransactionID(string $transactionID): string
*
* @param $currency
*
* @throws Exception
* @return string
* @throws InvalidBluemRequestException
*/
private function validateCurrency($currency): string
{
$availableCurrencies = [ "EUR" ]; // @todo: add list of currencies based on
if (!in_array($currency, $availableCurrencies, true)) {
throw new Exception(
"Currency not recognized,
should be one of the following available currencies: " .
implode(",", $availableCurrencies)
throw new InvalidBluemRequestException(
"Currency not recognized, should be one of the following available currencies: " .
implode(",", $availableCurrencies)
);
}

Expand Down Expand Up @@ -273,6 +260,28 @@ public function setPaymentMethodToCarteBancaire(): self
return $this;
}

/**
* @param mixed $dueDateTime
* @return string
* @throws InvalidBluemRequestException
*/
public function getDueDateTime(mixed $dueDateTime): string
{
$now = new Now();

if ($dueDateTime === null) {
return $now->tomorrow()->getCreateDateTimeForRequest();
}
try {
$then = is_int($dueDateTime)
? ($now->fromTimestamp($dueDateTime))
: ($now->fromDate($dueDateTime));
return $then->getCreateDateTimeForRequest();
} catch (Exception $e) {
throw new InvalidBluemRequestException($e);
}
}

private function addZeroPrefix($number)
{
if (strlen($number.'') === 1) {
Expand Down

0 comments on commit 54c718d

Please sign in to comment.