Updated gitignore

Added 2 recovery scripts
This commit is contained in:
David 2018-01-02 17:03:48 +01:00
parent 30dab6bcdf
commit 258cdc757a
3 changed files with 755 additions and 3 deletions

132
.gitignore vendored
View File

@ -1,3 +1,129 @@
/.settings/
/.buildpath
/.project
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries
# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
# Gradle:
.idea/**/gradle.xml
.idea/**/libraries
# CMake
cmake-build-debug/
# Mongo Explorer plugin:
.idea/**/mongoSettings.xml
## File-based project format:
*.iws
## Plugin-specific files:
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
### macOS template
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
### Eclipse template
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.recommenders
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# PyDev specific (Python IDE for Eclipse)
*.pydevproject
# CDT-specific (C/C++ Development Tooling)
.cproject
# Java annotation processor (APT)
.factorypath
# PDT-specific (PHP Development Tools)
.buildpath
# sbteclipse plugin
.target
# Tern plugin
.tern-project
# TeXlipse plugin
.texlipse
# STS (Spring Tool Suite)
.springBeans
# Code Recommenders
.recommenders/
# Scala IDE specific (Scala & Java development for Eclipse)
.cache-main
.scala_dependencies
.worksheet

346
replay_paybox.php Normal file
View File

@ -0,0 +1,346 @@
<?php
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
$_SERVER['SERVER_NAME'] = 'www.bebeboutik.com';
$_SERVER['HTTP_PORT'] = 80;
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['SERVER_PORT'] = 80;
include __DIR__ . '/www/config/config.inc.php';
if (version_compare(_PS_VERSION_, '1.5', '<')) {
include __DIR__ . '/www/init.php';
}
include __DIR__ . '/www/modules/paybox/paybox.php';
$test_mode = (int)Configuration::get('PBX_DEMO_MODE');
$paybox = new Paybox();
$fp = fopen(__DIR__ . '/name_of_my_extract.csv', 'r');
$errorcount = 0;
$count = 0;
if ($fp) {
while (($line = fgets($fp)) !== false) {
$infos = str_getcsv($line, ';', '"');
$error = '';
if ($infos[0] !== 'RemittancePaybox' && $infos[14] === 'Autorisation') {
$values = array();
$values['a'] = $infos[16]; //NumberOfAuthorization
$values['r'] = $infos[12]; //Reference
$values['t'] = $infos[8]; //callnumber
$values['s'] = $infos[7]; //ref paybox
$values['p'] = 'CARTE'; //paiement type
if (substr($infos[23], 0, 3) === 'CB-') {
$values['c'] = substr($infos[23], 3);
} else {
$values['c'] = $infos[23];
}
$values['m'] = $infos[17]; //amount
$values['i'] = $infos[22]; //card country
$values['y'] = $infos[21]; //country ip
if ($infos[31] === '') {
$values['e'] = '00000'; //errors
} else {
$values['e'] = $infos[31];
}
$values['d'] = '0118';
/*
r=1412537 //cart
t=776182861 //call number 776182861
a=615260 //autho number
b=0
p=CARTE //card
c=MasterCard //cardname
s=759782572 //ref paybox
y=FRA //country
i=FRA // country card
e=00000 //errors
n=513283
j=05
d=1809
*/
$x3 = false;
if (substr($values['r'], 0, 1) == 'x') {
$x3 = true;
$id_cart = substr($values['r'], 1);
} else {
$id_cart = $values['r'];
}
$cart = new Cart((int)$id_cart);
if (!$cart->id) {
Logger::addLog('Cart not valid', 4);
die('Cart not valid');
}
if (!Order::getOrderByCartId($cart->id)) {
echo "order nok \n";
$errorcount++;
echo json_encode($values) . "\n";
echo "processing order" . "\n";
$customer = new Customer((int)$cart->id_customer);
if ($x3) {
$total_paid = ($values['m'] * 3) / 100;
if (($cart->getOrderTotal() - $total_paid) < 2) {
$total_paid = $cart->getOrderTotal();
}
} else {
$total_paid = $values['m'] / 100;
}
$pbx_error = trim($values['e']);
$statut = '';
if ($test_mode === 0) {
if (empty($error) && $pbx_error == '00000') {
$error = '***TEST*** : Validated Payment <br>' . "\n";
$statut = _PS_OS_PAYMENT_;
} else {
$error = '***TEST*** : Invalid Payment <br>' . "\n" . $error;
$statut = _PS_OS_ERROR_;
}
} elseif ($test_mode === 1) {
if ($pbx_error == '00000' && empty($error)) {
$statut = _PS_OS_PAYMENT_;
} else {
$statut = _PS_OS_ERROR_;
}
}
switch ($pbx_error) {
case '00001':
$error .= 'Connection to the authorization center failed or an internal error occurred <br>' . "\n";
break;
case '00003':
$error .= 'Paybox error<br>' . "\n";
break;
case '00004':
$error .= 'Card number invalid or visual cryptogram invalid <br>' . "\n";
break;
case '00006':
$error .= 'Access refused or site/rank/identifier incorrect <br>' . "\n";
break;
case '00008':
$error .= 'Incorrect expiry date.<br>' . "\n";
break;
case '00009':
$error .= 'Error when during subscriber creation<br>' . "\n";
break;
case '00010':
$error .= 'Unknown currency<br>' . "\n";
break;
case '00011':
$error .= 'Amount incorrect<br>' . "\n";
break;
case '00015':
$error .= 'Payment already done<br>' . "\n";
break;
case '00016':
$error .= 'Subscriber already exists<br>' . "\n";
break;
case '00021':
$error .= 'Not authorized bin card<br>' . "\n";
break;
case '00029':
$error .= 'Not the same card used for the first payment.<br>' . "\n";
break;
case '00030':
$error .= 'Time-out > 15 mn before validation by the buyer when the buyer is on the page of payments of PAYBOX<br>' . "\n";
break;
case '00031':
case '00032':
$error .= 'Reserved<br>' . "\n";
break;
case '00033':
$error .= 'Unauthorized country code of the IP address of the cardholders browser<br>' . "\n";
break;
case '00040':
$error .= 'Operation without 3DSecure authentication, blocked by the fraud filter.<br>' . "\n";
break;
case '99999':
$error .= 'Payment waiting confirmation from the issuer<br>' . "\n";
break;
// Card schemes Carte Bancaire, American Express and Diners
case '00100':
$error .= 'Transaction approved or successfully processed.<br>' . "\n";
break;
case '00101':
case '00102':
$error .= 'Contact the card issuer<br>' . "\n";
break;
case '00103':
$error .= 'Invalid retailer<br>' . "\n";
break;
case '00104':
$error .= 'Keep the card<br>' . "\n";
break;
case '00105':
$error .= 'Do not honor<br>' . "\n";
break;
case '00107':
$error .= 'Keep the card, special conditions<br>' . "\n";
break;
case '00108':
$error .= 'Approve after holder identification<br>' . "\n";
break;
case '00112':
$error .= 'Invalid transaction<br>' . "\n";
break;
case '00113':
$error .= 'Invalid amount<br>' . "\n";
break;
case '00114':
$error .= 'Invalid holder number<br>' . "\n";
break;
case '00115':
$error .= 'Card issuer unknown<br>' . "\n";
break;
case '00117':
$error .= 'Client cancellation<br>' . "\n";
break;
case '00119':
$error .= 'Repeat the transaction later<br>' . "\n";
break;
case '00120':
$error .= 'Error in reply (error in the servers domain).<br>' . "\n";
break;
case '00124':
$error .= 'File update not withstood<br>' . "\n";
break;
case '00125':
$error .= 'Impossible to situate the record in the file<br>' . "\n";
break;
case '00126':
$error .= 'Record duplicated, former record replaced<br>' . "\n";
break;
case '00127':
$error .= 'Error in edit in file update field<br>' . "\n";
break;
case '00128':
$error .= 'Access to file denied<br>' . "\n";
break;
case '00129':
$error .= 'File update impossible<br>' . "\n";
break;
case '00130':
$error .= 'Error in format<br>' . "\n";
break;
case '00133':
$error .= 'Expired card<br>' . "\n";
break;
case '00138':
$error .= 'Too many attempts at secret code.<br>' . "\n";
break;
case '00151':
$error .= 'provision insuffisante.<br>' . "\n";
break;
case '00159':
$error .= 'Suspicion of fraud.<br>' . "\n";
break;
case '00000':
default:
$error .= '<b>Successful operation</b><br>' . "\n\n";
break;
}
echo 'PayBox version: ' . $paybox->version . "\n";
echo "(int)$cart->id, $statut, $total_paid, $paybox->displayName, $error, $customer->secure_key, $values\n";
$paybox->validateOrder((int)$cart->id, $statut, $total_paid, $paybox->displayName, $error, array(), NULL, false, $customer->secure_key, $values);
// save info paiement BDD
$paybox->saveInformationPaiement($values);
}
}
}
fclose($fp);
}
echo 'count ok ' . $count . "\n";
echo 'count nok ' . $errorcount . "\n";
die();
/*
$error = '';
$paybox = new Paybox();
$values = array(
'm', 'r', 't', 'p', 'c', 's'
);
$needed_vars = array('m', 'r', 't', 'p', 'c', 's');
if ((!isset($values['a']) || empty($values['a'])))
{
Logger::addLog('No autorisation number', 4);
die('No autorisation number');
}
$x3 = false;
if (substr($values['r'],0, 1) == 'x')
{
$x3 = true;
$id_cart = substr($values['r'],1);
}
else
$id_cart = $values['r'];
$cart = new Cart((int)$id_cart);
if (!$cart->id)
{
Logger::addLog('Cart not valid', 4);
die('Cart not valid');
}
if ($id_order = (int)Order::getOrderByCartId($cart->id))
{
$paybox->saveInformationPaiement($values);
if (empty($error))
{
$order = new Order($id_order);
$order->valid = 1;
$order->total_paid_real = $values['m'] / 100;
$order->update();
if ($order->getCurrentState() != _PS_OS_PAYMENT_)
{
$products = $cart->getProducts();
foreach ($products as $product)
{
Product::updateQuantity($product);
Hook::updateQuantity($product, $order);
}
}
$history = new OrderHistory();
$history->id_order = $id_order;
$history->changeIdOrderState((int)_PS_OS_PAYMENT_, $id_order);
$history->addWithemail(true, array());
$order_message = '';
foreach ($values as $key => $value)
$order_message .= $key.': '.$value.'<br>';
if (isset($order_message) && !empty($order_message))
{
$msg = new Message();
$message = $order_message;
if (Validate::isCleanHtml($order_message))
{
$msg->message = $order_message;
$msg->id_order = (int)$order->id;
$msg->private = 1;
$msg->add();
}
}
}
die($error);
}
*/

280
replay_paypal.php Normal file
View File

@ -0,0 +1,280 @@
<?php
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
$_SERVER['SERVER_NAME'] = 'www.bebeboutik.com';
$_SERVER['HTTP_PORT'] = 80;
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['SERVER_PORT'] = 80;
@ini_set('display_errors', 'on');
include __DIR__ . '/www/config/config.inc.php';
if (version_compare(_PS_VERSION_, '1.5', '<')) {
include __DIR__ . '/www/init.php';
}
include_once(_PS_MODULE_DIR_ . 'paypal/express_checkout/process.php');
include_once(_PS_MODULE_DIR_ . 'paypal/express_checkout/submit.php');
include_once(_PS_MODULE_DIR_ . 'paypal/paypal_login/PayPalLoginUser.php');
echo 'starting' . "\n";
$scriptDebug = true;
$fp = fopen(__DIR__ . '/Download.csv', 'r');
$errorCount = 0;
$customerNotFoundCount = 0;
$count = 0;
$customerFoundCount = 0;
$emailToIdCustomerArray = array();
$report = array(
'wrongTotal' => array(),
'missingOrder' => array(),
'multipleOrders' => array(),
'foundWithEmail' => array(),
'foundWithPaypalTable' => array(),
'foundWithFnLn' => array(),
'lostCustomers' => array(),
'orderToProcess' => array()
);
if ($fp) {
echo 'Reading ' . __DIR__ . '/Download.csv' . "\n";
while (($line = fgets($fp)) !== false) {
$splitCsvLine = str_getcsv($line, ',', '"');
$error = '';
if ($splitCsvLine[1] !== 'Heure' && $splitCsvLine[10] !== 'contact@bebeboutik.com') {
$count++;
$values = array();
$values['amount'] = str_replace(',', '.', $splitCsvLine[7]);
$values['email'] = $splitCsvLine[10];
$values['firstname_lastname'] = $splitCsvLine[3];
$values['id_transaction'] = $splitCsvLine[12];
$values['shipping_cost'] = str_replace(',', '.', $splitCsvLine[17]);
$values['date'] = $splitCsvLine[0] . ' ' . $splitCsvLine[1];
$exploded = explode(' ', $values['firstname_lastname']);
if (count($exploded) === 2) {
$values['possible_first_name'] = $exploded[0];
$values['possible_last_name'] = $exploded[1];
} else {
$values['possible_first_name'] = $exploded[0];
unset($exploded[0]);
$values['possible_last_name'] = implode(' ', $exploded);
}
if (!array_key_exists($values['email'], $emailToIdCustomerArray)) {
//check paypal table first
$result = Db::getInstance()->getRow('
SELECT id_customer
FROM ps_paypal_customer
WHERE paypal_email = \'' . pSQL($values['email']) . '\'');
if ($result) {
$customer = new Customer((int)$result['id_customer']);
}
if ($customer->id !== null && $result) {
$report['foundWithPaypalTable'][$values['email']] = $customer->id;
$emailToIdCustomerArray[$values['email']] = (int)$customer->id;
} else {
$customer = new Customer();
$customer->getByEmail($values['email']);
if (Validate::isLoadedObject($customer)) {
$emailToIdCustomerArray[$values['email']] = (int)$customer->id;
$report['foundWithEmail'][$values['email']] = (int)$customer->id;
} else {
$result = Db::getInstance()->getRow('
SELECT id_customer
FROM `ps_customer`
WHERE `active` = 1
AND lower(`firstname`) = \'' . pSQL(strtolower($values['possible_first_name'])) . '\'
AND lower(`lastname`) = \'' . pSQL(strtolower($values['possible_last_name'])) . '\'
AND `deleted` = 0
AND `is_guest` = 0');
if ($result) {
$customer = new Customer((int)$result['id_customer']);
$report['foundWithFnLn'][$values['email']] = $customer->id;
$emailToIdCustomerArray[$values['email']] = (int)$customer->id;
} else {
$result = Db::getInstance()->getRow('
SELECT id_customer
FROM `ps_customer`
WHERE `active` = 1
AND lower(`lastname`) = \'' . pSQL(strtolower($values['possible_first_name'])) . '\'
AND lower(`firstname`) = \'' . pSQL(strtolower($values['possible_last_name'])) . '\'
AND `deleted` = 0
AND `is_guest` = 0');
if ($result) {
$customer = new Customer((int)$result['id_customer']);
$report['foundWithFnLn'][$values['email']] = $customer->id;
$emailToIdCustomerArray[$values['email']] = (int)$customer->id;
} else {
$report['lostCustomers'][] = array('email' => $values['email'],
'info' => $splitCsvLine);
}
}
}
}
}
if (Validate::isLoadedObject($customer)) {
$order = Db::getInstance()->getRow('
SELECT po.id_order, o.total_paid
FROM ps_paypal_order po
JOIN ps_orders o ON o.id_order = po.id_order
WHERE id_transaction = \'' . $values['id_transaction'] . '\''
);
if ($order) {
if ($values['amount'] !== $order['total_paid']) {
$report['wrongTotal'][] = $order['id_order'];
}
} else {
$orders = Db::getInstance()->ExecuteS('
SELECT o.id_order , o.total_paid
FROM `ps_orders` o
WHERE o.`id_customer` = ' . (int)$customer->id . '
AND o.date_add BETWEEN "2017-12-20 00:00:00" AND "2017-12-23 23:59:00"'
);
if ($orders) {
if (count($orders) === 1) {
if ($values['amount'] !== $orders[0]['total_paid']) {
$report['wrongTotal'][] = $orders[0]['id_order'];
}
} else {
$report['multipleOrders'][] = $customer->id;
}
} else {
//try to find
//now we try to find id_cart that could do the job
if (534175 === (int)$customer->id) {
echo 'test 534175';
}
$result = Db::getInstance()->ExecuteS('
SELECT c.`id_cart` , c.date_upd
FROM `ps_cart` c
WHERE c.`id_customer` = ' . (int)$customer->id . '
ORDER BY c.date_upd desc');
if (534175 === (int)$customer->id) {
echo json_encode($result);
}
if ($result && count($result) > 0) {
$selectedCartId = $result[0]['id_cart'];
foreach ($result as $cartResult) {
$cart = new Cart((int)$cartResult['id_cart']);
$cartValue = $cart->getOrderTotal();
if ((float)$values['amount'] === $cartValue) {
$selectedCartId = (int)$cartResult['id_cart'];
continue;
}
}
$selectedCart = new Cart($selectedCartId);
$cartValue = $selectedCart->getOrderTotal();
if ((float)$values['amount'] === $cartValue) {
$errorWIthCartValue = 'ok';
} else {
$errorWIthCartValue = 'not ok';
}
$foundVia = 'nothing';
if (array_key_exists($values['email'], $report['foundWithPaypalTable'])) {
$foundVia = 'paypaltable';
} elseif (array_key_exists($values['email'], $report['foundWithEmail'])) {
$foundVia = 'email';
} elseif (array_key_exists($values['email'], $report['foundWithFnLn'])) {
$foundVia = 'lastname';
}
$report['missingOrder'][] = array('customer_id' => $customer->id,
'amount' => $values['amount'],
'transaction_id' => $values['id_transaction'],
'id_cart' => $selectedCart->id,
'cart_value' => $cartValue,
'error_with_cart_value' => $errorWIthCartValue,
'foundVia' => $foundVia
);
if ($errorWIthCartValue === 'ok') {
$report['orderToProcess'][$values['id_transaction']] = array('customer_id' => $customer->id,
'amount' => $values['amount'],
'transaction_id' => $values['id_transaction'],
'id_cart' => $selectedCart->id,
'email' => $values['email'],
'shipping_cost' => $values['shipping_cost'],
'order_time' => $values['date']
);
}
} else {
$report['missingOrder'][] = array('customer_id' => $customer->id,
'amount' => $values['amount'],
'transaction_id' => $values['id_transaction'],
'id_cart' => 'not found'
);
}
}
}
}
}
}
$report['missingOrderCount'] = count($report['missingOrder']);
$report['wrongTotalCount'] = count($report['wrongTotal']);
$report['missingOrderCount'] = count($report['missingOrder']);
$report['foundWithEmailCount'] = count($report['foundWithEmail']);
$report['foundWithPaypalTableCount'] = count($report['foundWithPaypalTable']);
$report['foundWithFnLnCount'] = count($report['foundWithFnLn']);
$report['lostCustomersCount'] = count($report['lostCustomers']);
$report['orderToProcessCount'] = count($report['orderToProcess']);
fclose($fp);
}
if ($scriptDebug) {
echo 'count nb lines ' . $count . "\n";
echo 'unique customers found ' . count($emailToIdCustomerArray) . "\n";
echo 'customer not found ' . $customerNotFoundCount . "\n";
echo '---report' . "\n";
echo json_encode($report) . "\n";
}
unset($values);
foreach ($report['orderToProcess'] as $id_transaction => $orderToProcess) {
echo 'treating cart ' . $orderToProcess['id_cart'] . "\n";
$request_type = 'payment_cart';
$ppec = new PaypalExpressCheckout($request_type);
$cart = new Cart((int)$orderToProcess['id_cart']);
$customer = new Customer((int)$cart->id_customer);
if (!$cart->OrderExists()) {
$payment_type = (int)Configuration::get('PS_OS_PAYMENT');
$payment_status = 'Completed';
$message = $ppec->l('Payment accepted.') . '<br />';
$transaction = array(
'currency' => 'EUR',
'id_invoice' => null,
'id_transaction' => $id_transaction,
'transaction_id' => $id_transaction,
'total_paid' => (float)$orderToProcess['amount'],
'shipping' => (float)$orderToProcess['shipping_cost'],
'payment_date' => $orderToProcess['order_time'],
'payment_status' => $payment_status
);
$order_total = (float)$cart->getOrderTotal(true, Cart::BOTH);
if ($scriptDebug) {
$params = array(
'cart_id ' => (int)$cart->id,
'payment_type' => $payment_type,
'order_total' => $order_total,
'displayName' => 'PayPal',
'message' => $message,
'transaction' => $transaction,
'cart->id_currency' => (int)$cart->id_currency,
'customer->secure_key' => $customer->secure_key
);
echo json_encode($params);
} else {
$ppec->validateOrder((int)$cart->id, $payment_type, $order_total, 'PayPal', $message, $transaction,
(int)$cart->id_currency, false, $customer->secure_key);
}
}
}