Skip to content

Commit

Permalink
Refined log system
Browse files Browse the repository at this point in the history
  • Loading branch information
Franck Allimant committed Sep 7, 2023
1 parent 9432e35 commit 9ba03f3
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 11 deletions.
1 change: 1 addition & 0 deletions Axepta.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Axepta extends AbstractPaymentModule
public const ALLOWED_IP_LIST = 'allowed_ip_list';
public const MINIMUM_AMOUNT = 'minimum_amount';
public const MAXIMUM_AMOUNT = 'maximum_amount';
const LOG_AXCEPTA_RESPONSE = 'log_axcepta_response';

public const SEND_CONFIRMATION_MESSAGE_ONLY_IF_PAID = 'send_confirmation_message_only_if_paid';

Expand Down
2 changes: 1 addition & 1 deletion Config/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<language>en_US</language>
<language>fr_FR</language>
</languages>
<version>2.0.1</version>
<version>2.0.2</version>
<authors>
<author>
<name>Nicolas Barbey</name>
Expand Down
26 changes: 17 additions & 9 deletions Controller/NotificationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ protected function getModuleCode()
}

/**
* @param $orderId
* @param EventDispatcherInterface $dispatcher
* @param Request $request
* @return void
* @throws \Exception
*/
public function cancelPaymentAction($orderId, EventDispatcherInterface $dispatcher, Request $request): void
Expand Down Expand Up @@ -79,7 +75,9 @@ public function notificationAction(Request $request, EventDispatcherInterface $d

$paymentResponse->setResponse($parameters);

$this->getLog()->addError('Notification parameters: '.print_r($paymentResponse->parameters, 1));
if ((bool) Axepta::getConfigValue(Axepta::LOG_AXCEPTA_RESPONSE, false)) {
$this->getLog()->addError('Notification parameters: '.print_r($paymentResponse->parameters, 1));
}

$transId = $paymentResponse->getTransID();

Expand All @@ -91,16 +89,20 @@ public function notificationAction(Request $request, EventDispatcherInterface $d
);
}

$this->getLog()->addInfo('Processing payment of order '.$order->getRef());

$event = new OrderEvent($order);

if ($paymentResponse->isValid() && $paymentResponse->isSuccessful()) {
$this->getLog()->addInfo('Payment of order '.$order->getRef().' is successful.');
if (!$order->isPaid()) {
$this->getLog()->addInfo("Setting order status to 'paid'.");
$this->getLog()->addInfo('Payment of order '.$order->getRef()." is successful, setting order status to 'paid'");
$event->setStatus(OrderStatusQuery::getPaidStatus()->getId());
$dispatcher->dispatch($event, TheliaEvents::ORDER_UPDATE_STATUS);
} else {
$this->getLog()->addInfo('Order '.$order->getRef()." is already in 'paid' status");
}

// Just return if no customer is connected.
if (null === $request->getSession()?->getCustomerUser()) {
return;
}

$this->redirectToSuccessPage($order->getId());
Expand All @@ -112,6 +114,12 @@ public function notificationAction(Request $request, EventDispatcherInterface $d
$dispatcher->dispatch($event, TheliaEvents::ORDER_UPDATE_STATUS);

$this->getLog()->addInfo('Failure cause:'.$paymentResponse->getDescription().' ('.$paymentResponse->getCode());

// Just return if no customer is connected.
if (null === $request->getSession()?->getCustomerUser()) {
return;
}

$this->redirectToFailurePage($order->getId(), $paymentResponse->getDescription().' ('.$paymentResponse->getCode().')');
}
}
15 changes: 15 additions & 0 deletions Form/ConfigurationForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,21 @@ protected function buildForm()
]
]
)
->add(
Axepta::LOG_AXCEPTA_RESPONSE,
CheckboxType::class,
[
'value' => 1,
'required' => false,
'label' => $this->trans('Log Axcepta request content (for debug purposes only)'),
'data' => (boolean)(Axepta::getConfigValue(Axepta::LOG_AXCEPTA_RESPONSE, false)),
'label_attr' => [
'help' => $this->trans(
'If checked, Axcepta request content will be logged in Thelia log file. Warning, this data may contain confidential information'
)
]
]
)

;
}
Expand Down
3 changes: 2 additions & 1 deletion I18n/fr_FR.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
return array(
'Allowed IPs in test mode' => 'Adresse IP autorisé en mode de test ',
'Blowfish encryption key' => 'Clé de cryptage Blowfish',
'Failed to find order reference %ref' => 'La référence de commande %ref n\'a pas été trouvé',
'HMAC key' => 'Clé HMAC',
'If checked, Axcepta request content will be logged in Thelia log file. Warning, this data may contain confidential information' => 'Si cette case est cochée, le contenu des notifications reçues d\'Axcepta sera loggé dans le fichier de log de Thelia. Attention, ces données peuvent contenir des infos confidentielles.',
'If checked, the order confirmation message is sent to the customer only when the payment is successful. The order notification is always sent to the shop administrator' => 'Si cette case est cochée, le mail de confirmation de commande sera envoyé au client seulement si son paiement est validé.',
'List of IP addresses allowed to use this payment on the front-office when in test mode (your current IP is %ip). One address per line' => 'Liste des adresses IP qui pourront choisir ce module de paiement en front-office pendant la phase de test (votre IP est %ip). Une adresse par ligne.',
'Log Axcepta request content (for debug purposes only)' => 'Logger le contenu des notification Axcepta (à des fins de débug uniquement)',
'Maximum order total' => 'Montant maximum de commande',
'Maximum order total in the default currency for which this payment method is available. Enter 0 for no maximum' => 'Montant maximum dans la devise par défaut pour proposer ce moyen de paiement. Laisser 0 pour ne pas fixer de maximum',
'Merchant ID' => 'Id du commerçant',
Expand Down
1 change: 1 addition & 0 deletions templates/backOffice/default/module-configuration.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
{render_form_field field="send_confirmation_message_only_if_paid"}
{render_form_field field="run_mode"}
{render_form_field field="allowed_ip_list"}
{render_form_field field="log_axcepta_response"}
{render_form_field field="minimum_amount"}
{render_form_field field="maximum_amount"}
</div>
Expand Down

0 comments on commit 9ba03f3

Please sign in to comment.