Skip to content

Commit af03112

Browse files
daanrijpkemacbDaanRijpkema
authored andcommitted
Append url params properly if base already has query string params
1 parent 5e0cb6f commit af03112

4 files changed

Lines changed: 20 additions & 7 deletions

File tree

src/Requests/BluemRequest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,4 +445,18 @@ public function setBrandId(string $brandID): void
445445
{
446446
$this->brandID = $brandID;
447447
}
448+
449+
/**
450+
* Use the right separator based on the presence of a query string
451+
*/
452+
protected function appendToUrl(string $urlBase, string $key, $value): string
453+
{
454+
$hasQueryString = preg_match('/\?.+=.+/', $urlBase);
455+
456+
if ($hasQueryString) {
457+
return "{$urlBase}&{$key}={$value}";
458+
}
459+
460+
return "{$urlBase}?{$key}={$value}";
461+
}
448462
}

src/Requests/EmandateBluemRequest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ public function __construct(BluemConfiguration $config, private $debtorReference
6767
$this->mandateID = $mandateID;
6868

6969
// https - unique return URL for customer
70-
$this->merchantReturnURL = sprintf('%s?mandateID=%s', $this->merchantReturnURLBase, $this->mandateID);
70+
$this->merchantReturnURL = $this->appendToUrl($this->merchantReturnURLBase, 'mandateID',$this->mandateID);
71+
7172
$this->sequenceType = $config->sequenceType ?? "RCUR";
7273
// reason for the mandate; configurable per client
7374
$this->eMandateReason = $config->eMandateReason ?? "Incasso machtiging";

src/Requests/IdentityBluemRequest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ public function __construct(
7272
if (empty($debtorReturnURL)) {
7373
$debtorReturnURL = $config->merchantReturnURLBase;
7474
}
75-
76-
$this->debtorReturnURL = $debtorReturnURL . ('?debtorReference=' . $this->debtorReference);
75+
$this->debtorReturnURL = $this->appendToUrl($debtorReturnURL,"debtorReference",$this->debtorReference);
7776

7877
// @todo: make this a configurable setting
7978
$this->minAge = $config->minAge ?? BLUEM_DEFAULT_MIN_AGE;

src/Requests/PaymentBluemRequest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,8 @@ public function __construct(
106106
$this->debtorReturnURL = $config->merchantReturnURLBase;
107107
}
108108

109-
$this->debtorReturnURL .= sprintf('?entranceCode=%s&transactionID=%s', $this->entranceCode, $this->transactionID);
110-
111-
$this->debtorReturnURL = str_replace('&', '&', $this->debtorReturnURL);
109+
$this->debtorReturnURL = $this->appendToUrl($this->debtorReturnURL, 'entranceCode', $this->entranceCode);
110+
$this->debtorReturnURL = $this->appendToUrl($this->debtorReturnURL, 'transactionID',$this->transactionID);
112111

113112
// Note: different variable name in config
114113
// added entranceCode as well, useful. Defined in generic bluem request class.
@@ -175,7 +174,7 @@ public function XmlString(): string
175174
if (!empty($this->brandID)) {
176175
$extraOptions['brandID'] = $this->brandID;
177176
}
178-
177+
179178
return $this->XmlRequestInterfaceWrap(
180179
$this->xmlInterfaceName,
181180
'TransactionRequest',

0 commit comments

Comments
 (0)