update
This commit is contained in:
218
modules/santandercredit/sql/ScbDbUtil.php
Normal file
218
modules/santandercredit/sql/ScbDbUtil.php
Normal file
@@ -0,0 +1,218 @@
|
||||
<?php
|
||||
|
||||
use PhpParser\Node\Stmt\TryCatch;
|
||||
|
||||
require_once dirname(__FILE__) . '/../../../config/config.inc.php';
|
||||
include_once dirname(__FILE__) . '/../services/ProposalService/HybridClient/Application.php';
|
||||
include_once dirname(__FILE__) . '/../services/ProposalService/HybridClient/OperationStatus.php';
|
||||
/**
|
||||
* Source Application Number to id_order converter
|
||||
*
|
||||
*/
|
||||
class ScbDbUtil {
|
||||
|
||||
public static function getIdOrder($ShopApplicationNumber) {
|
||||
$query = 'SELECT id_order FROM ' . _DB_PREFIX_ . 'scb_ehp_order_app_mapping where pos_app_number = \''.$ShopApplicationNumber. '\'';
|
||||
$idOrder = Db::getInstance()->getValue($query);
|
||||
if($idOrder){
|
||||
return $idOrder;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static function getShopApplicationNumber($IdOrder){
|
||||
$query = 'SELECT pos_app_number FROM ' . _DB_PREFIX_ . 'scb_ehp_order_app_mapping where id_order = '.$IdOrder;
|
||||
$san = Db::getInstance()->getValue($query);
|
||||
return $san;
|
||||
}
|
||||
|
||||
public static function RegisterSuccessfullPshResponse($shopAppNr, $operationStatus, $application) {
|
||||
$shop = trim(Configuration::get('SANTANDERCREDIT_SHOP_ID'));
|
||||
$numbers2check = [];
|
||||
$cnt = count(CHECK_THIS_STATES);
|
||||
for($i = 0; $i < $cnt; $i++) {
|
||||
array_push($numbers2check, Configuration::get(EHP_ORDER_STATE_PREFIX . CHECK_THIS_STATES[$i]));
|
||||
}
|
||||
$token = '';
|
||||
$orderObj = new Order(ScbDbUtil::getIdOrder($shopAppNr));
|
||||
$currentOrderState = $orderObj->getCurrentOrderState();
|
||||
$newOrderState = ScbDbUtil::mapCreditStateToOrderState($application->CreditState, $currentOrderState);
|
||||
$checkIt = '0';
|
||||
$cnt = count($numbers2check);
|
||||
for($i = 0; $i < $cnt; $i++){
|
||||
if($newOrderState == $numbers2check[$i]){
|
||||
$checkIt = '1';
|
||||
break;
|
||||
}
|
||||
}
|
||||
$request_date = date("Y-m-d H:i:s");
|
||||
$agreementDate = null;
|
||||
$appStatusChgDate = null;
|
||||
if(isset($application->AgreementDate)){
|
||||
$agreementDate = date("Y-m-d H:i:s",strtotime($application->AgreementDate));
|
||||
}
|
||||
if(isset($application->ChangeDate)){
|
||||
$appStatusChgDate = date("Y-m-d H:i:s",strtotime($application->ChangeDate));
|
||||
}
|
||||
$sql = [
|
||||
'INSERT INTO ' . _DB_PREFIX_ . 'scb_ehp_log (
|
||||
id_order,
|
||||
pos_app_number,
|
||||
application_number,
|
||||
agreement_number,
|
||||
agreement_date,
|
||||
shop_number,
|
||||
ehp_token,
|
||||
request_date,
|
||||
success,
|
||||
application_status,
|
||||
app_status_chg_date,
|
||||
downpayment,
|
||||
total_price
|
||||
) VALUES ('
|
||||
.ScbDbUtil::getIdOrder($shopAppNr) . ',\''
|
||||
.$shopAppNr . '\',\''
|
||||
.$application->ApplicationNumber . '\',\''
|
||||
.$application->AgreementNumber . '\',\''
|
||||
.$agreementDate . '\',\''
|
||||
.$shop . '\',\''
|
||||
.$token . '\',\''
|
||||
.$request_date . '\','
|
||||
.'1,\''
|
||||
.$application->CreditState . '\',\''
|
||||
.$appStatusChgDate . '\','
|
||||
.$application->Downpayment . ','
|
||||
.$application->TotalPrice . ');'
|
||||
,'UPDATE ' . _DB_PREFIX_ . 'scb_ehp_order_app_mapping SET '
|
||||
.'application_number = \'' . $application->ApplicationNumber . '\', '
|
||||
.'agreement_number = \'' . $application->AgreementNumber . '\', '
|
||||
.'agreement_date = \'' . $agreementDate . '\', '
|
||||
.'ehp_token = \'' . $token . '\', '
|
||||
.'order_status = \'' . $newOrderState . '\', '
|
||||
.'application_status = \'' . $application->CreditState . '\', '
|
||||
.'app_status_chg_date = \'' . $appStatusChgDate . '\', '
|
||||
.'downpayment = ' . $application->Downpayment . ','
|
||||
.'total_price = ' . $application->TotalPrice . ', '
|
||||
.'check_date = \'' . $request_date . '\', '
|
||||
.'check_it = ' . $checkIt
|
||||
.' WHERE pos_app_number = \'' . $shopAppNr .'\''
|
||||
];
|
||||
|
||||
foreach ($sql as $query) {
|
||||
Db::getInstance()->execute($query);
|
||||
}
|
||||
|
||||
if ($currentOrderState->id <> $newOrderState) {
|
||||
$orderObj->setCurrentState($newOrderState);
|
||||
$orderObj->save();
|
||||
};
|
||||
}
|
||||
|
||||
public static function LogIncorrectPshResponse($shopAppNr, $operationStatus, $errorInfo) {
|
||||
if(isset($shopAppNr) and is_object($operationStatus) and is_string($errorInfo)) {
|
||||
$shop = trim(Configuration::get('SANTANDERCREDIT_SHOP_ID'));
|
||||
$request_date = date("Y-m-d H:i:s");
|
||||
$token = '';
|
||||
$sql = [
|
||||
'INSERT INTO ' . _DB_PREFIX_ . 'scb_ehp_log (
|
||||
id_order,
|
||||
pos_app_number,
|
||||
shop_number,
|
||||
ehp_token,
|
||||
request_date,
|
||||
success,
|
||||
message
|
||||
) VALUES ('
|
||||
.ScbDbUtil::getIdOrder($shopAppNr) . ',\''
|
||||
.$shopAppNr . '\',\''
|
||||
.$shop . '\',\''
|
||||
.$token . '\',\''
|
||||
.$request_date . '\','
|
||||
.'0,\'' . $errorInfo . '\')'
|
||||
];
|
||||
|
||||
foreach ($sql as $query) {
|
||||
Db::getInstance()->execute($query);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static function mapCreditStateToOrderState($CreditState, $currentOrderState){
|
||||
$currentOrderStateId = $currentOrderState->id;
|
||||
$newOrderState = $currentOrderStateId;
|
||||
$luckyNumbers = [];
|
||||
foreach(EHP_APP_STATES as $key => $value) {
|
||||
$statNameNoPrefix = $key;
|
||||
$orderStateName = EHP_ORDER_STATE_PREFIX . $statNameNoPrefix;
|
||||
$StateId = Configuration::get($orderStateName);
|
||||
array_push($luckyNumbers, $StateId);
|
||||
}
|
||||
$editable = false;
|
||||
$cnt = count($luckyNumbers);
|
||||
for($i = 0; $i < $cnt; $i++) {
|
||||
if($currentOrderStateId == $luckyNumbers[$i]) {
|
||||
$editable = true;
|
||||
}
|
||||
}
|
||||
if($editable){
|
||||
if(array_key_exists($CreditState, BANK2SHOP_STATE_MAP)) {
|
||||
$statNameNoPrefix = BANK2SHOP_STATE_MAP[$CreditState];
|
||||
$orderStateName = EHP_ORDER_STATE_PREFIX . $statNameNoPrefix;
|
||||
$newOrderState = (int) Configuration::get($orderStateName);
|
||||
}
|
||||
}
|
||||
return $newOrderState;
|
||||
}
|
||||
|
||||
public static function getFullApplicationInfo($id_order){
|
||||
$app = new Application();
|
||||
$query = 'SELECT * FROM ' . _DB_PREFIX_ . 'scb_ehp_order_app_mapping where id_order = '.$id_order;
|
||||
$result = Db::getInstance()->executeS($query);
|
||||
foreach($result as $row){
|
||||
$app->AgreementDate = $row['agreement_date'];
|
||||
$app->AgreementNumber = $row['agreement_number'];
|
||||
$app->ApplicationNumber = $row['application_number'];
|
||||
$app->ChangeDate = $row['app_status_chg_date'];
|
||||
$app->CreditState = $row['application_status'];
|
||||
$app->Downpayment = $row['downpayment'];
|
||||
$app->ShopApplicationNumber = $row['pos_app_number'];
|
||||
$app->ShopNumber = $row['shop_number'];
|
||||
$app->TotalPrice = $row['total_price'];
|
||||
$app->check_date = $row['check_date'];
|
||||
}
|
||||
return $app;
|
||||
}
|
||||
|
||||
public static function getOrders2check(){
|
||||
$orderArray = [];
|
||||
$query = 'SELECT pos_app_number FROM ' . _DB_PREFIX_ . 'scb_ehp_order_app_mapping WHERE `date_add` > DATE_ADD(NOW(), INTERVAL -14 DAY) AND check_it = 1 order by check_date limit 20';
|
||||
$result = Db::getInstance()->executeS($query);
|
||||
foreach($result as $row){
|
||||
array_push($orderArray, $row['pos_app_number']);
|
||||
}
|
||||
return $orderArray;
|
||||
}
|
||||
|
||||
public static function updateCheckDate($arrayOfOrders){
|
||||
$request_date = date("Y-m-d H:i:s");
|
||||
$query = 'UPDATE ' . _DB_PREFIX_ . 'scb_ehp_order_app_mapping SET ';
|
||||
$query = $query . ' check_date = \'' . $request_date . '\' WHERE pos_app_number in (';
|
||||
$notEmpty = 0;
|
||||
foreach ($arrayOfOrders as $shopAppNumber) {
|
||||
$query = $query . '\'' . $shopAppNumber . '\',';
|
||||
$notEmpty = 1;
|
||||
}
|
||||
if($notEmpty > 0){
|
||||
$query = substr($query, 0, strlen($query) - 1);
|
||||
$query = $query . ')';
|
||||
Db::getInstance()->execute($query);
|
||||
}
|
||||
}
|
||||
|
||||
public static function updateAppStates($apps, $opState){
|
||||
foreach ($apps as $key => $a) {
|
||||
ScbDbUtil::RegisterSuccessfullPshResponse($a->ShopApplicationNumber, $opState, $a);
|
||||
}
|
||||
}
|
||||
}
|
||||
34
modules/santandercredit/sql/index.php
Normal file
34
modules/santandercredit/sql/index.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2021 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2021 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||
header('Pragma: no-cache');
|
||||
|
||||
header('Location: ../');
|
||||
exit;
|
||||
77
modules/santandercredit/sql/installDB.php
Normal file
77
modules/santandercredit/sql/installDB.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* service: HTTP_POST/ProposalServiceHybrid
|
||||
* method: POST/GetOrderStatus
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
$sql = array();
|
||||
|
||||
//(0 if there is no ehp db)
|
||||
$dbv = SantanderCredit::getEhpDbVersion();
|
||||
|
||||
//next db version
|
||||
if($dbv < 1){
|
||||
$sql = [
|
||||
'CREATE TABLE IF NOT EXISTS ' . _DB_PREFIX_ . 'scb_ehp_log (
|
||||
id INT(10) NOT NULL AUTO_INCREMENT ,
|
||||
id_order int(10),
|
||||
pos_app_number varchar(64) NOT NULL,
|
||||
application_number varchar(64) NULL ,
|
||||
agreement_number varchar(64) NULL ,
|
||||
agreement_date DATETIME NULL ,
|
||||
shop_number VARCHAR(10) NOT NULL ,
|
||||
ehp_token VARCHAR(128) NULL ,
|
||||
request_date DATETIME NOT NULL ,
|
||||
success INT(1) NOT NULL ,
|
||||
application_status VARCHAR(60) NULL ,
|
||||
app_status_chg_date DATETIME NULL ,
|
||||
downpayment DECIMAL(10,2) NULL,
|
||||
total_price DECIMAL(10,2) NULL,
|
||||
message TEXT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
INDEX `scb_ehp_san_idx` (`pos_app_number`),
|
||||
INDEX `scb_ehp_app_number_idx` (`application_number`),
|
||||
INDEX `scb_ehp_id_order_idx` (`id_order`));',
|
||||
'CREATE TABLE IF NOT EXISTS ' . _DB_PREFIX_ . 'scb_ehp_order_app_mapping (
|
||||
id_order int(10) NOT NULL,
|
||||
date_add DATETIME NOT NULL ,
|
||||
pos_app_number varchar(64) NOT NULL,
|
||||
reference varchar(64) NULL ,
|
||||
application_number varchar(64) NULL ,
|
||||
agreement_number varchar(64) NULL ,
|
||||
agreement_date DATETIME NULL ,
|
||||
ehp_token VARCHAR(128) NULL ,
|
||||
order_status VARCHAR(60) NULL ,
|
||||
application_status VARCHAR(60) NULL ,
|
||||
app_status_chg_date DATETIME NULL ,
|
||||
shop_number VARCHAR(10) NOT NULL ,
|
||||
downpayment DECIMAL(10,2) NULL,
|
||||
total_price DECIMAL(10,2) NULL,
|
||||
post_data TEXT NULL,
|
||||
check_date DATETIME NULL,
|
||||
check_it INT (1) NOT NULL ,
|
||||
PRIMARY KEY (`pos_app_number`),
|
||||
INDEX `scb_ehp_app_number_idx` (`application_number`),
|
||||
INDEX `scb_ehp_check_date_idx` (`check_date`),
|
||||
INDEX `scb_ehp_check_it_idx` (`check_it`),
|
||||
INDEX `scb_ehp_id_order_idx` (`id_order`));',
|
||||
'CREATE TABLE IF NOT EXISTS ' . _DB_PREFIX_ . 'scb_ehp_phist (
|
||||
id int(10) NOT NULL AUTO_INCREMENT,
|
||||
h_date datetime NOT NULL ,
|
||||
db_ver int(10) NULL ,
|
||||
module_ver varchar(10),
|
||||
params VARCHAR(1024) NULL ,
|
||||
PRIMARY KEY (`id`));'
|
||||
];
|
||||
}
|
||||
|
||||
$dbv = 1;
|
||||
|
||||
$qUpdDbv = 'INSERT INTO ' . _DB_PREFIX_ . 'scb_ehp_phist (h_date, db_ver, module_ver) VALUES (';
|
||||
$qUpdDbv = $qUpdDbv.'\''.date("Y-m-d H:i:s").'\','.strval($dbv).',\''.$this->version.'\')';
|
||||
array_push($sql, $qUpdDbv);
|
||||
foreach ($sql as $query) {
|
||||
Db::getInstance()->execute($query);
|
||||
}
|
||||
23
modules/santandercredit/sql/repair_oa_mapping.php
Normal file
23
modules/santandercredit/sql/repair_oa_mapping.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
use PhpParser\Node\Stmt\TryCatch;
|
||||
/**
|
||||
* Reference is used only for checking if there is correct id_order in
|
||||
* scb_ehp_order_app_mapping record.
|
||||
* As POSApplicationNumber is used id_order with time stamp in addition.
|
||||
* Construction: id_order_yyyy_MM_dd_hh_mm_ss
|
||||
* Something like this: 12_2023_11_25_12_54_45.
|
||||
* id_order = 12
|
||||
* time stamp: 2023-11-25 12:54:45
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../../../config/config.inc.php';
|
||||
|
||||
try {
|
||||
$query = 'update ' . _DB_PREFIX_ . 'scb_ehp_order_app_mapping oa_map left join ';
|
||||
$query = $query . _DB_PREFIX_ . 'orders o on o.reference = oa_map.order_reference set oa_map.id_order = o.id_order';
|
||||
Db::getInstance()->execute($query);
|
||||
echo '{"isOk":"1"}';
|
||||
} catch (\Throwable $th) {
|
||||
echo '{"isOk":"0"}';
|
||||
}
|
||||
38
modules/santandercredit/sql/uninstall.php
Normal file
38
modules/santandercredit/sql/uninstall.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2021 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2021 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
/**
|
||||
* In some cases you should not drop the tables.
|
||||
* Maybe the merchant will just try to reset the module
|
||||
* but does not want to loose all of the data associated to the module.
|
||||
*/
|
||||
$sql = array();
|
||||
|
||||
foreach ($sql as $query) {
|
||||
if (Db::getInstance()->execute($query) == false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user