Skip to content

Commit

Permalink
Added payment info fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Franck Allimant committed Mar 14, 2022
1 parent b811eb7 commit 52ce22c
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 7 deletions.
18 changes: 17 additions & 1 deletion Axepta.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Thelia\Log\Tlog;
use Thelia\Model\Order;
use Thelia\Module\AbstractPaymentModule;
use Thelia\Tools\MoneyFormat;
use Thelia\Tools\URL;

class Axepta extends AbstractPaymentModule
Expand Down Expand Up @@ -47,9 +48,11 @@ public function pay(Order $order)
$paymentRequest = new AxeptaPayment($hmac);
$paymentRequest->setCryptKey($cryptKey);

$transId = time().$order->getId();

$paymentRequest->setUrl(AxeptaPayment::PAYSSL);
$paymentRequest->setMerchantID($merchantId);
$paymentRequest->setTransID($order->getId());
$paymentRequest->setTransID($transId);
$paymentRequest->setAmount((int) ($order->getTotalAmount()*100));
$paymentRequest->setCurrency($order->getCurrency()->getCode());
$paymentRequest->setRefNr($order->getRef());
Expand Down Expand Up @@ -79,8 +82,21 @@ public function pay(Order $order)
'Len' => $len,
'Data' => $data,
'URLBack' => $urlAnnulation,
'CustomField1' => sprintf(
"%s, %s",
MoneyFormat::getInstance($this->getRequest())->format($order->getTotalAmount(), 2),
$order->getCurrency()->getCode()
),
'CustomField2' => $order->getRef()
];

TLog::getInstance()->error("Données Axcepta : " . print_r($paymentRequest->parameters, 1));
TLog::getInstance()->error("URL Axcepta : " . $paymentRequest->getUrl());

$order
->setTransactionRef($transId)
->save();

return $this->generateGatewayFormResponse($order, $paymentRequest->getUrl(), $transmit);
}

Expand Down
3 changes: 3 additions & 0 deletions Config/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@
<hook id="axepta.configuration.hook" class="Axepta\Hook\HookManager">
<tag name="hook.event_listener" event="module.configuration" type="back" method="onModuleConfigure" />
</hook>
<hook id="axepta.orderpaymentgateway.hook" class="Axepta\Hook\HookManager">
<tag name="hook.event_listener" event="order-payment-gateway.javascript" type="front" method="onOrderPaymentGatewayJavascript" />
</hook>
</hooks>
</config>
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>1.0.0</version>
<version>1.0.1</version>
<authors>
<author>
<name>Nicolas Barbey</name>
Expand Down
21 changes: 18 additions & 3 deletions Controller/NotificationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Thelia\Core\Event\Order\OrderEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Translation\Translator;
use Thelia\Exception\TheliaProcessException;
use Thelia\Model\Base\OrderQuery;
use Thelia\Model\OrderStatusQuery;
use Thelia\Module\BasePaymentModuleController;
Expand All @@ -29,25 +30,39 @@ public function notificationAction()
$paymentResponse->setCryptKey(Axepta::getConfigValue(Axepta::CRYPT_KEY));
$paymentResponse->setResponse($this->getRequest()->query->all());

$orderRef = $paymentResponse->getrefnr();
if (null === $order = OrderQuery::create()->filterByRef($orderRef)->findOne()) {
$this->redirectToFailurePage($order->getId(), Translator::getInstance()->trans("Failed to find order reference %ref", ['ref' => $orderRef ], Axepta::DOMAIN_NAME));
$this->getLog()->addError("Notification parameters: ".print_r($paymentResponse->parameters, 1));

$transId = $paymentResponse->getTransID();

if (null === $order = OrderQuery::create()->filterByTransactionRef($transId)->findOne()) {
$this->getLog()->addInfo("Failed to fin order for transaction ID $transId. Aborting.");

throw new TheliaProcessException(
Translator::getInstance()->trans("Failed to find order for transaction ID %id", ['id' => $transId ], Axepta::DOMAIN_NAME)
);
}

$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'.");
$event->setStatus(OrderStatusQuery::getPaidStatus()->getId());
$this->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event);
}

$this->redirectToSuccessPage($order->getId());
}

$this->getLog()->addInfo("Payment failed, cancelling order " . $order->getRef());

$event->setStatus(OrderStatusQuery::getCancelledStatus()->getId());
$this->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event);

$this->getLog()->addInfo("Failure cause:".$paymentResponse->getDescription() . ' ('.$paymentResponse->getCode());
$this->redirectToFailurePage($order->getId(), $paymentResponse->getDescription() . ' ('.$paymentResponse->getCode().')');
}
}
9 changes: 8 additions & 1 deletion Hook/HookManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,11 @@ public function onModuleConfigure(HookRenderEvent $event)
$this->render('module-configuration.html')
);
}
}

public function onOrderPaymentGatewayJavascript(HookRenderEvent $event)
{
$event->add(
$this->render('hook/order-payment-gateway-javascript.html')
);
}
}
2 changes: 1 addition & 1 deletion Util/Axepta.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Axepta

private $pspURL = self::PAYSSL;

private $parameters = array();
public $parameters = array();

/** Axepta fields **/
private $pspFields = array(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{* We shoud use the "GET" method fo rsome fields to be properly processed byt the gateway *}
{* see https://docs.axepta.bnpparibas/display/DOCBNP/Payment+page#Paymentpage-Howtocallthepaymentmethodsselectionpage? *}
<script type="text/javascript">
jQuery(function($) {
var $form = $('#payement_gateway_form');

$form.attr('method', 'get');
$form.submit();

$('#force-submit-payment-form').click(function(ev) {
$form.submit();

ev.preventDefault();
});
});
</script>

0 comments on commit 52ce22c

Please sign in to comment.