Skip to content

Commit 1ec33bc

Browse files
improved syntax
Improved tests Improved tests
1 parent 2441a00 commit 1ec33bc

11 files changed

Lines changed: 85 additions & 75 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"issues": "https://github.com/bluem-development/bluem-php"
1616
},
1717
"require": {
18-
"php": ">=8.0",
18+
"php": "^8.0|^8.1|^8.2|^8.3",
1919
"ext-dom": "*",
2020
"ext-libxml": "*",
2121
"ext-simplexml": "*",

src/Contexts/IdentityContext.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@ public function addPaymentMethodDetails(array $details = []): void
6565

6666
private function validateDetails(array $details = []): array
6767
{
68-
if ($this->isIDIN()) {
69-
// no validation yet
70-
}
71-
7268
return [];
7369
}
7470

src/Extensions/IPAPI.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@
2121
*/
2222
class IPAPI
2323
{
24-
/**
25-
* @var bool
26-
*/
27-
private bool $debug = false;
28-
2924
/**
3025
* @var string
3126
*/
@@ -69,7 +64,7 @@ public function QueryIP(string $ip = ""): mixed
6964
$ip = $this->GetCurrentIP();
7065
}
7166

72-
$call_url = "{$this->baseURL}{$ip}?access_key=$this->accessKey";
67+
$call_url = sprintf("%s%s?access_key=%s", $this->baseURL, $ip, $this->accessKey);
7368

7469
// Initialize CURL:
7570
$ch = curl_init(

src/Helpers/BIC.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace Bluem\BluemPHP\Helpers;
1010

11-
class BIC
11+
final class BIC
1212
{
1313
public function __construct(
1414
public string $issuerID,

src/Helpers/BluemConfiguration.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,7 @@ class BluemConfiguration
3737
* this is given by the bank and never changed (default 0)
3838
*/
3939
public string $merchantSubID;
40-
private string $PaymentsBrandID;
41-
// @todo: consider deprecating this?
42-
private string $EmandateBrandID;
43-
// @todo: consider deprecating this?
4440

45-
// additional helper flags
4641
/**
4742
* Allows for testing webhook on local environments with no HTTPS check and verbose output.
4843
*/
@@ -80,9 +75,7 @@ public function __construct(object|array $raw)
8075
$this->test_accessToken = $validated->test_accessToken ?? null;
8176

8277
$this->IDINBrandID = $this->_assumeBrandID("Identity", $this->brandID);
83-
$this->PaymentsBrandID = $this->_assumeBrandID("Payment", $this->brandID);
84-
$this->EmandateBrandID = $this->_assumeBrandID("Mandate", $this->brandID);
85-
78+
8679
$this->sequenceType = $validated->sequenceType ?? null;
8780

8881
$this->merchantID = $validated->merchantID ?? null;

src/Helpers/BluemCurrency.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
class BluemCurrency implements Stringable
1616
{
17-
1817
private const EURO_CURRENCY = 'EUR';
1918
private const US_DOLLAR_CURRENCY = 'USD';
2019

src/Helpers/BluemIdentityCategoryList.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
class BluemIdentityCategoryList
1313
{
14-
1514
/**
1615
* @var string[] $categories
1716
*/

src/Helpers/BluemMaxAmount.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,15 @@
1111

1212
class BluemMaxAmount implements \Stringable
1313
{
14-
1514
public BluemCurrency $currency;
16-
public float $amount;
1715

1816
public function __construct(
19-
float $amount,
17+
private float $amount,
2018
string $currencyCode
2119
) {
2220
// @todo: validate the amount to be non-negative and have a maximum, see xsd
23-
$this->amount = $amount;
2421

2522
try {
26-
2723
$this->currency = new BluemCurrency($currencyCode);
2824
} catch (\Exception $e) {
2925
$this->currency = new BluemCurrency();

src/Helpers/Now.php

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ public function __construct($timezoneString = self::DEFAULT_TIMEZONE)
1818
{
1919
try {
2020
$timezone = new DateTimeZone($timezoneString);
21-
} catch (\Exception $e) {
21+
} catch (Exception) {
2222
$timezone = new DateTimeZone(self::DEFAULT_TIMEZONE);
2323
}
2424

2525
try {
2626
$this->dateTime = new DateTimeImmutable(datetime: "now", timezone: $timezone);
27-
} catch (Exception $e) {
27+
} catch (Exception) {
2828
$this->dateTime = new DateTimeImmutable("now", self::DEFAULT_TIMEZONE);
2929
}
3030
}
@@ -55,28 +55,25 @@ public function addDay(int $days): static
5555
return $this;
5656
}
5757

58+
/**
59+
* @throws Exception
60+
*/
5861
public function fromDate(string $dateTimeString): static
5962
{
60-
try {
61-
$this->dateTime = new DateTimeImmutable(
62-
datetime: $dateTimeString,
63-
timezone: new DateTimeZone(self::DEFAULT_TIMEZONE)
64-
);
65-
} catch (Exception $e) {
66-
throw $e;
67-
}
63+
$this->dateTime = new DateTimeImmutable(
64+
datetime: $dateTimeString,
65+
timezone: new DateTimeZone(self::DEFAULT_TIMEZONE)
66+
);
67+
6868
return $this;
6969
}
7070

7171
public function fromTimestamp(string $timestamp): static
7272
{
73-
try {
74-
$this->dateTime = (new DateTimeImmutable())
75-
->setTimestamp($timestamp)
76-
->setTimezone(new DateTimeZone(self::DEFAULT_TIMEZONE));
77-
} catch (Exception $e) {
78-
throw $e;
79-
}
73+
$this->dateTime = (new DateTimeImmutable())
74+
->setTimestamp($timestamp)
75+
->setTimezone(new DateTimeZone(self::DEFAULT_TIMEZONE));
76+
8077
return $this;
8178
}
8279
}

src/Webhook.php

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,46 +44,39 @@ private function parse($xmlData = ''): void
4444
{
4545
if (!$this->isHttpsRequest()) {
4646
$this->exitWithError('Not HTTPS');
47-
return;
4847
}
4948

5049
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
5150
$this->exitWithError('Not POST');
52-
return;
5351
}
5452

5553
// Check: content type: XML with utf-8 encoding
5654
if ($_SERVER["CONTENT_TYPE"] !== self::XML_UTF8_CONTENT_TYPE) {
5755
$this->exitWithError('Wrong Content-Type given: should be XML with UTF-8 encoding');
58-
return;
5956
}
6057

6158
// Check: An empty POST to the URL (normal HTTP request) always has to respond with HTTP 200 OK.
6259
$xmlData = file_get_contents('php://input');
6360

6461
if (empty($xmlData)) {
6562
$this->exitWithError('No data body given');
66-
return;
6763
}
6864
}
6965

7066
$xmlObject = $this->parseRawXML($xmlData);
7167

72-
if (! $xmlObject instanceof \SimpleXMLElement) {
68+
if (! $xmlObject instanceof SimpleXMLElement) {
7369
$this->exitWithError('Could not parse XML');
74-
return;
7570
}
7671

7772
$xmlValidation = (new WebhookXmlValidation($this->senderID))->validate($xmlObject);
7873
if (! $xmlValidation::$isValid) {
7974
$this->exitWithError($xmlValidation->errorMessage());
80-
return;
8175
}
8276

8377
$signatureValidation = (new WebhookSignatureValidation($this->environment))->validate($xmlData);
8478
if (! $signatureValidation::$isValid) {
8579
$this->exitWithError($signatureValidation->errorMessage());
86-
return;
8780
}
8881

8982
$this->xmlObject = $xmlObject;
@@ -98,10 +91,11 @@ private function isHttpsRequest(): bool
9891
|| $_SERVER['SERVER_PORT'] === 443
9992
);
10093
}
101-
102-
private function exitWithError(string $string): void
94+
95+
private function exitWithError(string $errorMessage): void
10396
{
10497
http_response_code(self::STATUSCODE_BAD_REQUEST);
98+
exit($errorMessage);
10599
}
106100

107101
private function parseRawXML($postData): string|SimpleXMLElement
@@ -144,7 +138,7 @@ private function getPayloadValue(string $key): SimpleXMLElement|string|null
144138
if ((is_countable($payload->children()) ? count($payload->children()) : 0) > 0) {
145139
return $payload;
146140
}
147-
return $payload->$key ?? '';
141+
return $payload->$key ? ($payload->$key . '') : '';
148142
}
149143

150144
private function getPayload(): SimpleXMLElement
@@ -261,31 +255,31 @@ public function getIDealDetails(): ?SimpleXMLElement
261255
{
262256
$paymentDetails = $this->getPaymentMethodDetails();
263257

264-
if (!$paymentDetails instanceof \SimpleXMLElement) {
258+
if (!$paymentDetails instanceof SimpleXMLElement) {
265259
return null;
266260
}
267261
return $paymentDetails->IDealDetails;
268262
}
269263
public function getDebtorAccountName(): ?string
270264
{
271265
$details = $this->getIDealDetails();
272-
if (!$details instanceof \SimpleXMLElement) {
266+
if (!$details instanceof SimpleXMLElement) {
273267
return "";
274268
}
275269
return $details->DebtorAccountName."" ?? "";
276270
}
277271
public function getDebtorIBAN(): ?string
278272
{
279273
$details = $this->getIDealDetails();
280-
if (!$details instanceof \SimpleXMLElement) {
274+
if (!$details instanceof SimpleXMLElement) {
281275
return "";
282276
}
283277
return $details->DebtorIBAN."" ?? "";
284278
}
285279
public function getDebtorBankID(): ?string
286280
{
287281
$details = $this->getIDealDetails();
288-
if (!$details instanceof \SimpleXMLElement) {
282+
if (!$details instanceof SimpleXMLElement) {
289283
return "";
290284
}
291285
return $details->DebtorBankID."" ?? "";
@@ -358,7 +352,7 @@ public function getIdentityReportArray(): array
358352
{
359353
$report = $this->getPayload()->IdentityReport ?? null;
360354

361-
if (!$report instanceof \SimpleXMLElement) {
355+
if (!$report instanceof SimpleXMLElement) {
362356
return [];
363357
}
364358

0 commit comments

Comments
 (0)