Skip to content

Commit

Permalink
Merge pull request #67 from checkout/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
imenkar authored Jul 26, 2022
2 parents 600c34e + ae9d316 commit 1c01f4e
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 24 deletions.
10 changes: 5 additions & 5 deletions checkoutcom.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct()
{
$this->name = 'checkoutcom';
$this->tab = 'payments_gateways';
$this->version = '2.3.0';
$this->version = '2.3.1';
$this->author = 'Checkout.com';
$this->need_instance = 1;

Expand Down Expand Up @@ -78,7 +78,7 @@ public function install()
}

$sql = "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."checkoutcom_adminorder`(
`id_checkoutcom_adminorder` int(11) NOT NULL,
`id_checkoutcom_adminorder` int(11) NOT NULL AUTO_INCREMENT,
`transaction_id` varchar(255) NOT NULL,
`amount_captured` float(20,2) NOT NULL,
`amount_refunded` float(20,2) NOT NULL,
Expand All @@ -98,7 +98,7 @@ public function install()
Tools::clearSmartyCache();

return parent::install() &&
$this->addOrderState($this->l('Payment authorized by CKO, awaiting capture')) &&
$this->addOrderState('Payment authorized by CKO, awaiting capture') &&
$this->registerHook('paymentOptions') &&
$this->registerHook('header') &&
$this->registerHook('displayCustomerAccount') &&
Expand Down Expand Up @@ -772,12 +772,12 @@ public function hookActionOrderStatusPostUpdate($params)
$action = (float) \Configuration::get('CHECKOUTCOM_PAYMENT_ACTION');
$payment = new OrderPayment();
$payment = $payment->getByOrderId($params['id_order']);
$amountToCapture = (float) number_format( $order->total_paid_tax_incl, 2);
$amountToCapture = round($order->total_paid_tax_incl, 2);
$trigger_statuses = $trigger_statuses ? $trigger_statuses : [];
if (!$event && !$action && in_array($new_status_id, $trigger_statuses)) {
$checkout = new CheckoutApi( \Configuration::get('CHECKOUTCOM_SECRET_KEY') );
try {
$details = $checkout->payments()->capture(new Capture($payment[0]->transaction_id, $amountToCapture*100));
$details = $checkout->payments()->capture(new Capture($payment[0]->transaction_id, intval(round($amountToCapture*100))));
} catch (Exception $ex) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "checkoutcom/prestashop",
"description": "Checkout.com is an international provider of online payment solutions. We support 150+ currencies and access to all international cards and popular local payment methods.",
"version": "2.3.0",
"version": "2.3.1",
"type": "prestashop-module",
"require": {
"checkout/checkout-sdk-php": "^1.0"
Expand Down
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<name>checkoutcom</name>
<displayName><![CDATA[Checkout.com]]></displayName>
<version><![CDATA[2.3.0]]></version>
<version><![CDATA[2.3.1]]></version>
<description><![CDATA[Checkout.com is an international provider of online payment solutions. We support 150+ currencies and access to all international cards and popular local payment methods.]]></description>
<author><![CDATA[Checkout.com]]></author>
<tab><![CDATA[payments_gateways]]></tab>
Expand Down
24 changes: 21 additions & 3 deletions controllers/front/webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,35 @@ protected function handleOrder()

foreach ($this->events as $event) {
$cart_id = str_replace( 'CART_', '', $event['data']['reference'] );
$sql = 'SELECT `reference` FROM `'._DB_PREFIX_.'orders` WHERE `id_cart`='.$cart_id;
$order_reference = Db::getInstance()->getValue($sql);
$sql = 'SELECT `reference`,`id_shop` FROM `'._DB_PREFIX_.'orders` WHERE `id_cart`='.$cart_id;
$order_result = Db::getInstance()->executeS($sql);
$order_reference = $order_result[0]['reference'];
$order_id_shop = $order_result[0]['id_shop'];

$orders = Order::getByReference($order_reference);
$list = $orders->getAll();
$status = +Utilities::getOrderStatus($event['type'], $order_reference, $event['data']['action_id']);
$status = +Utilities::getOrderStatus($event['type'], $order_reference, $event['data']['action_id'], $order_id_shop);

if ($status) {

foreach ($list as $order) {

if($event['type'] == 'payment_captured'){
$sql = 'SELECT * FROM '._DB_PREFIX_."checkoutcom_adminorder WHERE `transaction_id` = '".$event['data']['reference']."'";
$row = Db::getInstance()->getRow($sql);

if ( empty($row) ) {
$sql = "INSERT INTO "._DB_PREFIX_."checkoutcom_adminorder (`transaction_id`, `amount_captured`, `amount_refunded`)";
$sql .= "VALUES ('".$event['data']['reference']."', ".($event['data']['balances']['total_captured']/100).", 0)";
Db::getInstance()->execute($sql);
}else{
$sql = "UPDATE "._DB_PREFIX_."checkoutcom_adminorder";
$sql .= " SET `amount_captured`=".($event['data']['balances']['total_captured']/100);
$sql .= " WHERE `transaction_id`='".$event['data']['reference']."'";
Db::getInstance()->execute($sql);
}
}

$currentStatus = $order->getCurrentOrderState()->id;
if($currentStatus !== $status && $this->preventAuthAfterCapture($currentStatus, $status)) {

Expand Down
10 changes: 5 additions & 5 deletions src/Helpers/Utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ public static function formatDate($timestamp)
*
* @return mixed The order status.
*/
public static function getOrderStatus($event, $reference, $id) {
public static function getOrderStatus($event, $reference, $id, $id_shop = null) {

switch ($event) {
case 'card_verified':
case 'payment_approved':
return \Configuration::get('CHECKOUTCOM_AUTH_ORDER_STATUS');
return \Configuration::get('CHECKOUTCOM_AUTH_ORDER_STATUS', null, null, $id_shop);
case 'card_verification_declined':
case 'payment_declined':
case 'payment_expired':
Expand All @@ -80,14 +80,14 @@ public static function getOrderStatus($event, $reference, $id) {
\PrestaShopLogger::addLog('The `' . $event .'` was triggered for order ' . $reference . '.', 2, 0, 'CheckoutcomWebhookModuleFrontController' , $id, false);
return _PS_OS_ERROR_;
case 'payment_voided':
return \Configuration::get('CHECKOUTCOM_VOID_ORDER_STATUS');
return \Configuration::get('CHECKOUTCOM_VOID_ORDER_STATUS', null, null, $id_shop);
case 'payment_canceled':
\PrestaShopLogger::addLog('The `' . $event .'` was triggered for order ' . $reference . '.', 2, 0, 'CheckoutcomWebhookModuleFrontController' , $id, false);
return _PS_OS_CANCELED_;
case 'payment_captured':
return \Configuration::get('CHECKOUTCOM_CAPTURE_ORDER_STATUS');
return \Configuration::get('CHECKOUTCOM_CAPTURE_ORDER_STATUS', null, null, $id_shop);
case 'payment_refunded':
return \Configuration::get('CHECKOUTCOM_REFUND_ORDER_STATUS');
return \Configuration::get('CHECKOUTCOM_REFUND_ORDER_STATUS', null, null, $id_shop);
default:
return null;
}
Expand Down
4 changes: 4 additions & 0 deletions src/Models/Payments/Google.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public static function pay(array $params)

if ($token) {
$payment = static::makePayment(new TokenSource($token->getTokenId()));

$threeDs = '3ds';
$payment->$threeDs->enabled = true;

$response = static::request($payment);
}

Expand Down
3 changes: 3 additions & 0 deletions src/Models/Payments/Method.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ public static function addThreeDs(Payment $payment)
if ($payment->threeDs->enabled) {
$payment->threeDs->attempt_n3d = (bool) \Configuration::get('CHECKOUTCOM_CARD_USE_3DS_ATTEMPT_N3D');
}

$threeDs = '3ds';
$payment->$threeDs = $payment->threeDs;
}

/**
Expand Down
32 changes: 25 additions & 7 deletions views/css/front.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions views/img/card-icons/cartes bancaires.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions views/js/card.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ function CheckoutcomFramesPay($form) {
country: prestashop.customer.addresses[$frames.dataset.billing].country_iso
},
phone: customerPhone,
},
schemeChoice: {
frameSelector: ".scheme-choice-frame"
}
});

Expand Down Expand Up @@ -109,9 +112,9 @@ function CheckoutcomFramesPay($form) {
var pm = event.paymentMethod;
let container = document.querySelector(".icon-container.payment-method");

if (!pm) {
if (!pm && document.getElementById("checkoutcom-multi-frame") !== null) {
clearPaymentMethodIcon(container);
} else {
} else if(document.getElementById("checkoutcom-multi-frame") !== null) {
clearErrorIcon("card-number");
showPaymentMethodIcon(container, pm);
}
Expand Down
4 changes: 4 additions & 0 deletions views/templates/front/payments/card.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@
{if $isSingleIframe}
{*frames will be added here*}
<div id="{$module|escape:'htmlall':'UTF-8'}-card-frame" class="card-frame" data-key="{$CHECKOUTCOM_PUBLIC_KEY|escape:'htmlall':'UTF-8'}" data-billing="{$billingId|escape:'htmlall':'UTF-8'}" data-debug="{$debug|escape:'htmlall':'UTF-8'}" data-lang="{$lang|escape:'htmlall':'UTF-8'}" data-module="{$module|escape:'htmlall':'UTF-8'}" data-saveCard="{$save_card_option|escape:'htmlall':'UTF-8'}" ></div>
<div class="scheme-choice-frame"></div>
{else}
<div id="{$module|escape:'htmlall':'UTF-8'}-multi-frame" class="multi-frame" data-key="{$CHECKOUTCOM_PUBLIC_KEY|escape:'htmlall':'UTF-8'}" data-billing="{$billingId|escape:'htmlall':'UTF-8'}" data-debug="{$debug|escape:'htmlall':'UTF-8'}" data-lang="{$lang|escape:'htmlall':'UTF-8'}" data-module="{$module|escape:'htmlall':'UTF-8'}" data-saveCard="{$save_card_option|escape:'htmlall':'UTF-8'}" data-imagedir="{$img_dir|escape:'htmlall':'UTF-8'}">
{*frames will be added here*}

<div class="input-container card-number">
<div class="icon-container">
<img id="icon-card-number"
Expand All @@ -93,7 +95,9 @@
<img id="icon-card-number-error"
src="{$img_dir|escape:'htmlall':'UTF-8'}card-icons/error.svg">
</div>
<div class="scheme-choice-frame"></div>
</div>


<div class="date-and-code">
<div>
Expand Down

0 comments on commit 1c01f4e

Please sign in to comment.