diff --git a/1.7.6/mobilpay_cc/validation.php b/1.7.6/mobilpay_cc/validation.php deleted file mode 100644 index e625115..0000000 --- a/1.7.6/mobilpay_cc/validation.php +++ /dev/null @@ -1,141 +0,0 @@ -boot(); - } - - #calea catre cheia privata - #cheia privata este generata de mobilpay, accesibil in Admin -> Conturi de comerciant -> Detalii -> Setari securitate - $privateKeyFilePath = dirname(__FILE__).'/Mobilpay/certificates/private.key'; - - try - { - $objPmReq = Mobilpay_Payment_Request_Abstract::factoryFromEncrypted($_POST['env_key'], $_POST['data'], $privateKeyFilePath); - - switch($objPmReq->objPmNotify->action) - { - #orice action este insotit de un cod de eroare si de un mesaj de eroare. Acestea pot fi citite folosind $cod_eroare = $objPmReq->objPmNotify->errorCode; respectiv $mesaj_eroare = $objPmReq->objPmNotify->errorMessage; - #pentru a identifica ID-ul comenzii pentru care primim rezultatul platii folosim $id_comanda = $objPmReq->orderId; - case 'confirmed': - #cand action este confirmed avem certitudinea ca banii au plecat din contul posesorului de card si facem update al starii comenzii si livrarea produsului - $errorMessage = $objPmReq->objPmNotify->getCrc(); - break; - case 'confirmed_pending': - #cand action este confirmed_pending inseamna ca tranzactia este in curs de verificare antifrauda. Nu facem livrare/expediere. In urma trecerii de aceasta verificare se va primi o noua notificare pentru o actiune de confirmare sau anulare. - $errorMessage = $objPmReq->objPmNotify->getCrc(); - break; - case 'paid_pending': - #cand action este paid_pending inseamna ca tranzactia este in curs de verificare. Nu facem livrare/expediere. In urma trecerii de aceasta verificare se va primi o noua notificare pentru o actiune de confirmare sau anulare. - $errorMessage = $objPmReq->objPmNotify->getCrc(); - break; - case 'paid': - #cand action este paid inseamna ca tranzactia este in curs de procesare. Nu facem livrare/expediere. In urma trecerii de aceasta procesare se va primi o noua notificare pentru o actiune de confirmare sau anulare. - $errorMessage = $objPmReq->objPmNotify->getCrc(); - break; - case 'canceled': - #cand action este canceled inseamna ca tranzactia este anulata. Nu facem livrare/expediere. - $errorMessage = $objPmReq->objPmNotify->getCrc(); - break; - case 'credit': - #cand action este credit inseamna ca banii sunt returnati posesorului de card. Daca s-a facut deja livrare, aceasta trebuie oprita sau facut un reverse. - $errorMessage = $objPmReq->objPmNotify->getCrc(); - break; - default: - $errorType = Mobilpay_Payment_Request_Abstract::CONFIRM_ERROR_TYPE_PERMANENT; - $errorCode = Mobilpay_Payment_Request_Abstract::ERROR_CONFIRM_INVALID_ACTION; - $errorMessage = 'mobilpay_refference_action paramaters is invalid'; - break; - } - } - catch(Exception $e) - { - $errorType = Mobilpay_Payment_Request_Abstract::CONFIRM_ERROR_TYPE_TEMPORARY; - $errorCode = $e->getCode(); - $errorMessage = $e->getMessage(); - } - } - else - { - $errorType = Mobilpay_Payment_Request_Abstract::CONFIRM_ERROR_TYPE_PERMANENT; - $errorCode = Mobilpay_Payment_Request_Abstract::ERROR_CONFIRM_INVALID_POST_PARAMETERS; - $errorMessage = 'mobilpay.ro posted invalid parameters'; - } -} -else -{ - $errorType = Mobilpay_Payment_Request_Abstract::CONFIRM_ERROR_TYPE_PERMANENT; - $errorCode = Mobilpay_Payment_Request_Abstract::ERROR_CONFIRM_INVALID_POST_METHOD; - $errorMessage = 'invalid request metod for payment confirmation'; -} - -$Mobilpay_cc = new Mobilpay_cc(); - -if(!empty($objPmReq->orderId) && $objPmReq->objPmNotify->errorCode == 0) { - $orderIdParts = explode('#', $objPmReq->orderId); - $realOrderId = intval($orderIdParts[0]); - $cart = new Cart($realOrderId); - $customer = new Customer((int)$cart->id_customer); - - //real order id - $order_id = Order::getOrderByCartId($realOrderId); - - if(intval($order_id)>0) { - $order = new Order(intval($order_id)); - - $history = new OrderHistory(); - $history->id_order = $order_id; - $history->changeIdOrderState(intval(Configuration::get('MPCC_OS_'.strtoupper($objPmReq->objPmNotify->action))), intval($order_id)); - - $history->id_employee = 1; - $carrier = new Carrier(intval($order->id_carrier), intval($order->id_lang)); - $templateVars = array('{followup}' => ($history->id_order_state == _PS_OS_SHIPPING_ AND $order->shipping_number) ? str_replace('@', $order->shipping_number, $carrier->url) : ''); - $history->addWithemail(true, $templateVars); - } - else { - //create the order - $Mobilpay_cc->validateOrder($objPmReq->orderId, intval(Configuration::get('MPCC_OS_'.strtoupper($objPmReq->objPmNotify->action))), floatval($objPmReq->invoice->amount), $Mobilpay_cc->displayName, NULL, array(), NULL, false, $customer->secure_key); - /*Tools::redirect( - $this->context->link->getPagelink( - 'order-confirmation.php', - null, - null, - array( - 'id_cart' => (int)$realOrderIdd, - 'id_module' => (int)$Mobilpay_cc->id, - 'id_order' => (int)$Mobilpay_cc->currentOrder, - 'key' => $customer->secure_key - ) - ) - );*/ - } -} - -header('Content-type: application/xml'); -echo "\n"; -if($errorCode == 0) -{ - echo "{$errorMessage}"; -} -else -{ - echo "{$errorMessage}"; -} diff --git a/1.7.6/mobilpay_cc/Mobilpay/Payment/Address.php b/1.7.7/mobilpay_cc/Mobilpay/Payment/Address.php similarity index 100% rename from 1.7.6/mobilpay_cc/Mobilpay/Payment/Address.php rename to 1.7.7/mobilpay_cc/Mobilpay/Payment/Address.php diff --git a/1.7.6/mobilpay_cc/Mobilpay/Payment/Invoice.php b/1.7.7/mobilpay_cc/Mobilpay/Payment/Invoice.php similarity index 100% rename from 1.7.6/mobilpay_cc/Mobilpay/Payment/Invoice.php rename to 1.7.7/mobilpay_cc/Mobilpay/Payment/Invoice.php diff --git a/1.7.6/mobilpay_cc/Mobilpay/Payment/Invoice/Item.php b/1.7.7/mobilpay_cc/Mobilpay/Payment/Invoice/Item.php similarity index 100% rename from 1.7.6/mobilpay_cc/Mobilpay/Payment/Invoice/Item.php rename to 1.7.7/mobilpay_cc/Mobilpay/Payment/Invoice/Item.php diff --git a/1.7.6/mobilpay_cc/Mobilpay/Payment/Request.php b/1.7.7/mobilpay_cc/Mobilpay/Payment/Request.php similarity index 100% rename from 1.7.6/mobilpay_cc/Mobilpay/Payment/Request.php rename to 1.7.7/mobilpay_cc/Mobilpay/Payment/Request.php diff --git a/1.7.6/mobilpay_cc/Mobilpay/Payment/Request/Abstract.php b/1.7.7/mobilpay_cc/Mobilpay/Payment/Request/Abstract.php similarity index 100% rename from 1.7.6/mobilpay_cc/Mobilpay/Payment/Request/Abstract.php rename to 1.7.7/mobilpay_cc/Mobilpay/Payment/Request/Abstract.php diff --git a/1.7.6/mobilpay_cc/Mobilpay/Payment/Request/Card.php b/1.7.7/mobilpay_cc/Mobilpay/Payment/Request/Card.php similarity index 100% rename from 1.7.6/mobilpay_cc/Mobilpay/Payment/Request/Card.php rename to 1.7.7/mobilpay_cc/Mobilpay/Payment/Request/Card.php diff --git a/1.7.6/mobilpay_cc/Mobilpay/Payment/Request/Notify.php b/1.7.7/mobilpay_cc/Mobilpay/Payment/Request/Notify.php similarity index 100% rename from 1.7.6/mobilpay_cc/Mobilpay/Payment/Request/Notify.php rename to 1.7.7/mobilpay_cc/Mobilpay/Payment/Request/Notify.php diff --git a/1.7.6/mobilpay_cc/Mobilpay/Payment/Request/Sms.php b/1.7.7/mobilpay_cc/Mobilpay/Payment/Request/Sms.php similarity index 100% rename from 1.7.6/mobilpay_cc/Mobilpay/Payment/Request/Sms.php rename to 1.7.7/mobilpay_cc/Mobilpay/Payment/Request/Sms.php diff --git a/1.7.6/mobilpay_cc/Mobilpay/certificates/.htaccess b/1.7.7/mobilpay_cc/Mobilpay/certificates/.htaccess similarity index 100% rename from 1.7.6/mobilpay_cc/Mobilpay/certificates/.htaccess rename to 1.7.7/mobilpay_cc/Mobilpay/certificates/.htaccess diff --git a/1.7.7/mobilpay_cc/README.me b/1.7.7/mobilpay_cc/README.me new file mode 100644 index 0000000..66c38ec --- /dev/null +++ b/1.7.7/mobilpay_cc/README.me @@ -0,0 +1,4 @@ +# Peresta upgrade for 1.7.7.x +## change to str to Front Controller + +## to make it seperate called *ALFA* \ No newline at end of file diff --git a/1.7.6/mobilpay_cc/config.xml b/1.7.7/mobilpay_cc/config.xml similarity index 100% rename from 1.7.6/mobilpay_cc/config.xml rename to 1.7.7/mobilpay_cc/config.xml diff --git a/1.7.6/mobilpay_cc/config_ro.xml b/1.7.7/mobilpay_cc/config_ro.xml similarity index 100% rename from 1.7.6/mobilpay_cc/config_ro.xml rename to 1.7.7/mobilpay_cc/config_ro.xml diff --git a/1.7.6/mobilpay_cc/confirmation.tpl b/1.7.7/mobilpay_cc/confirmation.tpl similarity index 100% rename from 1.7.6/mobilpay_cc/confirmation.tpl rename to 1.7.7/mobilpay_cc/confirmation.tpl diff --git a/1.7.7/mobilpay_cc/controllers/front/betavalidation.php b/1.7.7/mobilpay_cc/controllers/front/betavalidation.php new file mode 100644 index 0000000..35df82f --- /dev/null +++ b/1.7.7/mobilpay_cc/controllers/front/betavalidation.php @@ -0,0 +1,139 @@ +setTemplate('module:mobilpay_cc/views/templates/front/alfavalidation.tpl'); + } + + public function postProcess() + { + if (strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') == 0) + { + + if(isset($_POST['env_key']) && isset($_POST['data'])) + { + + #calea catre cheia privata + #cheia privata este generata de mobilpay, accesibil in Admin -> Conturi de comerciant -> Detalii -> Setari securitate + $privateKeyFilePath = dirname(__FILE__).'/../../Mobilpay/certificates/private.key'; + try{ + $objPmReq = Mobilpay_Payment_Request_Abstract::factoryFromEncrypted($_POST['env_key'], $_POST['data'], $privateKeyFilePath); + + switch($objPmReq->objPmNotify->action) + { + #orice action este insotit de un cod de eroare si de un mesaj de eroare. Acestea pot fi citite folosind $cod_eroare = $objPmReq->objPmNotify->errorCode; respectiv $mesaj_eroare = $objPmReq->objPmNotify->errorMessage; + #pentru a identifica ID-ul comenzii pentru care primim rezultatul platii folosim $id_comanda = $objPmReq->orderId; + case 'confirmed': + #cand action este confirmed avem certitudinea ca banii au plecat din contul posesorului de card si facem update al starii comenzii si livrarea produsului + $errorMessage = $objPmReq->objPmNotify->getCrc(); + break; + case 'confirmed_pending': + #cand action este confirmed_pending inseamna ca tranzactia este in curs de verificare antifrauda. Nu facem livrare/expediere. In urma trecerii de aceasta verificare se va primi o noua notificare pentru o actiune de confirmare sau anulare. + $errorMessage = $objPmReq->objPmNotify->getCrc(); + break; + case 'paid_pending': + #cand action este paid_pending inseamna ca tranzactia este in curs de verificare. Nu facem livrare/expediere. In urma trecerii de aceasta verificare se va primi o noua notificare pentru o actiune de confirmare sau anulare. + $errorMessage = $objPmReq->objPmNotify->getCrc(); + break; + case 'paid': + #cand action este paid inseamna ca tranzactia este in curs de procesare. Nu facem livrare/expediere. In urma trecerii de aceasta procesare se va primi o noua notificare pentru o actiune de confirmare sau anulare. + $errorMessage = $objPmReq->objPmNotify->getCrc(); + break; + case 'canceled': + #cand action este canceled inseamna ca tranzactia este anulata. Nu facem livrare/expediere. + $errorMessage = $objPmReq->objPmNotify->getCrc(); + break; + case 'credit': + #cand action este credit inseamna ca banii sunt returnati posesorului de card. Daca s-a facut deja livrare, aceasta trebuie oprita sau facut un reverse. + $errorMessage = $objPmReq->objPmNotify->getCrc(); + break; + default: + $errorType = Mobilpay_Payment_Request_Abstract::CONFIRM_ERROR_TYPE_PERMANENT; + $errorCode = Mobilpay_Payment_Request_Abstract::ERROR_CONFIRM_INVALID_ACTION; + $errorMessage = 'mobilpay_refference_action paramaters is invalid'; + break; + } + } catch (Exception $e) { + $this->errorType = Mobilpay_Payment_Request_Abstract::CONFIRM_ERROR_TYPE_TEMPORARY; + $this->errorCode = $e->getCode(); + $this->errorMessage = $e->getMessage(); + } + + } else { + $this->errorType = Mobilpay_Payment_Request_Abstract::CONFIRM_ERROR_TYPE_PERMANENT; + $this->errorCode = Mobilpay_Payment_Request_Abstract::ERROR_CONFIRM_INVALID_POST_PARAMETERS; + $this->errorMessage = 'mobilpay.ro posted invalid parameters'; + } + } else { + $this->errorType = Mobilpay_Payment_Request_Abstract::CONFIRM_ERROR_TYPE_PERMANENT; + $this->errorCode = Mobilpay_Payment_Request_Abstract::ERROR_CONFIRM_INVALID_POST_METHOD; + $this->errorMessage = 'invalid request metod for payment confirmation'; + } + + + if(!empty($objPmReq->orderId) && $objPmReq->objPmNotify->errorCode == 0) { + + + $IpnOrderIdParts = explode('#', $objPmReq->orderId); + $realOrderId = intval($IpnOrderIdParts[0]); + $cart = new Cart($realOrderId); + $customer = new Customer((int)$cart->id_customer); + + //real order id + $order_id = Order::getOrderByCartId($realOrderId); + + + if(intval($order_id)>0) { + $order = new Order(intval($order_id)); + + $history = new OrderHistory(); + $history->id_order = $order_id; + + $history->id_employee = 1; + $carrier = new Carrier(intval($order->id_carrier), intval($order->id_lang)); + $templateVars = array('{followup}' => ($history->id_order_state == _PS_OS_SHIPPING_ AND $order->shipping_number) ? str_replace('@', $order->shipping_number, $carrier->url) : ''); + $history->addWithemail(true, $templateVars); + + }else{ + /** + * Add Order + */ + $result = $this->module->validateOrder( + (int) $cart->id, + (int) Configuration::get('MPCC_OS_'.strtoupper($objPmReq->objPmNotify->action)), + // $total, + floatval($objPmReq->invoice->amount), + $this->module->displayName, + null, + // $mailVars, + array(), + // (int) $currency->id, + null, + false, + $customer->secure_key + ); + } + + + } + + $this->context->smarty->assign([ + 'errorType' => $this->errorType, + 'errorCode' => $this->errorCode, + 'errorMessage' => $this->errorMessage + ]); + } +} \ No newline at end of file diff --git a/1.7.6/mobilpay_cc/en.php b/1.7.7/mobilpay_cc/en.php similarity index 100% rename from 1.7.6/mobilpay_cc/en.php rename to 1.7.7/mobilpay_cc/en.php diff --git a/1.7.6/mobilpay_cc/it.php b/1.7.7/mobilpay_cc/it.php similarity index 100% rename from 1.7.6/mobilpay_cc/it.php rename to 1.7.7/mobilpay_cc/it.php diff --git a/1.7.6/mobilpay_cc/logo.gif b/1.7.7/mobilpay_cc/logo.gif similarity index 100% rename from 1.7.6/mobilpay_cc/logo.gif rename to 1.7.7/mobilpay_cc/logo.gif diff --git a/1.7.6/mobilpay_cc/mobilpay.gif b/1.7.7/mobilpay_cc/mobilpay.gif similarity index 100% rename from 1.7.6/mobilpay_cc/mobilpay.gif rename to 1.7.7/mobilpay_cc/mobilpay.gif diff --git a/1.7.6/mobilpay_cc/mobilpay_cc.php b/1.7.7/mobilpay_cc/mobilpay_cc.php similarity index 64% rename from 1.7.6/mobilpay_cc/mobilpay_cc.php rename to 1.7.7/mobilpay_cc/mobilpay_cc.php index 45f4dfe..c9e82cf 100644 --- a/1.7.6/mobilpay_cc/mobilpay_cc.php +++ b/1.7.7/mobilpay_cc/mobilpay_cc.php @@ -16,16 +16,13 @@ public function __construct() $this->name = 'mobilpay_cc'; $this->tab = 'payments_gateways'; $this->version = '1.0'; - $this->currencies = true; $this->currencies_mode = 'checkbox'; - - parent::__construct(); - $this->page = basename(__FILE__, '.php'); $this->displayName = $this->l('Mobilpay - credit card'); $this->description = $this->l('Accept payments by credit card'); $this->confirmUninstall = $this->l('Are you sure you want to delete your details ?'); + parent::__construct(); } public function install() @@ -33,14 +30,12 @@ public function install() if (!parent::install() OR !Configuration::updateValue('MPCC_SIGNATURE', '') OR !Configuration::updateValue('MPCC_CART_DESCRIPTION', '') - OR !Configuration::updateValue('MPCC_OS_CONFIRMED_PENDING', '') OR !Configuration::updateValue('MPCC_OS_CONFIRMED', '') OR !Configuration::updateValue('MPCC_OS_PAID_PENDING', '') OR !Configuration::updateValue('MPCC_OS_PAID', '') OR !Configuration::updateValue('MPCC_OS_CANCELED', '') OR !Configuration::updateValue('MPCC_OS_CREDIT', '') - OR !Configuration::updateValue('MPCC_TESTMODE', 1) OR !$this->registerHook('paymentOptions') OR !$this->registerHook('paymentReturn') @@ -101,14 +96,12 @@ public function getContent() } Configuration::updateValue('MPCC_SIGNATURE', strval($_POST['MPCC_SIGNATURE'])); Configuration::updateValue('MPCC_CART_DESCRIPTION', strval($_POST['MPCC_CART_DESCRIPTION'])); - Configuration::updateValue('MPCC_OS_CONFIRMED_PENDING', intval($_POST['MPCC_OS_CONFIRMED_PENDING'])); Configuration::updateValue('MPCC_OS_CONFIRMED', intval($_POST['MPCC_OS_CONFIRMED'])); Configuration::updateValue('MPCC_OS_PAID_PENDING', intval($_POST['MPCC_OS_PAID_PENDING'])); Configuration::updateValue('MPCC_OS_PAID', intval($_POST['MPCC_OS_PAID'])); Configuration::updateValue('MPCC_OS_CANCELED', intval($_POST['MPCC_OS_CANCELED'])); Configuration::updateValue('MPCC_OS_CREDIT', intval($_POST['MPCC_OS_CREDIT'])); - Configuration::updateValue('MPCC_TESTMODE', intval($_POST['MPCC_TESTMODE'])); $this->displayConf(); } else { @@ -148,11 +141,15 @@ public function displayErrors() public function displayPayex() { $this->_html .= ' - - ' . $this->l('This module allows you to accept credit card payments by MobilPay.') . ' -
 
'; + + ' . $this->l('This module allows you to accept credit card payments by MobilPay.') . ' +
 
'; } + + /** + * Make Backend Configuration Form + */ public function displayFormSettings() { global $cookie; @@ -168,68 +165,44 @@ public function displayFormSettings() 'MPCC_TESTMODE' )); - $MPCC_SIGNATURE = array_key_exists('MPCC_SIGNATURE', - $_POST) ? $_POST['MPCC_SIGNATURE'] : (array_key_exists('MPCC_SIGNATURE', - $conf) ? $conf['MPCC_SIGNATURE'] : ''); - $MPCC_CART_DESCRIPTION = array_key_exists('MPCC_CART_DESCRIPTION', - $_POST) ? $_POST['MPCC_CART_DESCRIPTION'] : (array_key_exists('MPCC_CART_DESCRIPTION', - $conf) ? $conf['MPCC_CART_DESCRIPTION'] : ''); - $MPCC_OS_CONFIRMED_PENDING = array_key_exists('MPCC_OS_CONFIRMED_PENDING', - $_POST) ? $_POST['MPCC_OS_CONFIRMED_PENDING'] : (array_key_exists('MPCC_OS_CONFIRMED_PENDING', - $conf) ? $conf['MPCC_OS_CONFIRMED_PENDING'] : ''); - $MPCC_OS_CONFIRMED = array_key_exists('MPCC_OS_CONFIRMED', - $_POST) ? $_POST['MPCC_OS_CONFIRMED'] : (array_key_exists('MPCC_OS_CONFIRMED', - $conf) ? $conf['MPCC_OS_CONFIRMED'] : ''); - $MPCC_OS_PAID_PENDING = array_key_exists('MPCC_OS_PAID_PENDING', - $_POST) ? $_POST['MPCC_OS_PAID_PENDING'] : (array_key_exists('MPCC_OS_PAID_PENDING', - $conf) ? $conf['MPCC_OS_PAID_PENDING'] : ''); - $MPCC_OS_PAID = array_key_exists('MPCC_OS_PAID', - $_POST) ? $_POST['MPCC_OS_PAID'] : (array_key_exists('MPCC_OS_PAID', $conf) ? $conf['MPCC_OS_PAID'] : ''); - $MPCC_OS_CANCELED = array_key_exists('MPCC_OS_CANCELED', - $_POST) ? $_POST['MPCC_OS_CANCELED'] : (array_key_exists('MPCC_OS_CANCELED', - $conf) ? $conf['MPCC_OS_CANCELED'] : ''); - $MPCC_OS_CREDIT = array_key_exists('MPCC_OS_CREDIT', - $_POST) ? $_POST['MPCC_OS_CREDIT'] : (array_key_exists('MPCC_OS_CREDIT', - $conf) ? $conf['MPCC_OS_CREDIT'] : ''); - $MPCC_TESTMODE = array_key_exists('MPCC_TESTMODE', - $_POST) ? $_POST['MPCC_TESTMODE'] : (array_key_exists('MPCC_TESTMODE', - $conf) ? $conf['MPCC_TESTMODE'] : ''); + $MPCC_SIGNATURE = array_key_exists('MPCC_SIGNATURE',$_POST) ? $_POST['MPCC_SIGNATURE'] : (array_key_exists('MPCC_SIGNATURE', $conf) ? $conf['MPCC_SIGNATURE'] : ''); + $MPCC_CART_DESCRIPTION = array_key_exists('MPCC_CART_DESCRIPTION', $_POST) ? $_POST['MPCC_CART_DESCRIPTION'] : (array_key_exists('MPCC_CART_DESCRIPTION', $conf) ? $conf['MPCC_CART_DESCRIPTION'] : ''); + $MPCC_OS_CONFIRMED_PENDING = array_key_exists('MPCC_OS_CONFIRMED_PENDING', $_POST) ? $_POST['MPCC_OS_CONFIRMED_PENDING'] : (array_key_exists('MPCC_OS_CONFIRMED_PENDING', $conf) ? $conf['MPCC_OS_CONFIRMED_PENDING'] : ''); + $MPCC_OS_CONFIRMED = array_key_exists('MPCC_OS_CONFIRMED', $_POST) ? $_POST['MPCC_OS_CONFIRMED'] : (array_key_exists('MPCC_OS_CONFIRMED', $conf) ? $conf['MPCC_OS_CONFIRMED'] : ''); + $MPCC_OS_PAID_PENDING = array_key_exists('MPCC_OS_PAID_PENDING', $_POST) ? $_POST['MPCC_OS_PAID_PENDING'] : (array_key_exists('MPCC_OS_PAID_PENDING', $conf) ? $conf['MPCC_OS_PAID_PENDING'] : ''); + $MPCC_OS_PAID = array_key_exists('MPCC_OS_PAID', $_POST) ? $_POST['MPCC_OS_PAID'] : (array_key_exists('MPCC_OS_PAID', $conf) ? $conf['MPCC_OS_PAID'] : ''); + $MPCC_OS_CANCELED = array_key_exists('MPCC_OS_CANCELED', $_POST) ? $_POST['MPCC_OS_CANCELED'] : (array_key_exists('MPCC_OS_CANCELED', $conf) ? $conf['MPCC_OS_CANCELED'] : ''); + $MPCC_OS_CREDIT = array_key_exists('MPCC_OS_CREDIT', $_POST) ? $_POST['MPCC_OS_CREDIT'] : (array_key_exists('MPCC_OS_CREDIT', $conf) ? $conf['MPCC_OS_CREDIT'] : ''); + $MPCC_TESTMODE = array_key_exists('MPCC_TESTMODE', $_POST) ? $_POST['MPCC_TESTMODE'] : (array_key_exists('MPCC_TESTMODE', $conf) ? $conf['MPCC_TESTMODE'] : ''); $this->_html .= ' -
+
' . $this->l('Settings') . ' - - -
- -

' . $this->l('MobilPay Account Signature') . '

-
 
- - - - -
- -

' . $this->l('MobilPay Private Key') . '

-
 
- - -
- -

' . $this->l('MobilPay Public Key') . '

-
 
- - - - - -
- -

' . $this->l('Description appears on mobilpay website') . '

-
 
+ +
+ +

' . $this->l('MobilPay Account Signature') . '

+
 
+ + +
+ +

' . $this->l('MobilPay Private Key') . '

+
 
+ + +
+ +

' . $this->l('MobilPay Public Key') . '

+
 
+ + +
+ +

' . $this->l('Description appears on mobilpay website') . '

+
 
@@ -241,102 +214,125 @@ public function displayFormSettings() $this->_html .= ' - -
'; - $this->_html .= ' '; + $currentStateTab = $MPCC_OS_CONFIRMED_PENDING; - foreach ($states AS $state) { $this->_html .= ''; } + + $this->_html .= ''; + $this->_html .= ' - '; - $this->_html .= '

' . $this->l('Transaction is pending verification regarding fraud risk. Money are already taken from the client\'s credit card') . '

-
 
'; +

' . + $this->l('Transaction is pending verification regarding fraud risk. Money are already taken from the client\'s credit card') . + '

+
 
'; $this->_html .= ' - -
'; - $this->_html .= ' '; $currentStateTab = $MPCC_OS_CONFIRMED; foreach ($states AS $state) { $this->_html .= ''; } - $this->_html .= ' - '; + + $this->_html .= ''; $this->_html .= '
 
'; - $this->_html .= ' - -
'; - $this->_html .= ' '; $currentStateTab = $MPCC_OS_PAID_PENDING; foreach ($states AS $state) { $this->_html .= ''; } - $this->_html .= ' - '; + + $this->_html .= ''; $this->_html .= '
 
'; - $this->_html .= ' - -
'; - $this->_html .= ' '; $currentStateTab = $MPCC_OS_PAID; foreach ($states AS $state) { $this->_html .= ''; } - $this->_html .= ' - '; + + $this->_html .= ''; $this->_html .= '
 
'; - $this->_html .= ' - -
'; - $this->_html .= ' '; $currentStateTab = $MPCC_OS_CANCELED; foreach ($states AS $state) { $this->_html .= ''; } - $this->_html .= ' - '; + + $this->_html .= ''; $this->_html .= '
 
'; - $this->_html .= ' - -
'; - $this->_html .= ' '; $currentStateTab = $MPCC_OS_CREDIT; foreach ($states AS $state) { $this->_html .= ''; } - $this->_html .= ' - '; - $this->_html .= '
 
'; + $this->_html .= ''; + $this->_html .= '
 
'; - $this->_html .= ' -
-
-


'; + $this->_html .= '
+
+ +
+ + +

'; } + /** + * Get Module actual path + */ public function getPath() { - return (Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://') . htmlspecialchars($_SERVER['HTTP_HOST'], - ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__ . 'modules/' . $this->name . '/'; + if(isset($_SERVER['HTTPS'])){ + $protocol = ($_SERVER['HTTPS'] && $_SERVER['HTTPS'] != "off") ? "https" : "http"; + } + else{ + $protocol = 'http'; + } + return $protocol . "://" . $_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']; + } + + /** + * Check Currency base on Cart + */ public function checkCurrency($cart) { $currency_order = new Currency((int)($cart->id_currency)); @@ -352,15 +348,24 @@ public function checkCurrency($cart) return false; } + /** + * Hook Payment Return + * NEED TO CHECK , !!!!! + */ public function hookPaymentReturn($params) - { + { if (!$this->active) { return; } return $this->display(__FILE__, 'confirmation.tpl'); } - function validateOrder( + /** + * Validate ORDER and register the ORDER + * Base on CART Information + * Looks Not need to be rewrite !!!! + */ + /*function validateOrder( $id_cart, $id_order_state, $amount_paid, @@ -376,31 +381,28 @@ function validateOrder( return; } - parent::validateOrder($id_cart, $id_order_state, $amount_paid, $payment_method, $message, $extra_vars, - $currency_special, true, $secure_key, $shop); - - /*Tools::redirect( - $this->context->link->getPagelink( - 'order-confirmation.php', - null, - null, - array( - 'id_cart' => (int)$this->context->cart->id, - 'id_module' => (int)$this->id, - 'id_order' => (int)$this->currentOrder, - 'key' => $this->context->customer->secure_key - ) - ) - );*/ - } - + + + parent::validateOrder($id_cart, $id_order_state, $amount_paid, $payment_method, $message, $extra_vars, $currency_special, true, $secure_key, $shop); + // Module::validateOrder($id_cart, $id_order_state, $amount_paid, $payment_method, $message, $extra_vars, $currency_special, true, $secure_key, $shop); + }*/ + + + /** + * The Main Hook + * @param $params + * @return $payment_options + */ public function hookPaymentOptions($params) { if (!$this->active) { return; } - //Tools::dieObject($params); + $this->setLogObj("Step #1 -> Mobilpay_CC -> hookPaymentOptions "); + //$this->setLogObj($params , " PARAMS ", true); + // Tools::dieObject($params); + $customer = new Customer(intval($params['cart']->id_customer)); $currency = new Currency(intval($params['cart']->id_currency)); @@ -410,41 +412,40 @@ public function hookPaymentOptions($params) $billing = new Address(intval($params['cart']->id_address_invoice)); $delivery = new Address(intval($params['cart']->id_address_delivery)); + + //include the main library require_once dirname(__FILE__) . '/Mobilpay/Payment/Request/Abstract.php'; require_once dirname(__FILE__) . '/Mobilpay/Payment/Request/Card.php'; require_once dirname(__FILE__) . '/Mobilpay/Payment/Invoice.php'; require_once dirname(__FILE__) . '/Mobilpay/Payment/Address.php'; - $paymentUrl = (Configuration::get('MPCC_TESTMODE') == 1) ? 'http://sandboxsecure.mobilpay.ro/' : 'https://secure.mobilpay.ro/'; + $paymentUrl = (Configuration::get('MPCC_TESTMODE') == 1) ? 'https://sandboxsecure.mobilpay.ro/' : 'https://secure.mobilpay.ro/'; $x509FilePath = dirname(__FILE__) . '/Mobilpay/certificates/public.cer'; try { $objPmReqCard = new Mobilpay_Payment_Request_Card(); - $objPmReqCard->signature = Configuration::get('MPCC_SIGNATURE'); $objPmReqCard->orderId = intval($params['cart']->id) . '#' . time(); - $objPmReqCard->returnUrl = 'http://' . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, - 'UTF-8') . __PS_BASE_URI__ . 'index.php?controller=order-confirmation?key=' . $customer->secure_key . '&id_cart=' . intval($params['cart']->id) . '&id_module=' . intval($this->id); - $objPmReqCard->confirmUrl = $this->getPath() . 'validation.php?key=' . $customer->secure_key . '&id_cart=' . intval($params['cart']->id) . '&id_currency=' . intval($currency->id) . '&id_module=' . intval($this->id); - $objPmReqCard->cancelUrl = 'http://' . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, - 'UTF-8') . __PS_BASE_URI__ . 'index.php'; - + $objPmReqCard->returnUrl = (Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://') . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT,'UTF-8') . __PS_BASE_URI__ . 'index.php?controller=order-confirmation?key=' . $customer->secure_key . '&id_cart=' . intval($params['cart']->id) . '&id_module=' . intval($this->id); + + + + /** + * Confirm URL + */ + //$objPmReqCard->confirmUrl = $this->getPath() . 'validation.php?key=' . $customer->secure_key . '&id_cart=' . intval($params['cart']->id) . '&id_currency=' . intval($currency->id) . '&id_module=' . intval($this->id); + $objPmReqCard->confirmUrl = (Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://') . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT,'UTF-8') . __PS_BASE_URI__ .'module/mobilpay_cc/betavalidation'; + + + $objPmReqCard->cancelUrl = 'http://' . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT,'UTF-8') . __PS_BASE_URI__ . 'index.php'; $objPmReqCard->invoice = new Mobilpay_Payment_Invoice(); // $objPmReqCard->invoice->currency = 'RON'; /*$currency_module->iso_code;*/ $objPmReqCard->invoice->currency = $currency->iso_code; -/* - if ($currency_default->iso_code == 'RON' && $currency->iso_code != 'RON') { - //convert prices manually - $objPmReqCard->invoice->amount = round($params['cart']->getOrderTotal(true) * 1 / $currency->conversion_rate, 2); - } else { - $objPmReqCard->invoice->amount = Tools::convertPrice($params['cart']->getOrderTotal(true), $currency); - } -*/ $objPmReqCard->invoice->amount = $params['cart']->getOrderTotal(true, 3); if (Configuration::get('MPCC_CART_DESCRIPTION') != '') { @@ -458,19 +459,24 @@ public function hookPaymentOptions($params) } else { $billingAddress->type = 'person'; } + + /** + * Billing Address + */ $billingAddress->firstName = $billing->firstname; $billingAddress->lastName = $billing->lastname; - $billingAddress->country = $billing->country; - $billingAddress->city = $billing->city; $billingAddress->zipCode = $billing->postcode; $billingAddress->address = $billing->address1 . ' ' . $billing->address2; $billingAddress->email = $customer->email; - $billingAddress->mobilePhone = $billing->phone_mobile; - + // $billingAddress->mobilePhone = $billing->phone_mobile; + $billingAddress->mobilePhone = ($billing->phone) ? $billing->phone : $billing->phone_mobile; $objPmReqCard->invoice->setBillingAddress($billingAddress); - + + /** + * Delivery Address + */ $deliveryAddress = new Mobilpay_Payment_Address(); if (!empty($delivery->company)) { $deliveryAddress->type = 'company'; @@ -479,15 +485,12 @@ public function hookPaymentOptions($params) } $deliveryAddress->firstName = $delivery->firstname; $deliveryAddress->lastName = $delivery->lastname; - $deliveryAddress->country = $delivery->country; - $deliveryAddress->city = $delivery->city; $deliveryAddress->zipCode = $delivery->postcode; $deliveryAddress->address = $delivery->address1 . ' ' . $delivery->address2; $deliveryAddress->email = $customer->email; $deliveryAddress->mobilePhone = $delivery->phone_mobile; - $objPmReqCard->invoice->setShippingAddress($deliveryAddress); $objPmReqCard->encrypt($x509FilePath); @@ -500,22 +503,10 @@ public function hookPaymentOptions($params) //return $this->display(__FILE__, 'validation.tpl'); } - - /*if (!isset($e) || !($e instanceof Exception)) { - - $this->smarty->assign(array( - 'data' => $objPmReqCard->getEncData(), - 'env_key' => $objPmReqCard->getEnvKey(), - 'paymentUrl' => $paymentUrl - )); - } else { - $error = $e->getMessage(); - $errors = explode("\n", $error);//just first line - $this->smarty->assign(array('errors' => $errors)); - return; - //return $this->display(__FILE__, 'validation.tpl'); - }*/ - + /** + * Redirecting to payment page + * Incloding Encrypted Data + */ $this->smarty->assign(array( 'data' => $objPmReqCard->getEncData(), 'env_key' => $objPmReqCard->getEnvKey(), @@ -533,4 +524,23 @@ public function hookPaymentOptions($params) return [$payment_options]; } + + + + /** + * Set Log #1 + */ + public function setLog($str) + { + // + } + + /** + * Set Log #2 + */ + public function setLogObj($obj, $justName = null, $seperator = false) + { + // + } + } diff --git a/1.7.6/mobilpay_cc/ro.php b/1.7.7/mobilpay_cc/ro.php similarity index 100% rename from 1.7.6/mobilpay_cc/ro.php rename to 1.7.7/mobilpay_cc/ro.php diff --git a/1.7.7/mobilpay_cc/validation.php b/1.7.7/mobilpay_cc/validation.php new file mode 100644 index 0000000..da0b125 --- /dev/null +++ b/1.7.7/mobilpay_cc/validation.php @@ -0,0 +1,212 @@ + Step #2", null, false); + +if (strcasecmp($_SERVER['REQUEST_METHOD'], 'post') == 0) +{ + if(isset($_POST['env_key']) && isset($_POST['data'])) + { + global $kernel; + if(!$kernel){ + require_once _PS_ROOT_DIR_.'/app/AppKernel.php'; + $kernel = new \AppKernel('prod', false); + $kernel->boot(); + } + + #calea catre cheia privata + #cheia privata este generata de mobilpay, accesibil in Admin -> Conturi de comerciant -> Detalii -> Setari securitate + $privateKeyFilePath = dirname(__FILE__).'/Mobilpay/certificates/private.key'; + + try + { + $objPmReq = Mobilpay_Payment_Request_Abstract::factoryFromEncrypted($_POST['env_key'], $_POST['data'], $privateKeyFilePath); + + switch($objPmReq->objPmNotify->action) + { + #orice action este insotit de un cod de eroare si de un mesaj de eroare. Acestea pot fi citite folosind $cod_eroare = $objPmReq->objPmNotify->errorCode; respectiv $mesaj_eroare = $objPmReq->objPmNotify->errorMessage; + #pentru a identifica ID-ul comenzii pentru care primim rezultatul platii folosim $id_comanda = $objPmReq->orderId; + case 'confirmed': + #cand action este confirmed avem certitudinea ca banii au plecat din contul posesorului de card si facem update al starii comenzii si livrarea produsului + $errorMessage = $objPmReq->objPmNotify->getCrc(); + break; + case 'confirmed_pending': + #cand action este confirmed_pending inseamna ca tranzactia este in curs de verificare antifrauda. Nu facem livrare/expediere. In urma trecerii de aceasta verificare se va primi o noua notificare pentru o actiune de confirmare sau anulare. + $errorMessage = $objPmReq->objPmNotify->getCrc(); + break; + case 'paid_pending': + #cand action este paid_pending inseamna ca tranzactia este in curs de verificare. Nu facem livrare/expediere. In urma trecerii de aceasta verificare se va primi o noua notificare pentru o actiune de confirmare sau anulare. + $errorMessage = $objPmReq->objPmNotify->getCrc(); + break; + case 'paid': + #cand action este paid inseamna ca tranzactia este in curs de procesare. Nu facem livrare/expediere. In urma trecerii de aceasta procesare se va primi o noua notificare pentru o actiune de confirmare sau anulare. + $errorMessage = $objPmReq->objPmNotify->getCrc(); + break; + case 'canceled': + #cand action este canceled inseamna ca tranzactia este anulata. Nu facem livrare/expediere. + $errorMessage = $objPmReq->objPmNotify->getCrc(); + break; + case 'credit': + #cand action este credit inseamna ca banii sunt returnati posesorului de card. Daca s-a facut deja livrare, aceasta trebuie oprita sau facut un reverse. + $errorMessage = $objPmReq->objPmNotify->getCrc(); + break; + default: + $errorType = Mobilpay_Payment_Request_Abstract::CONFIRM_ERROR_TYPE_PERMANENT; + $errorCode = Mobilpay_Payment_Request_Abstract::ERROR_CONFIRM_INVALID_ACTION; + $errorMessage = 'mobilpay_refference_action paramaters is invalid'; + break; + } + } + catch(Exception $e) + { + $errorType = Mobilpay_Payment_Request_Abstract::CONFIRM_ERROR_TYPE_TEMPORARY; + $errorCode = $e->getCode(); + $errorMessage = $e->getMessage(); + } + Mobilpay_cc::setLogObj( "IPN -> Data Posted to IPN", null, false); + Mobilpay_cc::setLogObj( " - IPN -> Action ".$objPmReq->objPmNotify->action, null, false); + // Mobilpay_cc::setLogObj( " - IPN -> MESSAGE : ".$errorMessage, null, false); + // Mobilpay_cc::setLogObj( null , null, false); + } + else + { + $errorType = Mobilpay_Payment_Request_Abstract::CONFIRM_ERROR_TYPE_PERMANENT; + $errorCode = Mobilpay_Payment_Request_Abstract::ERROR_CONFIRM_INVALID_POST_PARAMETERS; + $errorMessage = 'mobilpay.ro posted invalid parameters'; + } +} +else +{ + $errorType = Mobilpay_Payment_Request_Abstract::CONFIRM_ERROR_TYPE_PERMANENT; + $errorCode = Mobilpay_Payment_Request_Abstract::ERROR_CONFIRM_INVALID_POST_METHOD; + $errorMessage = 'invalid request metod for payment confirmation'; +} + + +$Mobilpay_cc = new Mobilpay_cc(); + +// $Mobilpay_cc->setLogObj( "IPN -> Create NEW OBJ -> Mobilpay_cc ", null, false); +// $Mobilpay_cc->setLogObj( "IPN -> objPmReq->orderId : ".$objPmReq->orderId, null, false); +// $Mobilpay_cc->setLogObj( "IPN -> objPmReq->objPmNotify->errorCode ".$objPmReq->objPmNotify->errorCode, null, false); +// $Mobilpay_cc->setLogObj( "-------------------------------------", null, false); + +if(!empty($objPmReq->orderId) && $objPmReq->objPmNotify->errorCode == 0) { + + Mobilpay_cc::setLogObj( "IPN -> objOrderID -> $objPmReq->orderId", null, false); + + $orderIdParts = explode('#', $objPmReq->orderId); + $realOrderId = intval($orderIdParts[0]); + $cart = new Cart($realOrderId); + $customer = new Customer((int)$cart->id_customer); + + Mobilpay_cc::setLogObj( "---- IPN -> objPmReq->orderId ", null, false); + Mobilpay_cc::setLogObj( "---- IPN -> realOrderId -> ".$realOrderId, null, false); + + // $Mobilpay_cc->setLogObj( $cart->date_upd, "IPN -> CART - date_upd : ", true); + // $Mobilpay_cc->setLogObj( $cart->_products, "IPN -> Products Value : ", true); + // $Mobilpay_cc->setLogObj( $cart, "IPN -> RealCardID : ".$realOrderId, true); + // $Mobilpay_cc->setLogObj( $customer, "IPN -> CUSTOMER " , true); + + //real order id + $order_id = Order::getOrderByCartId($realOrderId); + Mobilpay_cc::setLogObj( "---- IPN -> getOrderByCartId -> ".$realOrderId, null, false); + + if(intval($order_id)>0) { + Mobilpay_cc::setLogObj( "IPN -> Order Id is Not ZERO -> order_id : ".$order_id, null, false); + $order = new Order(intval($order_id)); + + $history = new OrderHistory(); + $history->id_order = $order_id; + // $history->changeIdOrderState(intval(Configuration::get('MPCC_OS_'.strtoupper($objPmReq->objPmNotify->action))), intval($order_id)); + + $history->id_employee = 1; + $carrier = new Carrier(intval($order->id_carrier), intval($order->id_lang)); + $templateVars = array('{followup}' => ($history->id_order_state == _PS_OS_SHIPPING_ AND $order->shipping_number) ? str_replace('@', $order->shipping_number, $carrier->url) : ''); + $history->addWithemail(true, $templateVars); + } + else { + Mobilpay_cc::setLogObj( "IPN -> NULL -> Before Order Register . ", null, false); + /** + * CALL NEW CONTROLLER HERE + */ + // $alfaLink = Context::getContext()->link->getModuleLink('mobilpay_cc', 'alfavalidation', array()); + // header("Location: http://navid.ctbhub.com/en/module/mobilpay_cc/alfavalidation/"); // Error 302 + // die(); + /** + * Another Method - Start + */ + // $postdata = http_build_query( + // array( + // 'var1' => 'some content', + // 'var2' => 'doh' + // ) + // ); + + // $opts = array('http' => + // array( + // 'method' => 'POST', + // 'header' => 'Content-Type: application/x-www-form-urlencoded', + // 'content' => $postdata + // ) + // ); + + // $context = stream_context_create($opts); + // $result = file_get_contents($alfaLink, false, $context); + /** + * Another Method - END + */ + + // $controller = $Mobilpay_cc->getModuleFrontControllerInstance(); + + //create the order + $Mobilpay_cc->validateOrder($objPmReq->orderId, intval(Configuration::get('MPCC_OS_'.strtoupper($objPmReq->objPmNotify->action))), floatval($objPmReq->invoice->amount), $Mobilpay_cc->displayName, NULL, array(), NULL, false, $customer->secure_key); + //$Mobilpay_cc->validateOrder($realOrderId, intval(Configuration::get('MPCC_OS_'.strtoupper($objPmReq->objPmNotify->action))), floatval($objPmReq->invoice->amount), $Mobilpay_cc->displayName, NULL, array(), NULL, false, $customer->secure_key); + + } +} + +/* +if (headers_sent()) { + die("Redirect failed. Please click on this link: "); +} +else{ + ?> + + + + + + + \n"; +if($errorCode == 0) +{ + echo "{$errorMessage}"; +} +else +{ + echo "{$errorMessage}"; +} diff --git a/1.7.6/mobilpay_cc/validation.tpl b/1.7.7/mobilpay_cc/validation.tpl similarity index 100% rename from 1.7.6/mobilpay_cc/validation.tpl rename to 1.7.7/mobilpay_cc/validation.tpl diff --git a/1.7.7/mobilpay_cc/views/templates/front/alfavalidation.tpl b/1.7.7/mobilpay_cc/views/templates/front/alfavalidation.tpl new file mode 100644 index 0000000..7fd2190 --- /dev/null +++ b/1.7.7/mobilpay_cc/views/templates/front/alfavalidation.tpl @@ -0,0 +1,2 @@ + +{$errorMessage} \ No newline at end of file diff --git a/1.7.6/mobilpay_cc/views/templates/front/form.tpl b/1.7.7/mobilpay_cc/views/templates/front/form.tpl similarity index 100% rename from 1.7.6/mobilpay_cc/views/templates/front/form.tpl rename to 1.7.7/mobilpay_cc/views/templates/front/form.tpl diff --git a/1.7.6/mobilpay_cc/views/templates/front/option.tpl b/1.7.7/mobilpay_cc/views/templates/front/option.tpl similarity index 100% rename from 1.7.6/mobilpay_cc/views/templates/front/option.tpl rename to 1.7.7/mobilpay_cc/views/templates/front/option.tpl