Skip to content

Commit

Permalink
Customer phone number in PBX_BILLING element
Browse files Browse the repository at this point in the history
  • Loading branch information
Franck Allimant committed Sep 5, 2024
1 parent af70d01 commit 47aadc0
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Config/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<descriptive locale="fr_FR">
<title>Paiement en carte bancaire avec Paybox</title>
</descriptive>
<version>2.2.4</version>
<version>2.2.5</version>
<author>
<name>Franck Allimant</name>
<email>franck@cqfdev.fr</email>
Expand Down
2 changes: 2 additions & 0 deletions I18n/en_US.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
'Failed to open %file, please check Paybox configuration' => 'Failed to open %file, please check Paybox configuration',
'Identifiant interne' => 'Internal identifier',
'Identifiant interne, tel que fourni par Paybox' => 'Internal identifier, provided by Paybox',
'Invalid phone number %num for country %country' => 'Invalid phone number %num for country %country',
'Le fichier de log est vide.' => 'The log file is empty.',
'Le fichier de log n\'a pas été trouvé.' => 'The log file could not be found.',
'Maximum order total' => 'Maximum order total',
Expand All @@ -32,6 +33,7 @@
'Paybox configuration' => 'Paybox configuration',
'Paybox platform request processing terminated.' => 'Paybox platform request processing terminated.',
'Paybox platform request received.' => 'Paybox platform request received.',
'Please enter a valid phone number in your invoice address (error is : %err)' => 'Please enter a valid phone number in your invoice address (error is : %err)',
'Production' => 'Production',
'Request parameters signature verification failed.' => 'Request parameters signature verification failed.',
'Test' => 'Test',
Expand Down
2 changes: 2 additions & 0 deletions I18n/fr_FR.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
'Failed to open %file, please check Paybox configuration' => 'Le fichier %file est inaccessible, merci de vérifier la configuration Paybox',
'Identifiant interne' => 'Identifiant interne',
'Identifiant interne, tel que fourni par Paybox' => 'Identifiant interne, tel que fourni par Paybox',
'Invalid phone number %num for country %country' => 'Le numéro de téléphone %num est invalide pour le pays %country',
'Le fichier de log est vide.' => 'Le fichier de log est vide.',
'Le fichier de log n\'a pas été trouvé.' => 'Le fichier de log n\'a pas été trouvé.',
'Maximum order total' => 'Montant de commande maximum',
Expand All @@ -32,6 +33,7 @@
'Paybox configuration' => 'Configuration Paybox',
'Paybox platform request processing terminated.' => 'Traitement de la requête Paybox terminé.',
'Paybox platform request received.' => 'Réception d\'une requête de la plate-form Paybox',
'Please enter a valid phone number in your invoice address (error is : %err)' => 'Merci d\'entrer un numero de téléphone mobile valide dans votre adresse de facturation (détail de l\'erreur : %err)',
'Production' => 'Production',
'Request parameters signature verification failed.' => 'La vérification de la signature de la requête a échoué.',
'Test' => 'Test',
Expand Down
53 changes: 43 additions & 10 deletions Paybox.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@

namespace Paybox;

use libphonenumber\NumberParseException;
use libphonenumber\PhoneNumberUtil;
use Propel\Runtime\Connection\ConnectionInterface;
use Symfony\Component\DependencyInjection\Loader\Configurator\ServicesConfigurator;
use Thelia\Core\HttpFoundation\Response;
use Thelia\Core\Translation\Translator;
use Thelia\Exception\TheliaProcessException;
use Thelia\Log\Tlog;
use Thelia\Model\Message;
use Thelia\Model\MessageQuery;
Expand Down Expand Up @@ -205,19 +208,49 @@ protected function doPayPayboxParameters(Order $order): array

protected function getBilling(Order $order): array|bool|string
{
$address = $order->getOrderAddressRelatedByInvoiceOrderAddressId();
$address = $order->getOrderAddressRelatedByInvoiceOrderAddressId();

$billingXml = new \SimpleXMLElement('<Billing/>');
$addressXml = $billingXml->addChild('Address');
// Decode phone number
$phoneNumber = empty($address->getCellphone()) ? $address->getPhone() : $address->getCellphone();

$addressXml?->addChild('FirstName', $address->getFirstname());
$addressXml?->addChild('LastName', $address->getLastname());
$addressXml?->addChild('Address1', $address->getAddress1());
$addressXml?->addChild('ZipCode', $address->getZipcode());
$addressXml?->addChild('City', $address->getCity());
$addressXml?->addChild('CountryCode', $address->getCountry()->getIsocode());
$phoneUtil = PhoneNumberUtil::getInstance();

return str_replace(["\n", "\r"], '', $billingXml->asXML());
try {
if (null === $phoneNumberProto = $phoneUtil->parse($phoneNumber, $address->getCountry()->getIsoalpha2())) {
throw new TheliaProcessException(
Translator::getInstance()->trans(
'Invalid phone number %num for country %country',
[
'%num' => $phoneNumber,
'%country' => $address->getCountry()->setLocale($this->getRequest()->getSession()->getLang()->getLocale())->getTitle(),
],
self::MODULE_DOMAIN
)
);
}

$billingXml = new \SimpleXMLElement('<Billing/>');
$addressXml = $billingXml->addChild('Address');

$addressXml->addChild('FirstName', $address->getFirstname());
$addressXml->addChild('LastName', $address->getLastname());
$addressXml->addChild('Address1', $address->getAddress1());
$addressXml->addChild('ZipCode', $address->getZipcode());
$addressXml->addChild('City', $address->getCity());
$addressXml->addChild('CountryCode', $address->getCountry()->getIsocode());
$addressXml->addChild('CountryCodeMobilePhone', '+'.$phoneNumberProto->getCountryCode());
$addressXml->addChild('MobilePhone', $phoneNumberProto->getNationalNumber());

return str_replace(["\n", "\r"], '', $billingXml->asXML());
} catch (NumberParseException $e) {
throw new TheliaProcessException(
Translator::getInstance()->trans(
'Please enter a valid phone number in your invoice address (error is : %err)',
['%err' => $e->getMessage()],
self::MODULE_DOMAIN
)
);
}
}

protected function getShoppingCart(Order $order): array|bool|string
Expand Down
10 changes: 8 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@
"license": "LGPL-3.0+",
"type": "thelia-module",
"require": {
"thelia/installer": "~1.0"
"thelia/installer": "~1.0",
"giggsey/libphonenumber-for-php": "^8.13"
},
"suggest": {
"thelia/paybox3x-module": "This module offers to your customers the Paybox 3x payment system"
},
"extra": {
"installer-name": "Paybox"
},
"config": {
"allow-plugins": {
"thelia/installer": true
}
}
}
}

0 comments on commit 47aadc0

Please sign in to comment.