CS and comment
This commit is contained in:
parent
c13496d8e1
commit
063ce25d01
@ -532,26 +532,28 @@ class Paybox extends PaymentModule
|
||||
}
|
||||
}
|
||||
|
||||
public function hookcancelShipping($params) {
|
||||
/**
|
||||
* Refund shipping
|
||||
* @param array $params
|
||||
* @return void|boolean
|
||||
*/
|
||||
public function hookcancelShipping($params)
|
||||
{
|
||||
global $cookie;
|
||||
|
||||
if(Tools::getValue('noCancelHook')) {
|
||||
if (Tools::getValue('noCancelHook')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if(Tools::isSubmit('generateDiscount'))
|
||||
// return false;
|
||||
if ($params['order']->module != $this->name) {
|
||||
return false;
|
||||
}
|
||||
if (!($order = $params['order']) OR !Validate::isLoadedObject($order)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if($params['order']->module != $this->name)
|
||||
return false;
|
||||
if(!($order = $params['order']) OR !Validate::isLoadedObject($order))
|
||||
return false;
|
||||
|
||||
if($cookie->profile == 1
|
||||
|| $cookie->profile == 7
|
||||
|| $cookie->profile == 14
|
||||
|| $cookie->profile == 11) {
|
||||
if(!$order->hasBeenPaid()) {
|
||||
if (in_array($cookie->profile, array(1,7,14,11))) {
|
||||
if (!$order->hasBeenPaid()) {
|
||||
// mail('thibault@antadis.com', 'Erreur remboursement', 'Erreur de remboursement sur la commande ' . $order_detail->id_order . ' la commande n\'a pas été payée.');
|
||||
mail('karen@bebeboutik.com', 'Erreur remboursement', 'Erreur de remboursement sur la commande ' . $order_detail->id_order . ' la commande n\'a pas été payée.');
|
||||
mail('doreen@bebeboutik.com', 'Erreur remboursement', 'Erreur de remboursement sur la commande ' . $order_detail->id_order . ' la commande n\'a pas été payée.');
|
||||
@ -564,37 +566,34 @@ class Paybox extends PaymentModule
|
||||
}
|
||||
}
|
||||
|
||||
public function hookcancelProduct($params) {
|
||||
/**
|
||||
* Refund product(s)
|
||||
* @param array $params
|
||||
* @return boolean
|
||||
*/
|
||||
public function hookcancelProduct($params)
|
||||
{
|
||||
global $cookie;
|
||||
|
||||
// if(Tools::isSubmit('generateDiscount')) {
|
||||
// return FALSE;
|
||||
// }
|
||||
|
||||
if($params['order']->module != $this->name) {
|
||||
return FALSE;
|
||||
if ($params['order']->module != $this->name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!($order_detail = new OrderDetail((int)($params['id_order_detail'])))
|
||||
if (!($order_detail = new OrderDetail((int)($params['id_order_detail'])))
|
||||
|| !Validate::isLoadedObject($order_detail)) {
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
$employee = new Employee((int) $cookie->id_employee);
|
||||
if(!Validate::isLoadedObject($employee)) {
|
||||
return FALSE;
|
||||
if (!Validate::isLoadedObject($employee)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Tools::isSubmit('generateCreditSlip')) {
|
||||
if($cookie->profile == 1
|
||||
|| $cookie->profile == 7
|
||||
|| $cookie->profile == 14
|
||||
|| $cookie->profile == 11) {
|
||||
|
||||
if (in_array($cookie->profile, array(1,7,14,11))) {
|
||||
$order = new Order($order_detail->id_order);
|
||||
|
||||
if ($order->payment == "Paybox") {
|
||||
if(!$order->hasBeenPaid()) {
|
||||
if (!$order->hasBeenPaid()) {
|
||||
// mail('thibault@antadis.com', 'Erreur remboursement la commande nest pas valide pour etre rembourse', 'Erreur de remboursement sur la commande ' . $order_detail->id_order . ' la commande n\'a pas été payée.');
|
||||
mail('karen@bebeboutik.com', 'Erreur remboursement', 'Erreur de remboursement sur la commande ' . $order_detail->id_order . ' la commande n\'a pas été payée.');
|
||||
mail('doreen@bebeboutik.com', 'Erreur remboursement', 'Erreur de remboursement sur la commande ' . $order_detail->id_order . ' la commande n\'a pas été payée.');
|
||||
@ -603,46 +602,40 @@ class Paybox extends PaymentModule
|
||||
$this->refundProduct($params['id_order_detail']);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Rembourse un Order Detail
|
||||
* @param int $id_order_detail Numéro de ligne de commande à refund
|
||||
**/
|
||||
public function refundProduct($id_order_detail) {
|
||||
* Rembourse un Order Detail
|
||||
* @param int $id_order_detail Numéro de ligne de commande à refund
|
||||
* @return boolean
|
||||
*/
|
||||
public function refundProduct($id_order_detail)
|
||||
{
|
||||
global $cookie;
|
||||
|
||||
$order_detail = new OrderDetail($id_order_detail);
|
||||
$order = new Order($order_detail->id_order);
|
||||
$transaction = $this->loadTransaction($order->id_cart);
|
||||
|
||||
if(empty($transaction)) {
|
||||
if (empty($transaction)) {
|
||||
return false;
|
||||
} else {
|
||||
$products = $order->getProducts();
|
||||
|
||||
// quantite deja envoye
|
||||
$send_quantity = (int) Db::getInstance()->getValue('
|
||||
SELECT `quantity`
|
||||
FROM `'._DB_PREFIX_.'lapostews`
|
||||
WHERE `id_order_detail` = '. (int) $order_detail->id
|
||||
);
|
||||
|
||||
$quantity_available = $order_detail->product_quantity;
|
||||
// $quantity_available = $order_detail->product_quantity - (($send_quantity - $order_detail->product_quantity_return));
|
||||
|
||||
if ( $_POST['cancelQuantity'][(int) $order_detail->id] <= $quantity_available) {
|
||||
$total_shipping = (int) Db::getInstance()->getValue('
|
||||
|
||||
if ($_POST['cancelQuantity'][(int) $order_detail->id] <= $quantity_available) {
|
||||
|
||||
// Frais de port
|
||||
$total_shipping = (int) Db::getInstance()->getValue('
|
||||
SELECT `shipping_cost`
|
||||
FROM `'._DB_PREFIX_.'order_slip`
|
||||
WHERE `id_order` = '.(int) $order->id.'
|
||||
AND `shipping_cost` = 1
|
||||
');
|
||||
|
||||
// Déjà remboursé
|
||||
$total_refunded = (float) Db::getInstance()->getValue('
|
||||
SELECT SUM(ROUND((product_price * (1 - reduction_percent / 100) - reduction_amount) * (1 - group_reduction / 100) * (1 + tax_rate / 100), 2) * product_quantity_refunded)
|
||||
FROM `'._DB_PREFIX_.'order_detail`
|
||||
@ -653,6 +646,7 @@ class Paybox extends PaymentModule
|
||||
$amt = $products[(int) $order_detail->id]['product_price_wt'] * (int) ($_POST['cancelQuantity'][(int) $order_detail->id]);
|
||||
$montant = min($amt, $order->total_paid_real - ((int) $total_shipping * $order->total_shipping) - $total_refunded);
|
||||
|
||||
// Call Paybox and make the refund
|
||||
$refund = $this->sendRefundPaybox($montant, 978, $transaction['num_transaction'], $order->id_cart, $transaction['num_appel']);
|
||||
|
||||
if (!$refund) {
|
||||
@ -674,10 +668,12 @@ class Paybox extends PaymentModule
|
||||
}
|
||||
|
||||
/**
|
||||
* Remboursement des frais de port d'une commande
|
||||
* @param Object $order
|
||||
**/
|
||||
public function refundShipping($order) {
|
||||
* Remboursement des frais de port d'une commande
|
||||
* @param Object $order
|
||||
* @return boolean
|
||||
*/
|
||||
public function refundShipping($order)
|
||||
{
|
||||
global $cookie;
|
||||
|
||||
$total_refunded = (float) Db::getInstance()->getValue('
|
||||
@ -709,16 +705,17 @@ class Paybox extends PaymentModule
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Génére un remboursement PAYBOX
|
||||
* @param float $montant Montant à rembourser
|
||||
* @param int $devise Numéro de la devise
|
||||
* @param int $num_transaction Numéro unique de transaction retourné par Paybox au paiement initial
|
||||
* @param int $reference Numéro de référence de la commande (id_cart)
|
||||
* @param int $num_appel Numéro d'appel retourné par Paybox au paiement initial
|
||||
**/
|
||||
public function sendRefundPaybox($montant, $devise, $num_transaction, $reference, $num_appel) {
|
||||
* Génére un remboursement PAYBOX
|
||||
* @param float $montant Montant à rembourser
|
||||
* @param int $devise Numéro de la devise
|
||||
* @param int $num_transaction Numéro unique de transaction retourné par Paybox au paiement initial
|
||||
* @param int $reference Numéro de référence de la commande (id_cart)
|
||||
* @param int $num_appel Numéro d'appel retourné par Paybox au paiement initial
|
||||
* @return boolean
|
||||
*/
|
||||
public function sendRefundPaybox($montant, $devise, $num_transaction, $reference, $num_appel)
|
||||
{
|
||||
$curl = curl_init('https://ppps.paybox.com/PPPS.php');
|
||||
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
@ -763,8 +760,7 @@ class Paybox extends PaymentModule
|
||||
$code_reponse = explode('CODEREPONSE=', $data[6]);
|
||||
|
||||
// refund success
|
||||
if ( $code_reponse[1] == "00000"
|
||||
|| $code_reponse[0] == "00000") {
|
||||
if ( $code_reponse[1] == "00000" || $code_reponse[0] == "00000") {
|
||||
return true;
|
||||
} else {
|
||||
// mail('thibault@antadis.com', 'Soucis remboursement reponse globale', json_encode($response));
|
||||
@ -774,15 +770,15 @@ class Paybox extends PaymentModule
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save refund transaction in BDD when its OK
|
||||
* @param int $id_order
|
||||
* @param int $id_order_detail
|
||||
* @param int $montant
|
||||
* @param int $id_employee
|
||||
**/
|
||||
protected function refundSave($id_order, $id_order_detail = 0, $montant, $id_employee) {
|
||||
* Save refund transaction in BDD when its OK
|
||||
* @param int $id_order
|
||||
* @param int $id_order_detail
|
||||
* @param int $montant
|
||||
* @param int $id_employee
|
||||
*/
|
||||
protected function refundSave($id_order, $id_order_detail = 0, $montant, $id_employee)
|
||||
{
|
||||
Db::getInstance()->execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'refund_transaction`
|
||||
(`id_order`, `id_order_detail`, `amount`, `date`, `id_employee`)
|
||||
@ -796,13 +792,13 @@ class Paybox extends PaymentModule
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load les informations d'une transaction paybox
|
||||
* @param int $id_cart Numéro du panier à charger
|
||||
* @return array Les informations de transaction
|
||||
**/
|
||||
public function loadTransaction($id_cart) {
|
||||
* Load les informations d'une transaction paybox
|
||||
* @param int $id_cart Numéro du panier à charger
|
||||
* @return array Les informations de transaction
|
||||
*/
|
||||
public function loadTransaction($id_cart)
|
||||
{
|
||||
return Db::getInstance()->getRow('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'paybox_transaction`
|
||||
@ -810,13 +806,13 @@ class Paybox extends PaymentModule
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Recupere la liste des remboursements effectués sur un id cmomande
|
||||
* @param int $order_id id de la commande
|
||||
* @return array
|
||||
**/
|
||||
public static function getAllRefundbyOrder($order_id) {
|
||||
* Recupere la liste des remboursements effectués sur un id cmomande
|
||||
* @param int $order_id id de la commande
|
||||
* @return array
|
||||
*/
|
||||
public static function getAllRefundbyOrder($order_id)
|
||||
{
|
||||
return Db::getInstance()->executeS('
|
||||
SELECT e.`email`, r.`date`, r.`amount`, r.`id_order_detail`, d.`product_name`
|
||||
FROM `'._DB_PREFIX_.'refund_transaction` r
|
||||
|
Loading…
Reference in New Issue
Block a user