✏️ 正在编辑: confirmation.php
路径:
/home/bpioifn/www/pigmentse/modules/axepta/controllers/front/confirmation.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php /** * 2007-2019 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-2019 PrestaShop SA * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ require_once _PS_MODULE_DIR_ . 'axepta/classes/AxeptaCustomerOneClickPaymentCard.php'; require_once _PS_MODULE_DIR_ . 'axepta/classes/AxeptaCustomerRecurringPaymentCard.php'; require_once _PS_MODULE_DIR_ . 'axepta/classes/AxeptaOrderReference.php'; require_once _PS_MODULE_DIR_ . 'axepta/classes/AxeptaBlowfish.php'; require_once _PS_MODULE_DIR_ . 'axepta/classes/AxeptaApi.php'; require_once _PS_MODULE_DIR_ . 'axepta/axepta.php'; require_once(_PS_CONFIG_DIR_ . '/config.inc.php'); require_once _PS_MODULE_DIR_ . 'axepta/classes/AxeptaLogger.php'; class AxeptaConfirmationModuleFrontController extends ModuleFrontController { public $ssl = true; public function initContent() { $this->display_column_left = false; $this->display_column_right = false; parent::initContent(); } public function postProcess() { // If the module is not active anymore, no need to process anything. if ($this->module->active == false) { die; } try { $context = Context::getContext(); $use_iframe = false; $error_tpl = 'error.tpl'; $id_merchant = Tools::getValue("id_merchant"); if (!$id_merchant && Tools::getValue('mid')) { $id_merchant = AxeptaConfigurationAccount::getIdByMid(Tools::getValue('mid')); } if (!$id_merchant) { $id_country = AxeptaApi::getLastCountryOrderForCustomer($context->customer->id); $id_merchant = AxeptaApi::getIdAccountByIdCountryAndIdCurrencyVerifyAllExist($id_country, $this->context->currency->id); } $merchant = new AxeptaConfigurationAccount($id_merchant); if (!$merchant) { throw new Exception('Merchant not found'); } $transaction_type = Tools::getValue('operation'); if (!$transaction_type) { $transaction_type = Tools::getValue('payment_mode'); } if ($merchant->mode_view == AxeptaConfigurationAccount::MODE_VIEW_IFRAME && $transaction_type != 'oneclick') { $use_iframe = true; $error_tpl = 'error-iframe.tpl'; } $data = Tools::getValue("Data"); $len = Tools::getValue("Len"); $plaintext = AxeptaApi::ctDecrypt($data, $len, $merchant->password); $a = explode('&', $plaintext); $data = AxeptaApi::ctSplit($a); $trigram = Tools::getValue('trigram'); $data['trigram'] = $trigram; if ($merchant->logs) { $message = 'PASSAGE DANS confirmation.php fonction =>'; $message .= 'Les paramètres recus seront les suivants =>'; $message .= ' Params: '; if (is_array($data)) { foreach ($data as $key => $row_params) { if (is_array($row_params)) { foreach ($row_params as $key_row => $row_param) { $message .= ' | '.$key_row .' => '.$row_param; } } else { $message .= ' | '.$key .' => '.$row_params; } } } AxeptaLogger::log($message, AxeptaLogger::LOG_DEBUG, AxeptaLogger::FILE_DEBUG); } // check HMAC if (!AxeptaApi::apiResponseVerifyHmac($data, $merchant)) { AxeptaLogger::log('HMAC corrputed for transID : '.$data['TransID'], AxeptaLogger::LOG_DEBUG, AxeptaLogger::FILE_DEBUG); die('HMAC corrputed for transID : '.$data['TransID']); } // Test if Cart in context is not set if (!(int) $this->context->cart->id) { AxeptaLogger::log("Context vide. On récupère l'id_cart avec le TransID (référence commande)", AxeptaLogger::LOG_DEBUG, AxeptaLogger::FILE_DEBUG); $id_cart = AxeptaOrderReference::getIdCartByReference($data['TransID']); // Set Cart and Customer in Context $this->context->cart = new Cart($id_cart); $this->context->customer = new Customer($this->context->cart->id_customer); } // #36912 : Fix deconnexion after payment if (!$this->context->cookie->isLogged()) { AxeptaLogger::log('Cookie lost', AxeptaLogger::LOG_DEBUG, AxeptaLogger::FILE_DEBUG); $cookie = $context->cookie; $cookie->__set('id_customer', $this->context->customer->id); $cookie->__set('customer_lastname', $this->context->customer->lastname); $cookie->__set('customer_firstname', $this->context->customer->firstname); $cookie->__set('logged', 1); $cookie->__set('passwd', $this->context->customer->passwd); $cookie->__set('email', $this->context->customer->email); $cookie->__set('id_cart', $this->context->cart->id); if (version_compare(_PS_VERSION_, '1.7.6.6' ,'>=')) { AxeptaLogger::log('Register Session', AxeptaLogger::LOG_DEBUG, AxeptaLogger::FILE_DEBUG); $cookie->registerSession(new CustomerSession()); } $this->context->customer->logged = 1; $cookie->write(); } // Reprise panier switch (Tools::substr($data['Code'], -4)) { case '0053': case '0073': case '0723': case '0946': Tools::redirect('index.php?controller=cart&action=show&key=' . $this->context->customer->secure_key); break; } // #36722 : URLSuccess/Failure === URLNotify, Fix la double save if (!isset($data['XID']) || !Validate::isLoadedObject(($transaction = AxeptaTransaction::getTransactionByXid($data['XID'])))) { // Cast save_payment from url $save_payment = Tools::getValue('save_payment') === 'true' ? true : false; if ($save_payment && isset($data['card'])) { $card = AxeptaApi::decodeParamJson($data['card']); if (!AxeptaCustomerOneClickPaymentCard::verifyIfCardExist($context->customer->id, $card['number'])) { $oneclick_card = new AxeptaCustomerOneClickPaymentCard(); $oneclick_card->id_customer = $context->customer->id; $oneclick_card->pcnr = $card['number']; $oneclick_card->ccexpiry = $card['expiryDate']; $oneclick_card->ccbrand = $card['brand']; $oneclick_card->holder_name = $card['cardholderName']; $oneclick_card->save(); } } if (Tools::getValue('is_recurring')) { $transaction_type = AxeptaTransaction::RECURRING; } AxeptaLogger::log("Type de transaction : ".$transaction_type, AxeptaLogger::LOG_DEBUG, AxeptaLogger::FILE_DEBUG); switch ($transaction_type) { case 'payment': $this->createSimpleOrder($data, $transaction_type, $merchant); break; case 'recurring': $this->createRecurringOrder($data, $transaction_type, $merchant); break; case 'oneclick': $this->createSimpleOrder($data, $transaction_type, $merchant); break; } } else { $transaction->merchant_id = $data['mid']; $raw_data = json_decode($transaction->raw_data); $transaction->raw_data = json_encode((object) array_merge((array) $raw_data, $data)); $transaction->save(); } //endswitch; $link = new Link(); /** * If the order has been validated we try to retrieve it */ $id_order = Order::getOrderByCartId((int) $this->context->cart->id); $cart_id = $this->context->cart->id; $module_id = $this->module->id; $secure_key = $this->context->customer->secure_key; $order = new Order($id_order); if ($id_order && !$use_iframe) { AxeptaLogger::log('Redirect : ' . sprintf('[%d/%d/%d]', $cart_id, $module_id, $id_order), AxeptaLogger::LOG_DEBUG, AxeptaLogger::FILE_DEBUG); /** * The order has been placed so we redirect the customer on the confirmation page. */ $module_id = $this->module->id; Tools::redirect('index.php?controller=order-confirmation&id_cart=' . $cart_id . '&id_module=' . $module_id . '&id_order=' . $id_order . '&key=' . $secure_key); } elseif ($id_order && $use_iframe) { AxeptaLogger::log('Iframe', AxeptaLogger::LOG_DEBUG, AxeptaLogger::FILE_DEBUG); $params = array( 'id_cart' => (int) $this->context->cart->id, 'id_module' => (int) $this->module->id, 'id_order' => (int) $id_order, 'key' => $this->context->customer->secure_key, ); $url = $link->getPageLink('order-confirmation', true, (int) $this->context->customer->id_lang, $params, false, $order->id_shop); $this->context->smarty->assign(array( 'url' => $url, )); return $this->setTemplate('module:axepta/views/templates/front/validation-iframe.tpl'); } AxeptaLogger::log('Error no ID ORDER', AxeptaLogger::LOG_DEBUG, AxeptaLogger::FILE_DEBUG); } catch (Exception $e) { AxeptaLogger::log('Throw Exception : ' . $e->getMessage(), AxeptaLogger::LOG_DEBUG, AxeptaLogger::FILE_DEBUG); } /* * Default action : redirect error * An error occured and is shown on a new page. */ $this->context->smarty->assign(array( 'errors' => $this->l('An error occured. Please contact the merchant to have more informations') )); return $this->setTemplate('module:axepta/views/templates/front/' . $error_tpl); } /** * Create a simple order */ private function createSimpleOrder($data, $transaction_type, $merchant) { AxeptaLogger::log("Passage dans createSimpleOrder.", AxeptaLogger::LOG_DEBUG, AxeptaLogger::FILE_DEBUG); $id_order = AxeptaApi::getOrderByCartId((int) $this->context->cart->id, (int) $this->context->cart->id_shop); if (!(int)$id_order) { AxeptaLogger::log("Aucune commande existante --> création", AxeptaLogger::LOG_DEBUG, AxeptaLogger::FILE_DEBUG); } else { AxeptaLogger::log("Commande existante : ".$id_order, AxeptaLogger::LOG_DEBUG, AxeptaLogger::FILE_DEBUG); } $this->context->order = new Order((int) $id_order); $amount = $this->context->cart->getOrderTotal(); // If payment success and same amount $status = (int) _PS_OS_PAYMENT_; //Get amount command $computop_amount = ((int)str_replace('amount_', '', $data['UserData']))/100; if ($amount != $computop_amount) { AxeptaLogger::log("Montant commande différent de montant renvoyé (".$amount." vs. ".$computop_amount.")", AxeptaLogger::LOG_DEBUG, AxeptaLogger::FILE_DEBUG); $amount_ok = false; } else { AxeptaLogger::log("Montant commande égal au montant renvoyé", AxeptaLogger::LOG_DEBUG, AxeptaLogger::FILE_DEBUG); $amount_ok = true; } if ($data['Code'] != '00000000') { $status = (int) _PS_OS_ERROR_; } else if ($data['trigram'] == 'PRE') { // Cetelem Presto gestion if (Tools::strtoupper($data['Description']) == 'PENDING') { $status = (int) Configuration::getGlobalValue('AXEPTA_PENDING_OS_PAYMENT'); } } if ($data['Code'] == '00000000' && !$amount_ok) { $status = (int) Configuration::getGlobalValue('AXEPTA_INCOMPLETE_OS_PAYMENT'); } // Check if this is a timeout notification $timeout = false; switch (Tools::substr($data['Code'], -4)) { case '0051': case '0056': case '0368': case '0402': case '0931': case '2206': case '4005': case '9040': case '110A': AxeptaLogger::log("Il s'agit d'un timeout", AxeptaLogger::LOG_DEBUG, AxeptaLogger::FILE_DEBUG); $timeout = true; break; } $extra_vars = array( 'transaction_id' => $data['PayID'] ); if (!$this->context->cart->OrderExists()) { AxeptaLogger::log("Aucune commande existante (not OrderExists()) --> création", AxeptaLogger::LOG_DEBUG, AxeptaLogger::FILE_DEBUG); $this->module->validateOrder( (int) $this->context->cart->id, $status, (float) $computop_amount, (string) $this->module->displayName, null, $extra_vars, (int) $this->context->cart->id_currency, false, $this->context->customer->secure_key ); $id_order = AxeptaApi::getOrderByCartId((int) $this->context->cart->id, (int) $this->context->cart->id_shop); $this->context->order = new Order((int) $id_order); } else if (!$timeout) { $id_order = AxeptaApi::getOrderByCartId((int) $this->context->cart->id, (int) $this->context->cart->id_shop); AxeptaLogger::log("Commande déjà existante : ".$id_order, AxeptaLogger::LOG_DEBUG, AxeptaLogger::FILE_DEBUG); $this->context->order = new Order((int) $id_order); // Check current state. If current state is not accepted, we take the notif in account and change the statut if (!in_array($this->context->order->current_state, array(_PS_OS_PAYMENT_))) { AxeptaLogger::log("Statut de la commande déjà existante égal à _PS_OS_ERROR_ ou AXEPTA_PENDING_OS_PAYMENT (".$this->context->order->current_state."). On prend en compte la notification. ", AxeptaLogger::LOG_DEBUG, AxeptaLogger::FILE_DEBUG); $this->context->order->current_state = $status; $this->context->order->payment = $this->module->displayName; $this->context->order->save(); $history = new OrderHistory(); $history->id_order = (int) $this->context->order->id; $history->changeIdOrderState($status, (int) ($this->context->order->id)); $carrier = new Carrier($this->context->order->id_carrier, $this->context->order->id_lang); $templateVars = array(); if ($history->id_order_state == Configuration::get('PS_OS_SHIPPING') && $this->context->order->shipping_number) { $templateVars = array('{followup}' => str_replace('@', $this->context->order->shipping_number, $carrier->url)); } $history->addWithemail(true, $templateVars); } else { AxeptaLogger::log("Statut de la commande déjà existante différent de _PS_OS_ERROR_ ou AXEPTA_PENDING_OS_PAYMENT : ".$this->context->order->current_state.". On ne prend pas en compte la notification. ", AxeptaLogger::LOG_DEBUG, AxeptaLogger::FILE_DEBUG); } } else { AxeptaLogger::log("Commande déjà existante : ".$id_order." et notification de Timeout -> non prise en compte", AxeptaLogger::LOG_DEBUG, AxeptaLogger::FILE_DEBUG); } $this->registerTransaction($data, $transaction_type, $merchant); } /** * Create a recurring order */ private function createRecurringOrder($data, $transaction_type, $merchant) { AxeptaLogger::log("Passage dans createRecurringOrder.", AxeptaLogger::LOG_DEBUG, AxeptaLogger::FILE_DEBUG); $id_order = AxeptaApi::getOrderByCartId((int) $this->context->cart->id, (int) $this->context->cart->id_shop); if (!(int)$id_order) { AxeptaLogger::log("Aucune commande existante --> création", AxeptaLogger::LOG_DEBUG, AxeptaLogger::FILE_DEBUG); } else { AxeptaLogger::log("Commande existante : ".$id_order, AxeptaLogger::LOG_DEBUG, AxeptaLogger::FILE_DEBUG); } $this->context->order = new Order((int) $id_order); $amount = $this->context->cart->getOrderTotal(); // If payment success and same amount $status = (int) _PS_OS_PAYMENT_; //Get amount command $computop_amount = ((int)str_replace('amount_', '', $data['UserData']))/100; if ($amount != $computop_amount) { AxeptaLogger::log("Montant commande différent de montant renvoyé (".$amount." vs. ".$computop_amount.")", AxeptaLogger::LOG_DEBUG, AxeptaLogger::FILE_DEBUG); $amount_ok = false; } else { AxeptaLogger::log("Montant commande égal au montant renvoyé", AxeptaLogger::LOG_DEBUG, AxeptaLogger::FILE_DEBUG); $amount_ok = true; } if ($data['Code'] != '00000000') { $status = (int) _PS_OS_ERROR_; } if ($data['Code'] == '00000000' && !$amount_ok) { $status = (int) Configuration::getGlobalValue('AXEPTA_INCOMPLETE_OS_PAYMENT'); } // Check if this is a timeout notification $timeout = false; switch (Tools::substr($data['Code'], -4)) { case '0051': case '0056': case '0368': case '0402': case '0931': case '2206': case '4005': case '9040': case '110A': AxeptaLogger::log("Il s'agit d'un timeout", AxeptaLogger::LOG_DEBUG, AxeptaLogger::FILE_DEBUG); $timeout = true; break; } $extra_vars = array( 'transaction_id' => $data['PayID'] ); // If payment success and same amount if (!$this->context->cart->OrderExists()) { AxeptaLogger::log("Aucune commande existante --> création.", AxeptaLogger::LOG_DEBUG, AxeptaLogger::FILE_DEBUG); $this->module->validateOrder( (int) $this->context->cart->id, $status, (float) $computop_amount, (string) $this->module->displayName, null, $extra_vars, (int) $this->context->cart->id_currency, false, $this->context->customer->secure_key ); $id_order = AxeptaApi::getOrderByCartId((int) $this->context->cart->id, (int) $this->context->cart->id_shop); $this->context->order = new Order((int) $id_order); } else if (!$timeout) { $id_order = AxeptaApi::getOrderByCartId((int) $this->context->cart->id, (int) $this->context->cart->id_shop); AxeptaLogger::log("Commande déjà existante : ".$id_order, AxeptaLogger::LOG_DEBUG, AxeptaLogger::FILE_DEBUG); $this->context->order = new Order((int) $id_order); // Check current state. If current state is not accepted, we take the notif in account and change the statut if (!in_array($this->context->order->current_state, array(_PS_OS_PAYMENT_))) { AxeptaLogger::log("Statut de la commande déjà existante égal à _PS_OS_ERROR_ ou AXEPTA_PENDING_OS_PAYMENT (".$this->context->order->current_state."). On prend en compte la notification. ", AxeptaLogger::LOG_DEBUG, AxeptaLogger::FILE_DEBUG); $this->context->order->current_state = $status; $this->context->order->payment = $this->module->displayName; $this->context->order->save(); $history = new OrderHistory(); $history->id_order = (int) $this->context->order->id; $history->changeIdOrderState($status, (int) ($this->context->order->id)); $carrier = new Carrier($this->context->order->id_carrier, $this->context->order->id_lang); $templateVars = array(); if ($history->id_order_state == Configuration::get('PS_OS_SHIPPING') && $this->context->order->shipping_number) { $templateVars = array('{followup}' => str_replace('@', $this->context->order->shipping_number, $carrier->url)); } $history->addWithemail(true, $templateVars); } else { AxeptaLogger::log("Statut de la commande déjà existante différent de _PS_OS_ERROR_ ou AXEPTA_PENDING_OS_PAYMENT : ".$this->context->order->current_state.". On ne prend pas en compte la notification. ", AxeptaLogger::LOG_DEBUG, AxeptaLogger::FILE_DEBUG); } } else { AxeptaLogger::log("Commande déjà existante : ".$id_order." et notification de Timeout -> non prise en compte", AxeptaLogger::LOG_DEBUG, AxeptaLogger::FILE_DEBUG); } // TODO LOG // Register transaction $this->registerTransaction($data, $transaction_type, $merchant); if ($data['Code'] == '00000000') { $this->CreateRecurringSchedule($data); } } /** * Register the transaction */ protected function registerTransaction($data, $transaction_type = null, $merchant) { AxeptaLogger::log("Passage dans registerTransaction.", AxeptaLogger::LOG_DEBUG, AxeptaLogger::FILE_DEBUG); $context = Context::getContext(); if (empty($transaction_type)) { $transaction_type = AxeptaTransaction::PAYMENT; } $transaction = AxeptaTransaction::getTransactionByPayId($data['PayID']); if (!Validate::isLoadedObject($transaction)) { AxeptaLogger::log("Aucune transaction existante --> création.", AxeptaLogger::LOG_DEBUG, AxeptaLogger::FILE_DEBUG); $this->transaction = new AxeptaTransaction(); } else { AxeptaLogger::log("Transaction existante : ".json_encode($transaction), AxeptaLogger::LOG_DEBUG, AxeptaLogger::FILE_DEBUG); $this->transaction = $transaction; } //Recuperation montant de la commande $computop_amount = ((int)str_replace('amount_', '', $data['UserData']))/100; $this->transaction->id_axepta_configuration_account = $merchant->id; $this->transaction->merchant_id = $merchant->mid; $this->transaction->transaction_reference = AxeptaOrderReference::getReferenceByCartId($context->cart->id); $this->transaction->transaction_date = date('Y-m-d H:i:s'); $this->transaction->id_order = (int) $this->context->order->id; $this->transaction->pay_id = isset($data['PayID']) ? $data['PayID'] : ''; $this->transaction->xid = isset($data['XID']) ? $data['XID'] : ''; $this->transaction->amount = $computop_amount; $this->transaction->transaction_type = $transaction_type; $this->transaction->trigram = isset($data['trigram']) ? $data['trigram'] : ''; $this->transaction->payment_mean_brand = isset($data['CCBrand']) ? $data['CCBrand'] : 'N/A'; $this->transaction->payment_mean_type = isset($data['Type']) ? $data['Type'] : 'N/A'; $this->transaction->response_code = isset($data['Code']) ? $data['Code'] : ''; $this->transaction->pcnr = isset($data['PCNr']) ? $data['PCNr'] : ''; $this->transaction->bid = isset($data['billingagreementid']) ? $data['billingagreementid'] : ''; $this->transaction->ccexpiry = isset($data['CCExpiry']) ? $data['CCExpiry'] : ''; $this->transaction->status = isset($data['Status']) ? $data['Status'] : ''; $this->transaction->description = isset($data['Description']) ? $data['Description'] : ''; $this->transaction->scheme_reference_id = isset($data['schemeReferenceID']) ? $data['schemeReferenceID'] : ''; $message = ""; foreach ($data as $key => $value) { $message .= $key . ': ' . $value . "<br>"; } $this->transaction->raw_data = json_encode($data); $this->transaction->save(); } /** * Create Recurring Schedule */ protected function createRecurringSchedule($data) { $context = Context::getContext(); $card_exist = null; if (isset($data['card'])) { $card = AxeptaApi::decodeParamJson($data['card']); $card_exist = AxeptaCustomerRecurringPaymentCard::verifyIfCardExist($context->customer->id, $card['number']); } $recurring_card = new AxeptaCustomerRecurringPaymentCard(); if (isset($data['billingagreementid'])) { $recurring_card->id_customer = $context->customer->id; $recurring_card->id_axepta_customer_payment_recurring = null; $recurring_card->pcnr = null; $recurring_card->ccexpiry = null; $recurring_card->ccbrand = null; $recurring_card->bid = $data['billingagreementid']; } elseif (!isset($data['billingagreementid']) && !$card_exist) { $recurring_card->id_customer = $context->customer->id; $recurring_card->id_axepta_customer_payment_recurring = null; $recurring_card->pcnr = $card['number']; $recurring_card->ccexpiry = $card['expiryDate']; $recurring_card->ccbrand = $card['brand']; $recurring_card->holder_name = $card['cardholderName']; $recurring_card->bid = null; } else { $exist_recurring_card = new AxeptaCustomerRecurringPaymentCard($card_exist['id']); $recurring_card->id_customer = $exist_recurring_card->id_customer; $recurring_card->id_axepta_customer_payment_recurring = null; $recurring_card->pcnr = $exist_recurring_card->pcnr; $recurring_card->ccexpiry = $exist_recurring_card->ccexpiry; $recurring_card->ccbrand = $exist_recurring_card->ccbrand; $recurring_card->holder_name = $exist_recurring_card->holder_name; $recurring_card->bid = null; if (isset($exist_recurring_card->bid)) { $recurring_card->bid = $exist_recurring_card->bid; } } $context = Context::getContext(); $id_order = AxeptaApi::getOrderByCartId((int) $context->cart->id, (int) $context->cart->id_shop); $is_already_created = AxeptaCustomerPaymentRecurring::isScheduleAlreadyCreated((int) $this->context->order->id); if ($is_already_created == false) { foreach ($this->context->cart->getProducts() as $product_cart) { $product_payment_recurring = AxeptaPaymentRecurring::getPaymentRecurringByProductId((int) $product_cart['id_product']); // if payment is paused if (!empty($product_payment_recurring)) { if ($product_payment_recurring['type'] == 2) { $quantity = 0; $id_pause_payment = AxeptaCustomerPaymentRecurring::isPausedRecurringPayment( (int) $this->context->customer->id, (int) $product_cart['id_product'], (int) $this->context->cart->id ); $paused_recurring_payment = new AxeptaCustomerPaymentRecurring((int) $id_pause_payment); if ((int) $paused_recurring_payment->id) { $qty = 1; if ((int) $paused_recurring_payment->getLateRecurringOccurence()) { $qty = (int) $paused_recurring_payment->getLateRecurringOccurence(); } $paused_recurring_payment->current_occurence += (int) $qty; $paused_recurring_payment->id_cart_paused_currency = 0; $paused_recurring_payment->id_order = (int) $this->context->order->id; $paused_recurring_payment->id_axepta_transaction = (int) $this->transaction->id; $last_schedule = new DateTime(); if ($paused_recurring_payment->isAnticipatedPayment()) { $last_schedule = new DateTime($paused_recurring_payment->next_schedule); } $paused_recurring_payment->last_schedule = $last_schedule->format('Y-m-d H:i:s'); $next_schedule = $last_schedule->add(new DateInterval('P' . (int) $paused_recurring_payment->number_occurences . (string) $paused_recurring_payment->periodicity)); $paused_recurring_payment->next_schedule = $next_schedule->format('Y-m-d H:i:s'); $paused_recurring_payment->status = AxeptaCustomerPaymentRecurring::ID_STATUS_ACTIVE; $paused_recurring_payment->save(); $quantity++; } while ($quantity < $product_cart['cart_quantity']) { $customer_payment_recurring = new AxeptaCustomerPaymentRecurring(); $customer_payment_recurring->id_product = (int) $product_cart['id_product']; $customer_payment_recurring->id_order = (int) $this->context->order->id; $customer_payment_recurring->id_customer = (int) $this->context->customer->id; $customer_payment_recurring->id_axepta_transaction = (int) $this->transaction->id; $customer_payment_recurring->id_tax_rules_group = (int) Product::getIdTaxRulesGroupByIdProduct((int) $product_cart['id_product'], $this->context); $customer_payment_recurring->status = (int) AxeptaCustomerPaymentRecurring::getStatus((int) AxeptaCustomerPaymentRecurring::ID_STATUS_ACTIVE, true); $periodicities = AxeptaPaymentRecurring::getPeriodicities(); $customer_payment_recurring->periodicity = $periodicities[(int) $product_payment_recurring['periodicity']]['days']; $customer_payment_recurring->amount_tax_exclude = (float) $product_cart['price_with_reduction_without_tax']; if ((float) $product_payment_recurring['recurring_amount']) { $customer_payment_recurring->amount_tax_exclude = (float) $product_payment_recurring['recurring_amount']; } $customer_payment_recurring->number_occurences = (int) $product_payment_recurring['number_occurences']; $customer_payment_recurring->current_occurence = (int) 1; $date_schedule = new DateTime(); $customer_payment_recurring->date_add = $date_schedule->format('Y-m-d H:i:s'); $customer_payment_recurring->last_schedule = $date_schedule->format('Y-m-d H:i:s'); $next_schedule = $date_schedule->add(new DateInterval('P' . (int) $customer_payment_recurring->number_occurences . (string) $customer_payment_recurring->periodicity)); $customer_payment_recurring->next_schedule = $next_schedule->format('Y-m-d H:i:s'); if (empty($customer_payment_recurring->scheme_reference_id)) { $customer_payment_recurring->scheme_reference_id = isset($data['schemeReferenceID']) ? $data['schemeReferenceID'] : ''; } $customer_payment_recurring->add(); $quantity++; // Fix : Add one Recurring card for each product $id = AxeptaCustomerPaymentRecurring::getAxeptaIdCustomerPaymentRecurringbyIdOrderandIdCustomer((int) $id_order, (int) $context->customer->id); $recurring_card_for_recurring_payment = clone $recurring_card; $recurring_card_for_recurring_payment->id_axepta_customer_payment_recurring = $id; $recurring_card_for_recurring_payment->save(); } } } } } } /** * Update the recurring payment */ private function updateRecurringSchedule($data, $id_schedule) { $customer_payment_recurring = new AxeptaCustomerPaymentRecurring((int) $id_schedule); $this->deleteCurrentSpecificPrice($customer_payment_recurring->id); if ($data['Code'] == '00') { $qty = 1; if ((int) $customer_payment_recurring->getLateRecurringOccurence()) { $qty = (int) $customer_payment_recurring->getLateRecurringOccurence(); } $customer_payment_recurring->current_occurence += (int) $qty; $last_schedule = new DateTime(); if ($customer_payment_recurring->isAnticipatedPayment()) { $last_schedule = new DateTime($customer_payment_recurring->next_schedule); } $customer_payment_recurring->last_schedule = $last_schedule->format('Y-m-d H:i:s'); $next_schedule = $last_schedule->add(new DateInterval('P' . (int) $customer_payment_recurring->number_occurences . (string) $customer_payment_recurring->periodicity)); $customer_payment_recurring->next_schedule = $next_schedule->format('Y-m-d H:i:s'); $customer_payment_recurring->status = AxeptaCustomerPaymentRecurring::ID_STATUS_ACTIVE; $customer_payment_recurring->save(); } else { $customer_payment_recurring->status = AxeptaCustomerPaymentRecurring::ID_STATUS_PAUSE; $customer_payment_recurring->save(); // payment failed during first 12 months ? $current_date = new DateTime; $recurring_init_date = new DateTime($customer_payment_recurring->date_add); $date_interval = $recurring_init_date->diff($current_date); $total_months = 12 * $date_interval->y + $date_interval->m; if ((int) $total_months < 12) { $customer = new Customer($customer_payment_recurring->id_customer); $module = Module::getInstanceByName('axepta'); $data = array( '{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email, '{customer_id}' => $customer->id, '{order_id}' => $customer_payment_recurring->id_order, ); // send email Mail::Send( (int) Context::getContext()->language->id, 'axepta_recurring_admin_error', Translate::getModuleTranslation( $module, 'A customer has error in his reccuring payment', 'AxeptaConfirmation' ), $data, Configuration::get('PS_SHOP_EMAIL'), Configuration::get('PS_SHOP_EMAIL'), null, null, null, null, _PS_MODULE_DIR_ . '/axepta/mails/' ); } } // TODO LOG } private function deleteCurrentSpecificPrice($id_customer_payment_recurring) { if ((int) $id_customer_payment_recurring) { Db::getInstance()->execute(' DELETE FROM `' . _DB_PREFIX_ . 'specific_price` WHERE `id_specific_price` = ' . pSQL((int) $id_customer_payment_recurring)); } return false; } }
💾 保存文件
← 返回文件管理器