Skip to content

Commit f64149d

Browse files
committed
Add text formatting for bank module compliance
1 parent 2683d92 commit f64149d

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

src/Legacy/Etransactions.php

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -658,16 +658,49 @@ public function setBilling(array $billingInfo)
658658
$this->parameters[PayBoxRequestParams::PBX_BILLING] = $this->getXmlBilling($billingInfo);
659659
}
660660

661+
/**
662+
* Format text for bank module requirements
663+
* @param string $value
664+
* @param int $maxLength
665+
* @return string
666+
*/
667+
private function formatage($value, $maxLength)
668+
{
669+
// Convert to uppercase and remove accents
670+
if (class_exists('Transliterator')) {
671+
$value = strtoupper(\Transliterator::create('NFD; [:Nonspacing Mark:] Remove; NFC')->transliterate($value));
672+
} else {
673+
// Fallback if Transliterator is not available
674+
$value = strtoupper($value);
675+
$value = str_replace(
676+
['À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'Ç', 'Ñ'],
677+
['A', 'A', 'A', 'A', 'A', 'A', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 'C', 'N'],
678+
$value
679+
);
680+
}
681+
682+
// Remove non-alphanumeric characters except spaces
683+
$value = preg_replace('/[^A-Z0-9\s]/', '', $value);
684+
685+
// Normalize multiple spaces to single spaces
686+
$value = preg_replace('/\s+/', ' ', $value);
687+
688+
// Truncate to maximum length
689+
$value = substr($value, 0, $maxLength);
690+
691+
return trim($value);
692+
}
693+
661694
private function getXmlBilling(array $billing)
662695
{
663-
$xml = '<?xml version="1.0" encoding="UTF-8"?>';
696+
$xml = '<?xml version="1.0" encoding="utf-8"?>';
664697
$xml .= '<Billing>';
665698
$xml .= '<Address>';
666-
$xml .= '<FirstName>' . $billing['firstName'] . '</FirstName>';
667-
$xml .= '<LastName>' . $billing['lastName'] . '</LastName>';
668-
$xml .= '<Address1>' . $billing['address1'] . '</Address1>';
669-
$xml .= '<ZipCode>' . $billing['zipCode'] . '</ZipCode>';
670-
$xml .= '<City>' . $billing['city'] . '</City>';
699+
$xml .= '<FirstName>' . $this->formatage($billing['firstName'] ?? '', 22) . '</FirstName>';
700+
$xml .= '<LastName>' . $this->formatage($billing['lastName'] ?? '', 22) . '</LastName>';
701+
$xml .= '<Address1>' . $this->formatage($billing['address1'] ?? '', 50) . '</Address1>';
702+
$xml .= '<ZipCode>' . $this->formatage($billing['zipCode'] ?? '', 16) . '</ZipCode>';
703+
$xml .= '<City>' . $this->formatage($billing['city'] ?? '', 50) . '</City>';
671704
$xml .= '<CountryCode>' . $billing['countryCode'] . '</CountryCode>';
672705
$xml .= '</Address>';
673706
$xml .= '</Billing>';

0 commit comments

Comments
 (0)