public static function ManageUrlSys() { $payment = new Kwixo(); if (!$payment->isInstalled('kwixo')) { KwixoLogger::insertLogKwixo(__METHOD__ . ' : ' . __LINE__, 'Module Kwixo non installé, retour UrlSys échoué'); return false; } $transactionID = Tools::getValue('TransactionID'); $refID = Tools::getValue('RefID'); $tag = Tools::getValue('Tag'); $id_cart = Tools::getValue('custom', false); $amount = Tools::getValue('amount', false); $cart = new Cart((int) $id_cart); //Multishop if (_PS_VERSION_ < '1.5') { $kwixo = new KwixoPayment(); } else { $kwixo = new KwixoPayment($cart->id_shop); } if ($kwixo->getAuthKey() == '') { KwixoLogger::insertLogKwixo(__METHOD__ . ' : ' . __LINE__, 'Clé privée Kwixo vide, retour UrlSys échoué'); return false; } $md5 = new KwixoMD5(); $waitedhash = $md5->hash($kwixo->getAuthKey() . $refID . $transactionID); $receivedhash = Tools::getValue('HashControl', '0'); //Hash control if ($waitedhash != $receivedhash) { KwixoLogger::insertLogKwixo(__METHOD__ . ' : ' . __LINE__, 'URLSys erreur : HashControl invalide (valeur attendue = "' . $waitedhash . '", valeur reçue = "' . $receivedhash . '"). IP expediteur : ' . Tools::getRemoteAddr()); } else { //if cart if empty : error and exit if (!$cart->id) { KwixoLogger::insertLogKwixo(__METHOD__ . ' : ' . __LINE__, "Le panier pour la commande {$refid}/{$transactionid} n'existe pas."); exit; } global $cookie; //Give order_id $id_order = Order::getOrderByCartId($cart->id); if ($id_order !== false) { $order = new Order((int) $id_order); KwixoLogger::insertLogKwixo(__METHOD__ . ' : ' . __LINE__, 'URLSys : id_cart = ' . $id_cart . (!Order::getOrderByCartId($id_cart) ? '' : ' | id_order = ' . Order::getOrderByCartId($id_cart)) . ' | tag = ' . $tag); } else { KwixoLogger::insertLogKwixo(__METHOD__ . ' : ' . __LINE__, 'URLSys : order false'); } switch ($tag) { //Give up payment, tag sent after 1 hour case 0: KwixoLogger::insertLogKwixo(__METHOD__ . ' : ' . __LINE__, 'URLSys abandon après 1h : id_cart = ' . $id_cart . (!Order::getOrderByCartId($id_cart) ? '' : ' | id_order = ' . Order::getOrderByCartId($id_cart)) . ' | tag = ' . $tag); break; //Accepted payment //Accepted payment case 1: case 13: case 14: case 10: //Retrieve score if present $score = Tools::getValue('Score', false); //if order current state in cancelled or waiting or under control or credit status, status updated if ($id_order === false || in_array($order->getCurrentState(), array((int) _PS_OS_CANCELED_, (int) Configuration::get('KW_OS_WAITING'), (int) Configuration::get('KW_OS_CREDIT'), (int) Configuration::get('KW_OS_CONTROL')))) { if ($score == 'positif') { $psosstatus = (int) Configuration::get('KW_OS_PAYMENT_GREEN'); } elseif ($score == 'negatif') { $psosstatus = (int) Configuration::get('KW_OS_PAYMENT_RED'); } else { $psosstatus = (int) _PS_OS_PAYMENT_; } } break; //Payment refused //Payment refused case 2: if (!in_array($order->getCurrentState(), array((int) Configuration::get('KW_OS_PAYMENT_GREEN'), (int) Configuration::get('KW_OS_PAYMENT_RED'), (int) Configuration::get('KW_OS_CONTROL'), (int) Configuration::get('KW_OS_CREDIT')))) { $psosstatus = (int) _PS_OS_CANCELED_; } break; //order under control //order under control case 3: //if order current state in cancelled or waiting or credit status, status updated if ($id_order === false || in_array($order->getCurrentState(), array((int) _PS_OS_CANCELED_, (int) Configuration::get('KW_OS_WAITING'), (int) Configuration::get('KW_OS_CREDIT')))) { $psosstatus = (int) Configuration::get('KW_OS_CONTROL'); } break; //order on waiting status //order on waiting status case 4: if ($id_order === false) { $psosstatus = (int) Configuration::get('KW_OS_WAITING'); } break; //order under credit status //order under credit status case 6: //if order current state in cancelled or waiting, status updated if ($id_order === false || in_array($order->getCurrentState(), array((int) _PS_OS_CANCELED_, (int) Configuration::get('KW_OS_WAITING')))) { $psosstatus = (int) Configuration::get('KW_OS_CREDIT'); } break; //payment refused //payment refused case 11: case 12: //if order current state in cancelled or waiting, status updated if ($id_order === false || in_array($order->getCurrentState(), array((int) _PS_OS_CANCELED_, (int) Configuration::get('KW_OS_WAITING'), (int) Configuration::get('KW_OS_CREDIT'), (int) Configuration::get('KW_OS_CONTROL')))) { $psosstatus = (int) _PS_OS_CANCELED_; } break; //payment cancelled //payment cancelled case 101: $psosstatus = (int) _PS_OS_CANCELED_; break; //delivery done //delivery done case 100: if ($id_order === false || !in_array($order->getCurrentState(), array((int) _PS_OS_DELIVERED_, (int) _PS_OS_PREPARATION_, (int) _PS_OS_SHIPPING_, (int) _PS_OS_PAYMENT_))) { $psosstatus = (int) _PS_OS_PAYMENT_; } break; default: break; KwixoLogger::insertLogKwixo(__METHOD__ . ' : ' . __LINE__, 'Appel URLSys : id_cart = ' . $id_cart . (!Order::getOrderByCartId($id_cart) ? '' : ' | id_order = ' . Order::getOrderByCartId($id_cart)) . ' | tag = ' . $tag); } } //Validate order and update status if (isset($psosstatus)) { if ($id_order === false) { $feedback = 'Order Create'; $payment->validateOrder((int) $cart->id, $psosstatus, $amount, $payment->displayName, $feedback, NULL, $cart->id_currency); $id_order = Order::getOrderByCartId($cart->id); $payment->manageKwixoOrder($id_order, $tag, $transactionID, $id_cart, 'urlsys'); if ($cookie->id_cart == (int) $cookie->last_id_cart) { unset($cookie->id_cart); } } else { //update order history $order->setCurrentState($psosstatus); } } }
/** * Check if xml parameters given on payment validation are right * * @return xml_params given on payment validation */ public function checkUrlCallXMLParams() { $errors = array(); $xml_params = array(); if (!Tools::getValue('custom')) { $errors[] = $payment->displayName . ' ' . $payment->l('key "custom" not specified, cannot rely to cart') . "\n"; KwixoLogger::insertLogKwixo(__METHOD__ . " : " . __LINE__, 'clé custom non spécifiée dans xmlparams'); return false; } else { $xml_params['id_cart'] = (int) Tools::getValue('custom'); } if (!Tools::getValue('id_module')) { $errors[] = $payment->displayName . ' ' . $payment->l('key "module" not specified, cannot rely to payment module') . "\n"; KwixoLogger::insertLogKwixo(__METHOD__ . " : " . __LINE__, 'clé module non spécifiée dans xmlparams'); return false; } else { $xml_params['id_module'] = (int) Tools::getValue('id_module'); } if (!isset($_POST['amount'])) { $errors[] = $payment->displayName . ' ' . $payment->l('"amount" not specified, cannot control the amount paid') . "\n"; KwixoLogger::insertLogKwixo(__METHOD__ . " : " . __LINE__, 'clé montant non spécifiée dans xmlparams'); return false; } else { $xml_params['amount'] = (double) Tools::getValue('amount'); } //payed cart instanciation $cart = new Cart((int) $xml_params['id_cart']); $order_created = Order::getOrderByCartId($xml_params['id_cart']); //if not founded cart if (!$cart->id) { $errors[] = $payment->l('cart not found') . "\n"; KwixoLogger::insertLogKwixo(__METHOD__ . " : " . __LINE__, 'Panier non trouvé'); return false; } if (empty($errors)) { $xml_params['errors'] = 0; $xml_params['order_created'] = $order_created; KwixoLogger::insertLogKwixo(__METHOD__ . " : " . __LINE__, 'Récupération xml_params réussie'); return $xml_params; } else { $xml_params['errors'] = count($errors); return $xml_params; } }
{ return isTypeKwixo('KwixoFormField', $input); } /** * retour vrai si l'objet en paramètre est un objet Form, faux sinon
/** * * return Kwixo delivery by product_category, carrier id and defaut delivery * @param array $products_deliveries, int $carrier_id * @return int */ public function getKwixoDelivery($products_deliveries, $carrier_id) { $max_product_delivery = max($products_deliveries); if ($max_product_delivery != '') { KwixoLogger::insertLogKwixo(__METHOD__ . " : " . __LINE__, 'Délai de livraison par catégorie : ' . $max_product_delivery); return $max_product_delivery; } elseif (Configuration::get('KWIXO_CARRIER_DELIVERY_' . $carrier_id) != '') { KwixoLogger::insertLogKwixo(__METHOD__ . " : " . __LINE__, 'Délai de livraison par transporteur : ' . Configuration::get('KWIXO_CARRIER_DELIVERY_' . $carrier_id)); return Configuration::get('KWIXO_CARRIER_DELIVERY_' . $carrier_id); } else { KwixoLogger::insertLogKwixo(__METHOD__ . " : " . __LINE__, 'Délai de livraison par défaut : ' . Configuration::get('KWIXO_DELIVERY')); return Configuration::get('KWIXO_DELIVERY'); } }
public static function ManageUrlCall() { $payment = new Kwixo(); if (!$payment->isInstalled('kwixo')) { KwixoLogger::insertLogKwixo(__METHOD__ . ' : ' . __LINE__, 'Module Kwixo non installé, retour UrlCall échoué'); return false; } global $cart, $cookie; $errors = array(); $payment_ok = false; $params = array(); $TransactionID = Tools::getValue('TransactionID'); $RefID = Tools::getValue('RefID'); //Multishop if (_PS_VERSION_ < '1.5') { $kwixo = new KwixoPayment(); } else { $kwixo = new KwixoPayment($cart->id_shop); } if ($kwixo->getAuthKey() == '') { KwixoLogger::insertLogKwixo(__METHOD__ . ' : ' . __LINE__, 'Clé privée Kwixo vide, retour UrlCall échoué'); return false; } $md5 = new KwixoMD5(); $waitedhash = $md5->hash($kwixo->getAuthKey() . $RefID . $TransactionID); $receivedhash = Tools::getValue('HashControl', '0'); $id_order = false; //Hash control if ($waitedhash != $receivedhash) { KwixoLogger::insertLogKwixo(__METHOD__ . " : " . __LINE__, "Hash control invalide (les données ne proviennent pas de Kwixo)"); } else { //check xml_params for urlcall payment $xml_params = $payment->checkUrlCallXMLParams(); if ($xml_params['errors'] == 0) { $tag = Tools::getValue('Tag', false); $id_cart = $xml_params['id_cart']; $amount = $xml_params['amount']; $id_module = $xml_params['id_module']; $order_created = $xml_params['order_created']; switch ($tag) { //Give up payment or payment refused by bank -> back to cart without order creation case '0': KwixoLogger::insertLogKwixo(__METHOD__ . ' : ' . __LINE__, 'URLCall abandon paiement : id_cart = ' . $id_cart . (!$order_created ? '' : ' / id_order = ' . Order::getOrderByCartId($id_cart)) . ' / tag = ' . $tag); $payment_ok = false; break; case '2': $errors[] = $payment->l('Your payment has been refused.'); KwixoLogger::insertLogKwixo(__METHOD__ . ' : ' . __LINE__, 'URLCall : id_cart = ' . $id_cart . (!$order_created ? '' : ' / id_order = ' . Order::getOrderByCartId($id_cart)) . ' / tag = ' . $tag); $payment_ok = false; break; //Payment accepted -> order creation with waiting payment status and back to confirmation page //Payment accepted -> order creation with waiting payment status and back to confirmation page case '1': $feedback = $payment->l('Transaction OK:') . ' RefID=' . $RefID . ' & TransactionID=' . $TransactionID; //order validation if ($order_created == false) { $payment->validateOrder((int) $cart->id, (int) Configuration::get('KW_OS_WAITING'), $amount, $payment->displayName, $feedback, '', $cart->id_currency, false, $cart->secure_key); } $payment_ok = true; //get id_order to update database $id_order = Order::getOrderByCartId($id_cart); KwixoLogger::insertLogKwixo(__METHOD__ . ' : ' . __LINE__, 'Paiement accepté : $order->id = ' . $id_order); //Insert in kwixo order with urlcall method $payment->manageKwixoOrder($id_order, '', $TransactionID, $id_cart, 'urlcall'); //cart clean if ($cookie->id_cart == (int) $cookie->last_id_cart) { unset($cookie->id_cart); } $customer = new Customer((int) $cart->id_customer); break; //for unknowned tag //for unknowned tag default: //error saved $errors[] = $payment->l('One or more error occured during the validation') . "\n"; KwixoLogger::insertLogKwixo(__METHOD__ . ' : ' . __LINE__, 'Tag inconnu "' . $tag . '" recu.'); //cart clean if ($cookie->id_cart == (int) $cookie->last_id_cart) { unset($cookie->id_cart); } $payment_ok = false; break; } } else { //error saved $errors[] = $payment->l('One or more error occured during the validation') . "\n"; if ($cookie->id_cart == (int) $cookie->last_id_cart) { unset($cookie->id_cart); } } $params['payment_status'] = $payment_ok; $params['errors'] = $errors; $params['id_order'] = $id_order; return $params; } }
public static function generateForm() { global $cart, $cookie; $customer = new Customer((int) $cart->id_customer); $module = new Kwixo(); //For multishop if (_PS_VERSION_ < '1.5') { $kwixo = new KwixoPayment(); $customer_gender = $customer->id_gender; $male_gender = 1; $carrier_id = $cart->id_carrier; } else { $kwixo = new KwixoPayment($cart->id_shop); $gender = new Gender($customer->id_gender); $customer_gender = $gender->type; $male_gender = 0; //retrieve carrier_id in delivery string option, fix for PS 1.5 with onepagecheckout foreach ($cart->getDeliveryOption() as $delivery_string) { $carrier_id = substr($delivery_string, 0, -1); } } $mobile_detect = new MobileDetect(); $mobile = $mobile_detect->isMobile(); $control = new FianetKwixoControl(); $products = $cart->getProducts(); $invoice_address = new Address((int) $cart->id_address_invoice); $delivery_address = new Address((int) $cart->id_address_delivery); $carrier = new Carrier((int) $carrier_id); $currency = new Currency((int) $cart->id_currency); $invoice_country = new Country((int) $invoice_address->id_country); $delivery_country = new Country((int) $delivery_address->id_country); $invoice_company = $invoice_address->company == '' ? null : $invoice_address->company; $delivery_company = $delivery_address->company == '' ? null : $delivery_address->company; //Address and customer invoice $control->createInvoiceCustomer($customer_gender == $male_gender ? 'Monsieur' : 'Madame', $invoice_address->lastname, $invoice_address->firstname, $customer->email, $invoice_company, $invoice_address->phone_mobile, $invoice_address->phone); $control->createInvoiceAddress($invoice_address->address1, $invoice_address->postcode, $invoice_address->city, $invoice_country->iso_code, $invoice_address->address2); //gets the carrier kwixo type if (_PS_VERSION_ >= '1.5' && Shop::isFeatureActive()) { $carrier_type = Configuration::get('KWIXO_CARRIER_TYPE_' . (string) $carrier->id, null, null, $cart->id_shop); $carrier_speed = Configuration::get('KWIXO_CARRIER_SPEED_' . (string) $carrier->id, null, null, $cart->id_shop); } else { $carrier_type = Configuration::get('KWIXO_CARRIER_TYPE_' . (string) $carrier->id); $carrier_speed = Configuration::get('KWIXO_CARRIER_SPEED_' . (string) $carrier->id); } //if carrier type is empty, we take defaut carrier type if ($carrier_type == '0' || $carrier_type == '' || $carrier_type == false) { $carrier_type = Configuration::get('KWIXO_DEFAULT_CARRIER_TYPE'); $carrier_speed = Configuration::get('KWIXO_DEFAULT_CARRIER_SPEED'); $carrier_name = 'Transporteur'; } else { $carrier_name = $carrier->name; } switch ($carrier_type) { //if the order is to be delivered at home: element <utilisateur type="livraison"...> has to be added case '4': $control->createDeliveryCustomer($customer_gender == $male_gender ? 'Monsieur' : 'Madame', $delivery_address->lastname, $delivery_address->firstname, $customer->email, $delivery_company, $delivery_address->phone_mobile, $delivery_address->phone); $control->createDeliveryAddress($delivery_address->address1, $delivery_address->postcode, $delivery_address->city, $delivery_country->iso_code, $delivery_address->address2); //xml <infocommande> $order_details = $control->createOrderDetails($cart->id, $kwixo->getSiteid(), (string) $cart->getOrderTotal(true), $currency->iso_code, $_SERVER['REMOTE_ADDR'], date('Y-m-d H:i:s')); $kwixo_carrier = $order_details->createCarrier($carrier_name, $carrier_type, $carrier_speed); break; case '5': $order_details = $control->createOrderDetails($cart->id, $kwixo->getSiteid(), (string) $cart->getOrderTotal(true), $currency->iso_code, $_SERVER['REMOTE_ADDR'], date('Y-m-d H:i:s')); $kwixo_carrier = $order_details->createCarrier($carrier_name, $carrier_type, $carrier_speed); break; case '6': $order_details = $control->createOrderDetails($cart->id, $kwixo->getSiteid(), (string) $cart->getOrderTotal(true), $currency->iso_code, $_SERVER['REMOTE_ADDR'], date('Y-m-d H:i:s')); $socolissimoinfo = $module->getSoColissimoInfo($cart->id); $socolissimo_installed_module = Module::getInstanceByName('socolissimo'); if ($socolissimoinfo != false) { foreach ($socolissimoinfo as $info) { //get socolissimo informations $delivery_mode = $info['delivery_mode']; $firstname = $info['prfirstname']; $name = $info['prname']; $mobile_phone = $info['cephonenumber']; $company_name = $info['cecompanyname']; $email = $info['ceemail']; $address1 = $info['pradress1']; $address2 = $info['pradress2']; $address3 = $info['pradress3']; $address4 = $info['pradress4']; $zipcode = $info['przipcode']; $city = $info['prtown']; //data is retrieved differently and depending on the version of the module if ($socolissimo_installed_module->version < '2.8') { $address2 = $address1; $address1 = $name; $country = 'FR'; KwixoLogger::insertLogKwixo(__METHOD__ . " : " . __LINE__, "Module So Colissimo " . $socolissimo_installed_module->version . " détecté"); } else { $country = $info['cecountry']; } } //if delivery mode is DOM or RDV, <adresse type="livraison" ...> and <utilisateur type="livraison" ...> added if ($delivery_mode == 'DOM' || $delivery_mode == 'RDV') { $control->createDeliveryCustomer($customer_gender == $male_gender ? 'Monsieur' : 'Madame', $name, $firstname, $email, $company_name, $mobile_phone, null); $control->createDeliveryAddress($address3, $zipcode, $city, $country, $address4); $kwixo_carrier = $order_details->createCarrier($carrier_name, '4', $carrier_speed); } else { //<pointrelais> added if delivery mode is not BPR, A2P or CIT $kwixo_carrier = $order_details->createCarrier($carrier_name, '2', $carrier_speed); $drop_off_point = $kwixo_carrier->createDropOffPoint($address1, null); $drop_off_point->createAddress($address2, $zipcode, $city, $country, null); } } else { KwixoLogger::insertLogKwixo(__METHOD__ . " : " . __LINE__, "Flux incorrect : Module SoColissimo non installé ou non activé"); } break; default: $order_details = $control->createOrderDetails($cart->id, $kwixo->getSiteid(), (string) $cart->getOrderTotal(true), $currency->iso_code, $_SERVER['REMOTE_ADDR'], date('Y-m-d H:i:s')); $kwixo_carrier = $order_details->createCarrier($carrier_name, $carrier_type, $carrier_speed); if ($carrier_type == 1) { if ($module->checkShopAddress() == true) { //xml <pointrelais> $drop_off_point = $kwixo_carrier->createDropOffPoint(Configuration::get('PS_SHOP_NAME'), Configuration::get('PS_SHOP_NAME')); $drop_off_point->createAddress(Configuration::get('PS_SHOP_ADDR1'), Configuration::get('PS_SHOP_CODE'), Configuration::get('PS_SHOP_CITY'), Configuration::get('PS_SHOP_COUNTRY'), Configuration::get('PS_SHOP_ADDR2')); } else { //xml <pointrelais> $drop_off_point = $kwixo_carrier->createDropOffPoint($carrier_name, $carrier_name); $drop_off_point->createAddress($delivery_address->address1, $delivery_address->postcode, $delivery_address->city, $invoice_country->iso_code, $delivery_address->address2); } } else { //xml <pointrelais> $drop_off_point = $kwixo_carrier->createDropOffPoint($carrier_name, $carrier_name); $drop_off_point->createAddress($delivery_address->address1, $delivery_address->postcode, $delivery_address->city, $invoice_country->iso_code, $delivery_address->address2); } break; } //xml <list> $product_list = $order_details->createProductList(); $product_deliveries = array(); foreach ($products as $product) { $kwixo_categorie_id = Configuration::get('KWIXO_PRODUCT_TYPE_' . (int) $product['id_category_default']) == 0 ? Configuration::get('KWIXO_DEFAULT_PRODUCT_TYPE') : Configuration::get('KWIXO_PRODUCT_TYPE_' . (int) $product['id_category_default']); $product_reference = (isset($product['reference']) and !empty($product['reference'])) ? $product['reference'] : ((isset($product['ean13']) and !empty($product['ean13'])) ? $product['ean13'] : $product['name']); $product_list->createProduct($product['name'], str_replace("'", "", $product_reference), $kwixo_categorie_id, $product['price'], $product['cart_quantity']); $product_deliveries[] = Configuration::get('KWIXO_PRODUCT_TYPE_DELIVERY_' . (int) $product['id_category_default']); } $kwixo_delivery = $module->getKwixoDelivery($product_deliveries, $carrier->id); //xml <wallet> $date_order = date('Y-m-d H:i:s'); $wallet = $control->createWallet($date_order, $kwixo->generateDatelivr($date_order, $kwixo_delivery)); $wallet->addCrypt($kwixo->generateCrypt($control), '2.0'); //kwixo payment options //standard kwixo if (Tools::getValue('payment') == '1') { $control->createPaymentOptions('comptant', 0); } //comptant kwixo if (Tools::getValue('payment') == '2') { $control->createPaymentOptions('comptant', 1); } //credit kwixo if (Tools::getValue('payment') == '3') { $control->createPaymentOptions('credit'); } //facturable kwixo if (Tools::getValue('payment') == '4') { $control->createPaymentOptions('comptant', 1, 0); } $xml_params = new KwixoXMLParams(); $xml_params->addParam('custom', $cart->id); $xml_params->addParam('amount', $cart->getOrderTotal(true)); $xml_params->addParam('secure_key', $customer->secure_key); $xml_params->addParam('id_module', $module->name); //urlcall and urlsys link on PS 1.4 and PS 1.5 if (_PS_VERSION_ < '1.5') { $token = Tools::getAdminToken($kwixo->getSiteid() . $kwixo->getAuthkey()); $link_urlcall = 'http://' . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__ . 'modules/kwixo/payment_return.php?token=' . $token; $link_urlsys = 'http://' . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__ . 'modules/kwixo/push.php?token=' . $token; //returns kwixo form with auto submit return $kwixo->getTransactionForm($control, $xml_params, $link_urlsys, $link_urlcall, $mobile, KwixoForm::SUBMIT_AUTO, null); } else { $link_urlcall = Context::getContext()->link->getModuleLink('kwixo', 'urlcall'); $link_urlsys = Context::getContext()->link->getModuleLink('kwixo', 'urlsys'); //returns kwixo form with standard submit return $kwixo->getTransactionForm($control, $xml_params, $link_urlsys, $link_urlcall, $mobile, KwixoForm::SUBMIT_IMAGE, __PS_BASE_URI__ . 'modules/kwixo/img/logo_kwixo.png'); } }