Пример #1
0
 private function cartEnabled()
 {
     if (!Validate::isLoadedObject($this->cart)) {
         $this->addError(sprintf($this->module->l('Cart not exists : %s'), $this->idCart), PowaTagErrorType::$INVALID_CARD);
         return false;
     }
     if ($this->cart->orderExists()) {
         $this->addError(sprintf($this->module->l('Cart has already associated with order : %s'), $this->idCart), PowaTagErrorType::$INTERNAL_ERROR);
         return false;
     }
     return true;
 }
Пример #2
0
 public function postProcess()
 {
     $cartId = Tools::getValue('id_cart', false);
     if (!$cartId) {
         Tools::redirect('index.php?controller=order-confirmation');
     }
     $cart = new Cart((int) $cartId);
     if (!$cart->orderExists()) {
         $this->module->validateOrder($cart->id, Configuration::get('PS_OS_CANCELED'), $cart->getOrderTotal(), $this->module->displayName, 'Order cancelled by Aplazame cancel_url', null, null, false, Tools::getValue('key', false));
     }
     $orderId = Order::getOrderByCartId($cart->id);
     Tools::redirect('index.php?controller=order-confirmation&id_cart=' . $cart->id . '&id_module=' . $this->module->id . '&id_order=' . $orderId . '&key=' . $cart->secure_key);
 }
 public function postProcess()
 {
     parent::postProcess();
     $dd = serialize($_REQUEST);
     $this->log_on = Configuration::get('YA_ORG_LOGGING_ON');
     if ($this->log_on) {
         $this->module->log_save('payment_kassa ' . $dd);
     }
     Tools::getValue('label') ? $data = explode('_', Tools::getValue('label')) : ($data = explode('_', Tools::getValue('customerNumber')));
     if (!empty($data) && $data[0] == 'KASSA') {
         $cart = new Cart($data[1]);
         if ($cart->id_customer == 0 || $cart->id_address_delivery == 0 || $cart->id_address_invoice == 0 || !$this->module->active) {
             Tools::redirect('index.php?controller=order&step=1');
         }
         $customer = new Customer($cart->id_customer);
         if (!Validate::isLoadedObject($customer)) {
             Tools::redirect('index.php?controller=order&step=1');
         }
         $total_to_pay = $cart->getOrderTotal(true);
         $rub_currency_id = Currency::getIdByIsoCode('RUB');
         if ($cart->id_currency != $rub_currency_id) {
             $from_currency = new Currency($cart->id_currency);
             $to_currency = new Currency($rub_currency_id);
             $total_to_pay = Tools::convertPriceFull($total_to_pay, $from_currency, $to_currency);
         }
         $total_to_pay = number_format($total_to_pay, 2, '.', '');
         $amount = Tools::getValue('orderSumAmount');
         $action = Tools::getValue('action');
         $shopId = Tools::getValue('shopId');
         $invoiceId = Tools::getValue('invoiceId');
         $signature = md5($action . ';' . $amount . ';' . Tools::getValue('orderSumCurrencyPaycash') . ';' . Tools::getValue('orderSumBankPaycash') . ';' . $shopId . ';' . $invoiceId . ';' . Tools::getValue('customerNumber') . ';' . trim(Configuration::get('YA_ORG_MD5_PASSWORD')));
         $ord = $cart->orderExists() ? new Order((int) Order::getOrderByCartId($cart->id)) : $this->module->validateOrder($cart->id, _PS_OS_PREPARATION_, $cart->getOrderTotal(true, Cart::BOTH), $this->module->displayName, NULL, array(), NULL, false, $cart->secure_key);
         if (!$ord) {
             $this->module->validateResponse($this->module->l('Invalid order number'), 1, $action, $shopId, $invoiceId, true);
         }
         if (Tools::strtoupper($signature) != Tools::strtoupper(Tools::getValue('md5'))) {
             $this->module->validateResponse($this->module->l('Invalid signature'), 1, $action, $shopId, $invoiceId, true);
         }
         if ($amount != $total_to_pay) {
             $this->module->validateResponse($this->module->l('Incorrect payment amount'), $action == 'checkOrder' ? 100 : 200, $action, $shopId, $invoiceId, true);
         }
         if ($action == 'checkOrder') {
             if ($this->log_on) {
                 $this->module->log_save('payment_kassa: checkOrder invoiceId="' . $invoiceId . '" shopId="' . $shopId . '" ' . $this->module->l('check order'));
             }
             $this->module->validateResponse('', 0, $action, $shopId, $invoiceId, true);
         }
         if ($action == 'paymentAviso') {
             $history = new OrderHistory();
             $history->id_order = $ord->id;
             $history->changeIdOrderState(Configuration::get('PS_OS_PAYMENT'), $ord->id);
             $history->addWithemail(true);
             if ($this->log_on) {
                 $this->module->log_save('payment_kassa: paymentAviso invoiceId="' . $invoiceId . '" shopId="' . $shopId . '" #' . $ord->id . ' ' . $this->module->l('Order success'));
             }
             $this->module->validateResponse('', 0, $action, $shopId, $invoiceId, true);
         }
     } else {
         Tools::redirect('index.php?controller=order&step=3');
     }
 }
Пример #4
0
 public function processNotification($http_raw_post_data)
 {
     // First we convert the raw post data to something that we can read
     $http_post_object = Tools::jsonDecode($http_raw_post_data, true);
     if (!isset($http_post_object['method'])) {
         return false;
     }
     // Errors are managed with exceptions, so if there is not any exception then the status is OK
     $status = 'OK';
     try {
         if ($http_post_object['method'] != 'credit') {
             throw new Exception($this->l('Method not supported'));
         }
         if (!$this->trustly_verify($http_post_object['method'], $http_post_object['params']['uuid'], $http_post_object['params']['data'], $http_post_object['params']['signature'])) {
             throw new Exception($this->l('The response from Trustly server cannot be verified'));
         }
         // We can save the order in the database, PrestaShop handle everything by itself
         $id_cart = intval($http_post_object['params']['data']['messageid']);
         $cart = new Cart($id_cart);
         $id_currency = (int) Currency::getIdByIsoCode($http_post_object['params']['data']['currency']);
         if ((bool) $id_currency === false) {
             $payment_status = Configuration::get('PS_OS_ERROR');
         } else {
             $payment_status = Configuration::get('PS_OS_PAYMENT');
         }
         if (!$cart->orderExists()) {
             $customer = new Customer($http_post_object['params']['data']['enduserid']);
             $this->validateOrder($id_cart, $payment_status, $http_post_object['params']['data']['amount'], $this->displayName, print_r($http_post_object['params']['data'], true), array(), $id_currency, false, $customer->secure_key);
         }
     } catch (Exception $e) {
         // This status will be returned to Trustly
         $status = 'FAILED';
     }
     // The response is prepared then returned
     $response_api_method = $http_post_object['method'];
     $response_api_version = '1.1';
     $response_api_uuid = $http_post_object['params']['uuid'];
     $response_api_data = array('status' => $status);
     $response_api_signature = $this->trustly_sign($response_api_method, $response_api_uuid, $response_api_data);
     $response_api_result = array('method' => $response_api_method, 'signature' => $response_api_signature, 'uuid' => $response_api_uuid, 'data' => $response_api_data);
     $response_array = array('result' => $response_api_result, 'version' => $response_api_version);
     $response_json = Tools::jsonEncode($response_array);
     return $response_json;
 }
Пример #5
0
 public function initContent()
 {
     parent::initContent();
     $this->context = Context::getContext();
     $payulatam = new PayuLatam();
     if (isset($_REQUEST['signature'])) {
         $signature = $_REQUEST['signature'];
     } else {
         $signature = $_REQUEST['firma'];
     }
     if (isset($_REQUEST['merchantId'])) {
         $merchant_id = $_REQUEST['merchantId'];
     } else {
         $merchant_id = $_REQUEST['usuario_id'];
     }
     if (isset($_REQUEST['referenceCode'])) {
         $reference_code = $_REQUEST['referenceCode'];
     } else {
         $reference_code = $_REQUEST['ref_venta'];
     }
     if (isset($_REQUEST['TX_VALUE'])) {
         $value = $_REQUEST['TX_VALUE'];
     } else {
         $value = $_REQUEST['valor'];
     }
     if (isset($_REQUEST['currency'])) {
         $currency = $_REQUEST['currency'];
     } else {
         $currency = $_REQUEST['moneda'];
     }
     if (isset($_REQUEST['transactionState'])) {
         $transaction_state = $_REQUEST['transactionState'];
     } else {
         $transaction_state = $_REQUEST['estado'];
     }
     $value = number_format($value, 1, '.', '');
     $api_key = Configuration::get('PAYU_LATAM_API_KEY');
     $signature_local = $api_key . '~' . $merchant_id . '~' . $reference_code . '~' . $value . '~' . $currency . '~' . $transaction_state;
     $signature_md5 = md5($signature_local);
     if (isset($_REQUEST['polResponseCode'])) {
         $pol_response_code = $_REQUEST['polResponseCode'];
     } else {
         $pol_response_code = $_REQUEST['codigo_respuesta_pol'];
     }
     $messageApproved = '';
     if ($transaction_state == 6 && $pol_response_code == 5) {
         $estado_tx = $payulatam->l('Failed Transaction');
     } else {
         if ($transaction_state == 6 && $pol_response_code == 4) {
             $estado_tx = $payulatam->l('Rejected Transaction');
         } else {
             if ($transaction_state == 12 && $pol_response_code == 9994) {
                 $estado_tx = $payulatam->l('Pending Transaction, Please check if the debit was made in the Bank');
             } else {
                 if ($transaction_state == 4 && $pol_response_code == 1) {
                     $estado_tx = $payulatam->l('Transaction Approved');
                     $messageApproved = $payulatam->l('Thank you for your purchase!');
                 } else {
                     if (isset($_REQUEST['message'])) {
                         $estado_tx = $_REQUEST['message'];
                     } else {
                         $estado_tx = $_REQUEST['mensaje'];
                     }
                 }
             }
         }
     }
     if (isset($_REQUEST['transactionId'])) {
         $transaction_id = $_REQUEST['transactionId'];
     } else {
         $transaction_id = $_REQUEST['transaccion_id'];
     }
     if (isset($_REQUEST['reference_pol'])) {
         $reference_pol = $_REQUEST['reference_pol'];
     } else {
         $reference_pol = $_REQUEST['ref_pol'];
     }
     if (isset($_REQUEST['pseBank'])) {
         $pse_bank = $_REQUEST['pseBank'];
     } else {
         $pse_bank = $_REQUEST['banco_pse'];
     }
     $cus = $_REQUEST['cus'];
     if (isset($_REQUEST['description'])) {
         $description = $_REQUEST['description'];
     } else {
         $description = $_REQUEST['descripcion'];
     }
     if (isset($_REQUEST['lapPaymentMethod'])) {
         $lap_payment_method = $_REQUEST['lapPaymentMethod'];
     } else {
         $lap_payment_method = $_REQUEST['medio_pago_lap'];
     }
     $cart = new Cart((int) $reference_code);
     if (Tools::strtoupper($signature) == Tools::strtoupper($signature_md5)) {
         if (!$cart->orderExists()) {
             $customer = new Customer((int) $cart->id_customer);
             $this->context->customer = $customer;
             $payulatam->validateOrder((int) $cart->id, Configuration::get('PAYU_OS_PENDING'), (double) $cart->getordertotal(true), 'PayU', null, array(), (int) $cart->id_currency, false, $customer->secure_key);
             Configuration::updateValue('PAYULATAM_CONFIGURATION_OK', true);
         }
         $this->context->smarty->assign(array('estadoTx' => $estado_tx, 'transactionId' => $transaction_id, 'reference_pol' => $reference_pol, 'referenceCode' => $reference_code, 'pseBank' => $pse_bank, 'cus' => $cus, 'value' => $value, 'currency' => $currency, 'description' => $description, 'lapPaymentMethod' => $lap_payment_method, 'messageApproved' => $messageApproved, 'valid' => true, 'css' => '../modules/payulatam/css/'));
     } else {
         $this->context->smarty->assign(array('valid' => false, 'css' => '../modules/payulatam/css/'));
     }
     $this->setTemplate('response.tpl');
 }
function hipayResetOrderStatus($cart = null)
{
    echo '-fnROS';
    if ($_POST['status'] == '117' || $_POST['status'] == '118') {
        $cart = new Cart((int) $_POST['order']->id);
        if ($cart->orderExists()) {
            $orderState = _PS_OS_PAYMENT_;
            if ($_POST['captured_amount'] < $_POST['authorized_amount']) {
                $orderState = Configuration::get('HIPAY_PARTIALLY_CAPTURED') ? Configuration::get('HIPAY_PARTIALLY_CAPTURED') : HipayClass::getConfiguration('HIPAY_PARTIALLY_CAPTURED');
            }
            // FORCE INVOICE CREATION IF OrderState = _PS_OS_PAYMENT_
            if ($orderState == _PS_OS_PAYMENT_) {
                $order_id = retrieveOrderId($cart->id);
                // Retrieve order id
                $order = new Order((int) $order_id);
                // Recreate order
                $newOS = new OrderState((int) $orderState, $order->id_lang);
                // Emulate the order state _PS_OS_PAYMENT_
                // Uf the order state allows invoice and there is no invoice number, then generate the invoice
                if ($newOS->invoice and !$order->invoice_number) {
                    $order->setInvoice();
                }
            }
        }
    }
    // New modification for status challenged
    // Second check for status 112 -> 117 -> 118
    if ($_POST['status'] == '117') {
        if ((bool) $order->getHistory($context->language->id, Configuration::get('HIPAY_CHALLENGED'))) {
            $cart = new Cart((int) $_POST['order']->id);
            if ($cart->orderExists()) {
                $orderState = _PS_OS_PAYMENT_;
            }
            if ($_POST['captured_amount'] < $_POST['authorized_amount']) {
                $orderState = Configuration::get('HIPAY_PARTIALLY_CAPTURED') ? Configuration::get('HIPAY_PARTIALLY_CAPTURED') : HipayClass::getConfiguration('HIPAY_PARTIALLY_CAPTURED');
            }
            // FORCE INVOICE CREATION IF OrderState = _PS_OS_PAYMENT_
            if ($orderState == _PS_OS_PAYMENT_) {
                $order_id = retrieveOrderId($cart->id);
                // Retrieve order id
                $order = new Order((int) $order_id);
                // Recreate order
                $newOS = new OrderState((int) $orderState, $order->id_lang);
                // Emulate the order state _PS_OS_PAYMENT_
                // Uf the order state allows invoice and there is no invoice number, then generate the invoice
                if ($newOS->invoice and !$order->invoice_number) {
                    $order->setInvoice();
                }
            }
        }
    }
    // Update to minimize risk of simultaneous calls for status 116 and 117
    if ($_POST['status'] == '116') {
        usleep(500000);
        // 0.5sec
        echo '/116';
        // If order exists for cart
        $cart = new Cart((int) $_POST['order']->id);
        if ($cart->orderExists()) {
            echo '/C_OK' . $GLOBALS['_HIPAY_CALLBACK_ORDER_ID_'];
            $context = Context::getContext();
            // Retrieve Order ID
            $order_id = retrieveOrderId($cart->id);
            $order = new Order((int) $order_id);
            echo '/' . (int) $order_id;
            // If current state is paiement accepted or capture partielle
            // then skip the process
            if ((bool) $order->getHistory($context->language->id, _PS_OS_PAYMENT_)) {
                echo '/' . (int) _PS_OS_PAYMENT_ . '_U';
                // Update orders
                $sql_update = "UPDATE `" . _DB_PREFIX_ . "orders`\r\n                    SET `current_state` = '" . _PS_OS_PAYMENT_ . "'\r\n                    WHERE `id_order`='" . (int) $order_id . "'";
                Db::getInstance()->execute($sql_update);
                // Insert into order_history
                $sql_insert = "INSERT INTO `" . _DB_PREFIX_ . "order_history` (`id_employee`, `id_order`, `id_order_state`, `date_add`)\r\n                    VALUES ('0', '" . (int) $order_id . "', '" . _PS_OS_PAYMENT_ . "', now());";
                Db::getInstance()->execute($sql_insert);
            }
            if ((bool) $order->getHistory($context->language->id, Configuration::get('HIPAY_PARTIALLY_CAPTURED'))) {
                echo '/' . (int) Configuration::get('HIPAY_PARTIALLY_CAPTURED') . '_U';
                // Update orders
                $sql_update = "UPDATE `" . _DB_PREFIX_ . "orders`\r\n                    SET `current_state` = '" . Configuration::get('HIPAY_PARTIALLY_CAPTURED') . "'\r\n                    WHERE `id_order`='" . (int) $order_id . "'";
                Db::getInstance()->execute($sql_update);
                // Insert into order_history
                $sql_insert = "INSERT INTO `" . _DB_PREFIX_ . "order_history` (`id_employee`, `id_order`, `id_order_state`, `date_add`)\r\n                    VALUES ('0', '" . (int) $order_id . "', '" . Configuration::get('HIPAY_PARTIALLY_CAPTURED') . "', now());";
                Db::getInstance()->execute($sql_insert);
            }
            HipayLogger::addLog($hipay->l('Callback process', 'hipay'), HipayLogger::NOTICE, 'hipayResetOrderStatus status 116 cart already ok - cid : ' . (int) $_POST['order']->id);
            die;
        } else {
            echo '/C_KO' . $GLOBALS['_HIPAY_CALLBACK_ORDER_ID_'];
        }
    }
    HipayLogger::addLog($hipay->l('Callback process', 'hipay'), HipayLogger::NOTICE, 'hipayResetOrderStatus ended - cid : ' . (int) $_POST['order']->id);
    die;
}
Пример #7
0
    $reference_pol = $_REQUEST['ref_pol'];
}
if (isset($_REQUEST['pseBank'])) {
    $pse_bank = $_REQUEST['pseBank'];
} else {
    $pse_bank = $_REQUEST['banco_pse'];
}
$cus = $_REQUEST['cus'];
if (isset($_REQUEST['description'])) {
    $description = $_REQUEST['description'];
} else {
    $description = $_REQUEST['descripcion'];
}
if (isset($_REQUEST['lapPaymentMethod'])) {
    $lap_payment_method = $_REQUEST['lapPaymentMethod'];
} else {
    $lap_payment_method = $_REQUEST['medio_pago_lap'];
}
$cart = new Cart((int) $reference_code);
if (Tools::strtoupper($signature) == Tools::strtoupper($signature_md5)) {
    if (!$cart->orderExists()) {
        $customer = new Customer((int) $cart->id_customer);
        Context::getContext()->customer = $customer;
        $payulatam->validateOrder((int) $cart->id, Configuration::get('PAYU_OS_PENDING'), (double) $cart->getordertotal(true), 'PayU', null, array(), (int) $cart->id_currency, false, $customer->secure_key);
    }
    Context::getContext()->smarty->assign(array('estadoTx' => $estado_tx, 'transactionId' => $transaction_id, 'reference_pol' => $reference_pol, 'referenceCode' => $reference_code, 'pseBank' => $pse_bank, 'cus' => $cus, 'value' => $value, 'currency' => $currency, 'description' => $description, 'lapPaymentMethod' => $lap_payment_method, 'messageApproved' => $messageApproved, 'valid' => true, 'css' => '../modules/payulatam/css/'));
} else {
    Context::getContext()->smarty->assign(array('valid' => false, 'css' => '../modules/payulatam/css/'));
}
Context::getContext()->smarty->display(dirname(__FILE__) . '/../views/templates/front/response.tpl');
include dirname(__FILE__) . '/../../../footer.php';