/**
  * @return string
  */
 public function getContent()
 {
     $paymentsParams = array();
     $output = '<h2>' . 'SecurionPay ' . 'refund for order id: ' . Tools::getValue('id_order') . '</h2>';
     $order = new Order(Tools::getValue('id_order'));
     $payments = $order->getOrderPaymentCollection();
     $currency = new Currency((int) $order->id_currency);
     foreach ($payments as $payment) {
         if ($payment->payment_method == 'Card payment') {
             $paymentsParams[] = array('id' => $payment->transaction_id, 'name' => $this->l($payment->transaction_id . ' ' . $payment->amount . ' ' . $currency->sign));
         }
     }
     return $output . $this->renderForm($paymentsParams);
 }
 public function initContent()
 {
     global $smarty, $cart;
     $this->display_column_left = false;
     $this->display_column_right = false;
     parent::initContent();
     if (!empty($_POST)) {
         $b_is_SSL = function_exists('curl_init') && function_exists('curl_setopt') && function_exists('curl_exec') && function_exists('curl_close');
         $p24_session_id = $_POST["p24_session_id"];
         $p24_order_id = $_POST["p24_order_id"];
         $p24_id_sprzedawcy = Configuration::get('P24_ID_SPRZEDAWCY');
         //TWÓJ ID_SPRZEDAWCY;
         $sa_sid = explode('|', $_POST["p24_session_id"]);
         $sa_sid = preg_replace('/[^a-z0-9]/i', '', $sa_sid[1]);
         $o_order = Db::getInstance()->getRow('SELECT `i_id_order`,`i_amount` FROM `' . _DB_PREFIX_ . 'przelewy24_amount` WHERE `s_sid`="' . $sa_sid . '"');
         $p24_kwota = (int) $o_order['i_amount'];
         // WYNIK POBRANY Z TWOJEJ BAZY (w groszach)
         $i_id_order = $o_order['i_id_order'];
         $WYNIK = false;
         $url = 'secure.przelewy24.pl';
         if (Configuration::get('P24_TEST_MODE') == 1) {
             $url = 'sandbox.przelewy24.pl';
         }
         if ($b_is_SSL) {
             $WYNIK = p24_weryfikujSSL($p24_id_sprzedawcy, $p24_session_id, $p24_order_id, $p24_kwota, $url);
         } else {
             $WYNIK = p24_weryfikujNoSSL($p24_id_sprzedawcy, $p24_session_id, $p24_order_id, $p24_kwota, $url);
         }
         $o_przelewy24 = new Przelewy24();
         $opis = "przelewy24.pl";
         $cart = new Cart($i_id_order);
         $secure_key = $cart->secure_key;
         if ($WYNIK[0] == 'TRUE') {
             $order_id = Order::getOrderByCartId(intval($i_id_order));
             $order = new Order($order_id);
             $history = new OrderHistory();
             $history->id_order = intval($order_id);
             $order_state = Configuration::get('P24_ORDER_STATE_2');
             $history->changeIdOrderState($order_state, intval($order_id));
             $history->addWithemail(true);
             $payments = $order->getOrderPaymentCollection();
             if (count($payments) > 0) {
                 $payments[0]->transaction_id = $p24_order_id;
                 $payments[0]->update();
             }
         }
         $smarty->assign('p24_status', 'success');
     }
     $this->setTemplate('paymentSuccessful.tpl');
 }
 /**
  * @param $response
  * @param $payu
  * @param $id_order
  */
 private function addPaymentIdToOrder($response, Payu $payu, $id_order)
 {
     $payu->payu_payment_id = $response->properties[0]->value;
     SimplePayuLogger::addLog('notification', __FUNCTION__, 'PAYMENT_ID: ' . $payu->payu_payment_id, $payu->payu_order_id);
     SimplePayuLogger::addLog('notification', __FUNCTION__, 'Status zamówienia PayU: ' . $response->order->status, $response->order->orderId);
     if (version_compare(_PS_VERSION_, '1.5', 'ge')) {
         $order = new Order($id_order);
         $payment = $order->getOrderPaymentCollection();
         $payments = $payment->getAll();
         $payments[$payment->count() - 1]->transaction_id = $payu->payu_payment_id;
         $payments[$payment->count() - 1]->update();
     } else {
         $payu->addMsgToOrder('payment_id: ' . $payu->payu_payment_id, $id_order);
     }
 }
 /**
  * @brief Validate a payment, verify if everything is right
  */
 public function validation()
 {
     if (!isset($_POST['sign']) && !isset($_POST['signature'])) {
         Logger::AddLog('[Payulatam] the signature is missing.', 2, null, null, null, true);
     } else {
         $token = isset($_POST['sign']) ? $_POST['sign'] : $_POST['signature'];
     }
     if (!isset($_POST['reference_sale']) && !isset($_POST['referenceCode'])) {
         Logger::AddLog('[Payulatam] the reference is missing.', 2, null, null, null, true);
     } else {
         $ref = isset($_POST['reference_sale']) ? $_POST['reference_sale'] : $_POST['referenceCode'];
     }
     if (!isset($_POST['value']) && !isset($_POST['amount'])) {
         Logger::AddLog('[Payulatam] the amount is missing.', 2, null, null, null, true);
     } else {
         $amount = isset($_POST['value']) ? $_POST['value'] : $_POST['amount'];
     }
     if (!isset($_POST['merchant_id']) && !isset($_POST['merchantId'])) {
         Logger::AddLog('[Payulatam] the merchantId is missing.', 2, null, null, null, true);
     } else {
         $merchantId = isset($_POST['merchant_id']) ? $_POST['merchant_id'] : $_POST['merchantId'];
     }
     if (!isset($_POST['lap_state']) && !isset($_POST['state_pol'])) {
         Logger::AddLog('[Payulatam] the lap_state is missing.', 2, null, null, null, true);
     } else {
         $statePol = isset($_POST['lap_state']) ? $_POST['lap_state'] : $_POST['state_pol'];
     }
     $idCart = substr($ref, 6 + strlen(Configuration::get('PS_SHOP_NAME')));
     $this->context->cart = new Cart((int) $idCart);
     if (!$this->context->cart->OrderExists()) {
         Logger::AddLog('[Payulatam] The shopping card ' . (int) $idCart . ' doesn\'t have any order created', 2, null, null, null, true);
         return false;
     }
     if (Validate::isLoadedObject($this->context->cart)) {
         $id_orders = Db::getInstance()->ExecuteS('SELECT `id_order` FROM `' . _DB_PREFIX_ . 'orders` WHERE `id_cart` = ' . (int) $this->context->cart->id . '');
         foreach ($id_orders as $val) {
             $order = new Order((int) $val['id_order']);
             if ($this->context->cart->getOrderTotal() != $amount) {
                 Logger::AddLog('[Payulatam] The shopping card ' . (int) $idCart . ' doesn\'t have the correct amount expected during payment validation', 2, null, null, null, true);
             } else {
                 $currency = new Currency((int) $this->context->cart->id_currency);
                 if ($token == md5(Configuration::get('PAYU_API_KEY') . '~' . Tools::safeOutput(Configuration::get('PAYU_MERCHANT_ID')) . '~payU_' . Configuration::get('PS_SHOP_NAME') . '_' . (int) $this->context->cart->id . '~' . (double) $this->context->cart->getOrderTotal() . '~' . $currency->iso_code . '~' . $statePol)) {
                     if ($statePol == 7) {
                         $order->setCurrentState((int) Configuration::get('PAYU_WAITING_PAYMENT'));
                     } else {
                         if ($statePol == 4) {
                             $order->setCurrentState((int) Configuration::get('PS_OS_PAYMENT'));
                         } else {
                             $order->setCurrentState((int) Configuration::get('PS_OS_ERROR'));
                             Logger::AddLog('[PayU] The shopping card ' . (int) $idCart . ' has been rejected by PayU state pol=' . (int) $statePol, 2, null, null, null, true);
                         }
                     }
                 } else {
                     Logger::AddLog('[PayU] The shopping card ' . (int) $idCart . ' has an incorrect token given from payU during payment validation', 2, null, null, null, true);
                 }
             }
             if (_PS_VERSION_ >= 1.5) {
                 $payment = $order->getOrderPaymentCollection();
                 if (isset($payment[0])) {
                     $payment[0]->transaction_id = pSQL($ref);
                     $payment[0]->save();
                 }
             }
         }
     } else {
         Logger::AddLog('[PayU] The shopping card ' . (int) $idCart . ' was not found during the payment validation step', 2, null, null, null, true);
     }
 }
 public function validationws()
 {
     require_once _PS_MODULE_DIR_ . 'payulatam/config.php';
     $conf = new ConfPayu();
     $keysPayu = $conf->keys();
     $currency_iso_code = '';
     if ($conf->isTest()) {
         $currency_iso_code = 'USD';
     } else {
         $currency_iso_code = $params[9]['currency'];
     }
     if (!isset($_POST['sign']) && !isset($_POST['signature'])) {
         Logger::AddLog('[Payulatam] the signature is missing.', 2, null, null, null, true);
     } else {
         $token = isset($_POST['sign']) ? $_POST['sign'] : $_POST['signature'];
     }
     if (!isset($_POST['reference_sale']) && !isset($_POST['referenceCode'])) {
         Logger::AddLog('[Payulatam] the reference is missing.', 2, null, null, null, true);
     } else {
         $ref = isset($_POST['reference_sale']) ? $_POST['reference_sale'] : $_POST['referenceCode'];
     }
     if (!isset($_POST['value']) && !isset($_POST['amount'])) {
         Logger::AddLog('[Payulatam] the amount is missing.', 2, null, null, null, true);
     } else {
         $amount = isset($_POST['value']) ? $_POST['value'] : $_POST['amount'];
     }
     if (!isset($_POST['merchant_id']) && !isset($_POST['merchantId'])) {
         Logger::AddLog('[Payulatam] the merchantId is missing.', 2, null, null, null, true);
     } else {
         $merchantId = isset($_POST['merchant_id']) ? $_POST['merchant_id'] : $_POST['merchantId'];
     }
     if (!isset($_POST['lap_state']) && !isset($_POST['state_pol'])) {
         Logger::AddLog('[Payulatam] the lap_state is missing.', 2, null, null, null, true);
     } else {
         $statePol = isset($_POST['lap_state']) ? $_POST['lap_state'] : $_POST['state_pol'];
     }
     $idCart = explode('_', $ref)[2];
     $this->context->cart = new Cart((int) $idCart);
     $total_order = $this->context->cart->getOrderTotal();
     if (!$this->context->cart->OrderExists()) {
         Logger::AddLog('[Payulatam] The shopping card ' . (int) $idCart . ' doesn\'t have any order created', 2, null, null, null, true);
         return false;
     }
     if (Validate::isLoadedObject($this->context->cart)) {
         $id_orders = Db::getInstance()->ExecuteS('SELECT `id_order` FROM `' . _DB_PREFIX_ . 'orders` WHERE `id_cart` = ' . (int) $this->context->cart->id . '');
         foreach ($id_orders as $val) {
             $order = new Order((int) $val['id_order']);
             if ($this->context->cart->getOrderTotal() != $amount) {
                 Logger::AddLog('[Payulatam] The shopping card ' . (int) $idCart . ' doesn\'t have the correct amount expected during payment validation.' . $keysPayu['apiKey'] . '~' . Tools::safeOutput($keysPayu['merchantId']) . '~payU_' . Configuration::get('PS_SHOP_NAME') . '_' . (int) $this->context->cart->id . '~' . number_format((double) $this->context->cart->getOrderTotal(), 2, '.', '') . '~' . $currency->iso_code . '~' . $statePol . "---" . $amount, 2, null, null, null, true);
             } else {
                 $currency = new Currency((int) $this->context->cart->id_currency);
                 if ($token == md5($keysPayu['apiKey'] . '~' . Tools::safeOutput($keysPayu['merchantId']) . '~payU_' . Configuration::get('PS_SHOP_NAME') . '_' . (int) $this->context->cart->id . '_' . $conf->get_intentos($this->context->cart->id) . '~' . number_format((double) $total_order, 2, '.', '') . '~' . $currency_iso_code . '~' . $statePol) || $token == md5($keysPayu['apiKey'] . '~' . Tools::safeOutput($keysPayu['merchantId']) . '~payU_' . Configuration::get('PS_SHOP_NAME') . '_' . (int) $this->context->cart->id . '_' . $conf->get_intentos($this->context->cart->id) . '~' . number_format((double) $total_order, 1, '.', '') . '~' . $currency_iso_code . '~' . $statePol) || $token == md5($keysPayu['apiKey'] . '~' . Tools::safeOutput($keysPayu['merchantId']) . '~payU_' . Configuration::get('PS_SHOP_NAME') . '_' . (int) $this->context->cart->id . '_' . $conf->get_intentos($this->context->cart->id) . '~' . number_format((double) $total_order, 0, '.', '') . '~' . $currency_iso_code . '~' . $statePol)) {
                     // CUANDO SE ENVIAN # ENTEROS EN EL PAGO A PAYU, ESTE RETORNA 1 DECIMAL, CUANDO SE ENVIAN DECIMALES, PAYU RETORNA 2 DECIMALES. SE VALIDA TAMBIEN SIN DECIMALES EVG GPB
                     if ($statePol == 7) {
                         if ($order->getCurrentState() != (int) Configuration::get('PAYU_WAITING_PAYMENT')) {
                             $order->setCurrentState((int) Configuration::get('PAYU_WAITING_PAYMENT'));
                         }
                     } else {
                         if ($statePol == 4) {
                             if ($order->getCurrentState() != (int) Configuration::get('PS_OS_PAYMENT')) {
                                 $order->setCurrentState((int) Configuration::get('PS_OS_PAYMENT'));
                             }
                         } else {
                             if ($order->getCurrentState() != (int) Configuration::get('PS_OS_ERROR')) {
                                 $order->setCurrentState((int) Configuration::get('PS_OS_ERROR'));
                             }
                             Logger::AddLog('[PayU] (payulatam) The shopping card ' . (int) $idCart . ' has been rejected by PayU state pol=' . (int) $statePol, 2, null, null, null, true);
                         }
                     }
                 } else {
                     Logger::AddLog('[PayU] The shopping card ' . (int) $idCart . ' has an incorrect token given from payU during payment validation.' . $keysPayu['apiKey'] . '~' . Tools::safeOutput($keysPayu['merchantId']) . '~payU_' . Configuration::get('PS_SHOP_NAME') . '_' . (int) $this->context->cart->id . '~' . number_format((double) $total_order, 2, '.', '') . '~' . $currency->iso_code . '~' . $statePol . "--" . number_format((double) $total_order, 1, '.', '') . "--" . $token, 2, null, null, null, true);
                 }
             }
             if (_PS_VERSION_ >= 1.5) {
                 $payment = $order->getOrderPaymentCollection();
                 if (isset($payment[0])) {
                     $payment[0]->transaction_id = pSQL("payU_" . md5(Configuration::get('PS_SHOP_NAME')) . "_" . $idCart);
                     $payment[0]->save();
                 }
             }
         }
     } else {
         Logger::AddLog('[PayU] The shopping card ' . (int) $idCart . ' was not found during the payment validation step', 2, null, null, null, true);
     }
 }
Exemple #6
0
 /**
  * Interpret instant payment notification
  *
  * @param array $params
  * @return array|bool
  */
 public function interpretIPN(array $params)
 {
     if (!isset($params['REFNOEXT'], $params['HASH'], $params['ORDERSTATUS'], $params['REFNO'], $params['IPN_TOTALGENERAL'], $params['CURRENCY'], $params['HASH'], $params['IPN_PID'], $params['IPN_PNAME'], $params['IPN_DATE'])) {
         return array('error' => 'One or more parameters are missing');
     }
     $order_id = (int) $params['REFNOEXT'];
     if (empty($order_id)) {
         return array('error' => 'Missing REFNOEXT');
     }
     if ($this->getBusinessPartnerSetting('type') !== self::BUSINESS_PARTNER_TYPE_EPAYMENT) {
         return array('error' => 'Incorrect business partner');
     }
     if (!Configuration::get('PAYU_EPAYMENT_IPN')) {
         return array('error' => 'IPN disabled');
     }
     if ($params['HASH'] != PayuSignature::generateHmac(Configuration::get('PAYU_EPAYMENT_SECRET_KEY'), PayuSignature::signatureString($params, array('HASH')))) {
         return array('error' => 'Invalid signature');
     }
     try {
         $history = new OrderHistory();
         $history->id_order = $order_id;
         switch ($params['ORDERSTATUS']) {
             case 'PAYMENT_AUTHORIZED':
             case 'PAYMENT_RECEIVED':
                 $new_status = (int) Configuration::get('PAYU_PAYMENT_STATUS_COMPLETED');
                 $history->changeIdOrderState($new_status, $order_id);
                 $history->addWithemail(true);
                 $order = new Order($order_id);
                 if (version_compare(_PS_VERSION_, '1.5', 'ge')) {
                     $payment = $order->getOrderPaymentCollection();
                     $payments = $payment->getAll();
                     $payments[$payment->count() - 1]->transaction_id = $params['REFNO'];
                     $payments[$payment->count() - 1]->update();
                 }
                 $this->updatePayuTransaction($order_id, (int) $params['REFNO'], $params['IPN_TOTALGENERAL'], $params['CURRENCY']);
                 break;
         }
         $date = date('YmdGis');
         $response_params = array($params['IPN_PID'][0], $params['IPN_PNAME'][0], $params['IPN_DATE'], $date);
         $hash = PayuSignature::generateHmac(Configuration::get('PAYU_EPAYMENT_SECRET_KEY'), PayuSignature::signatureString($response_params, array('HASH')));
         return array('date' => $date, 'hash' => $hash);
     } catch (Exception $e) {
         Logger::addLog($this->displayName . ' ' . trim($e->getCode() . ' ' . $e->getMessage() . ' id_order: ' . $order_id), 1);
         return false;
     }
 }
 /**
  * @param array $hook
  * @return string
  */
 public function hookdisplayAdminOrder($hook)
 {
     $order = new Order(Tools::getValue('id_order'));
     $securionPayPayment = null;
     foreach ($order->getOrderPaymentCollection() as $payment) {
         if ($payment->payment_method == 'Card payment' && $order->module == 'securionpay' && $order->getCurrentState() != 7) {
             $securionPayPayment = $payment;
             break;
         }
     }
     if (!$securionPayPayment) {
         return '';
     }
     $this->context->smarty->assign(array('button_href' => 'index.php?controller=AdminSecurionPay' . '&id_order=' . Tools::getValue('id_order') . '&token=' . Tools::getAdminTokenLite('AdminSecurionPay'), 'version' => (double) _PS_VERSION_));
     return $this->display(__FILE__, 'displayAdminOrder.tpl');
 }
 public function updatePendyngOrdesConfirmation()
 {
     $orders_pendyng = $this->getPendyngOrdesConfirmation();
     foreach ($orders_pendyng as $key) {
         $order = new Order((int) $key['id_order']);
         $statePol = $this->getStatePolBymessagePol($key['message']);
         if ($statePol == 7) {
             if ($order->getCurrentState() != (int) Configuration::get('PAYU_OS_PENDING')) {
                 $order->setCurrentState((int) Configuration::get('PAYU_OS_PENDING'));
             }
         } else {
             if ($statePol == 4) {
                 if ($order->getCurrentState() != (int) Configuration::get('PS_OS_PAYMENT')) {
                     $order->setCurrentState((int) Configuration::get('PS_OS_PAYMENT'));
                 }
             } else {
                 if ($order->getCurrentState() != (int) Configuration::get('PS_OS_ERROR')) {
                     $order->setCurrentState((int) Configuration::get('PS_OS_ERROR'));
                 }
             }
         }
         if (_PS_VERSION_ >= 1.5) {
             $payment = $order->getOrderPaymentCollection();
             if (isset($payment[0])) {
                 $payment[0]->transaction_id = pSQL("payU_farmalisto_" . $key['id_cart']);
                 $payment[0]->save();
             }
         }
         echo '<br>Order: ' . $key['id_order'];
     }
 }