Skip to content

Commit 81fd98e

Browse files
committed
Change algo to generate OrderId for EBICS 2.4
1 parent a392b2c commit 81fd98e

File tree

3 files changed

+9
-36
lines changed

3 files changed

+9
-36
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## 2.4
22

3+
* Change algo to generate OrderId for EBICS 2.4
34
* Validation schema for Request.
45
* Update CustomerCreditTransferBuilder.
56
* Add debugger for requests option.

src/Factories/RequestFactoryV24.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected function addOrderType(
4444
$orderAttribute = OrderDetailsBuilder::ORDER_ATTRIBUTE_DZHNN;
4545
}
4646

47-
$orderId = $this->cryptService->generateOrderId($this->user->getPartnerId());
47+
$orderId = $this->cryptService->generateOrderId();
4848

4949
return $orderDetailsBuilder
5050
->addOrderType($orderType)

src/Services/CryptService.php

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -450,46 +450,18 @@ public function getPublicKeyDetails(string $publicKey): array
450450
}
451451

452452
/**
453-
* Generate order id from A000 to ZZZZ
454-
* Unique value per partner for customer.
455-
*
456-
* @param string $partnerId
453+
* Generate random order id from A000 to ZZZZ.
457454
*
458455
* @return string
459456
*/
460-
public function generateOrderId(string $partnerId): string
457+
public function generateOrderId(): string
461458
{
462-
$hash = $this->hash($partnerId, 'crc32', false);
463-
464-
$decs = str_split($hash, 2);
465-
466-
$first = true;
467-
$letOf = 65;
468-
$letLim = 90;
469-
$dgLim = 9;
470-
$letRng = $letLim - $letOf;
471-
$letDecRng = $letLim - $letOf + $dgLim;
472-
473-
$chrs = [];
474-
foreach ($decs as $dec) {
475-
$dec = hexdec($dec);
476-
477-
if ($first) {
478-
$chrs[] = chr(($dec % $letRng) + $letOf);
479-
$first = false;
480-
continue;
481-
}
482-
483-
$chrCode = $dec % $letDecRng;
484-
485-
if ($chrCode > $letRng) {
486-
$chrs[] = $chrCode - $letRng;
487-
} else {
488-
$chrs[] = chr($chrCode + $letOf);
489-
}
490-
}
459+
$first = chr(rand(65, 90));
460+
$num = rand(0, pow(36, 3) - 1);
461+
$suffix = strtoupper(base_convert((string)$num, 10, 36));
462+
$suffix = str_pad($suffix, 3, '0', STR_PAD_LEFT);
491463

492-
return implode($chrs);
464+
return $first . $suffix;
493465
}
494466

495467
/**

0 commit comments

Comments
 (0)