Ejemplo n.º 1
0
 public function validation()
 {
     # LOG
     $message = '######################################' . "\r\n";
     $message .= '# Date Début Validation - ' . date("d/m/Y H:i:s") . "\r\n";
     $message .= '#### Module actif - ' . ($this->active ? 'TRUE' : 'FALSE') . "\r\n";
     $message .= '#### Variable POST :' . "\r\n";
     $message .= print_r($_POST, true);
     $message .= "\r\n";
     # ---
     $this->HipayLog($message);
     if (!$this->active) {
         return;
     }
     if (!array_key_exists('xml', $_POST)) {
         return;
     }
     if (_PS_MAGIC_QUOTES_GPC_) {
         $_POST['xml'] = stripslashes($_POST['xml']);
     }
     require_once dirname(__FILE__) . '/mapi/mapi_package.php';
     # LOG
     $this->HipayLog('#### Début HIPAY_MAPI_COMM_XML::analyzeNotificationXML' . "\r\n");
     # ---
     if (HIPAY_MAPI_COMM_XML::analyzeNotificationXML($_POST['xml'], $operation, $status, $date, $time, $transid, $amount, $currency, $id_cart, $data) === false) {
         file_put_contents('logs' . Configuration::get('HIPAY_UNIQID') . '.txt', '[' . date('Y-m-d H:i:s') . '] Analysis error: ' . htmlentities($_POST['xml']) . "\n", FILE_APPEND);
         return false;
     }
     # LOG
     $message = '#### Fin HIPAY_MAPI_COMM_XML::analyzeNotificationXML' . "\r\n";
     $message .= '#### Version Prestashop : ' . _PS_VERSION_;
     # ---
     $this->HipayLog($message);
     if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) {
         # LOG
         $this->HipayLog('#### ID Panier : ' . (int) $id_cart . "\r\n");
         # ---
         Context::getContext()->cart = new Cart((int) $id_cart);
     }
     $cart = new Cart((int) $id_cart);
     # LOG
     $message = '#### TOKEN : ' . Tools::getValue('token') . "\r\n";
     $message .= '#### SECURE KEY : ' . $cart->secure_key . "\r\n";
     $message .= '#### HIPAY SALT : ' . Configuration::get('HIPAY_SALT') . "\r\n";
     $message .= '#### CLE ENCRYPTE : ' . Tools::encrypt($cart->id . $cart->secure_key . Configuration::get('HIPAY_SALT')) . "\r\n";
     # ---
     $this->HipayLog($message);
     if (Tools::encrypt($cart->id . $cart->secure_key . Configuration::get('HIPAY_SALT')) != Tools::getValue('token')) {
         # LOG
         $this->HipayLog('#### TOKEN = CLE : NOK' . "\r\n");
         # ---
         file_put_contents('logs' . Configuration::get('HIPAY_UNIQID') . '.txt', '[' . date('Y-m-d H:i:s') . '] Token error: ' . htmlentities($_POST['xml']) . "\n", FILE_APPEND);
     } else {
         # LOG
         $message = '#### Opération : ' . trim($operation) . "\r\n";
         $message .= '#### Status : ' . trim(strtolower($status)) . "\r\n";
         # ---
         $this->HipayLog($message);
         if (trim($operation) == 'authorization' && trim(strtolower($status)) == 'waiting') {
             // Authorization WAITING
             $orderMessage = $operation . ": " . $status . "\ndate: " . $date . " " . $time . "\ntransaction: " . $transid . "\namount: " . (double) $amount . " " . $currency . "\nid_cart: " . (int) $id_cart;
             //$this->_createAuthorizationOrderState();
             $this->validateOrder((int) $id_cart, Configuration::get('HIPAY_WAITINGPAYMENT_OS'), (double) $amount, $this->displayName, $orderMessage, array(), NULL, false, $cart->secure_key);
             # LOG
             $this->HipayLog('######## AW - création Commande / status : ' . (int) Configuration::get('HIPAY_WAITINGPAYMENT_OS') . "\r\n");
             # ---
         } else {
             if (trim($operation) == 'authorization' && trim(strtolower($status)) == 'ok') {
                 // vérification si commande existante
                 $id_order = Order::getOrderByCartId((int) $id_cart);
                 # LOG
                 $this->HipayLog('######## AOK - ID Commande : ' . ($id_order ? $id_order : 'Pas de commande') . "\r\n");
                 # ---
                 if ($id_order !== false) {
                     // change statut si commande en attente de paiement
                     $order = new Order((int) $id_order);
                     if ((int) $order->getCurrentState() == (int) Configuration::get('HIPAY_WAITINGPAYMENT_OS')) {
                         // on affecte à la commande au statut paiement autorisé par HiPay
                         $statut_id = Configuration::get('HIPAY_AUTHORIZATION_OS');
                         $order_history = new OrderHistory();
                         $order_history->id_order = $id_order;
                         $order_history->changeIdOrderState($statut_id, $id_order);
                         $order_history->addWithemail();
                         # LOG
                         $this->HipayLog('######## AOK - Historique Commande / Change status : ' . (int) Configuration::get('HIPAY_AUTHORIZATION_OS') . "\r\n");
                         # ---
                     }
                 } else {
                     // on revérifie si la commande n'existe pas au cas où la capture soit arrivée avant
                     // sinon on ne fait rien
                     $id_order = Order::getOrderByCartId((int) $id_cart);
                     if ($id_order === false) {
                         // Authorization OK
                         $orderMessage = $operation . ": " . $status . "\ndate: " . $date . " " . $time . "\ntransaction: " . $transid . "\namount: " . (double) $amount . " " . $currency . "\nid_cart: " . (int) $id_cart;
                         //$this->_createAuthorizationOrderState();
                         $this->validateOrder((int) $id_cart, Configuration::get('HIPAY_AUTHORIZATION_OS'), (double) $amount, $this->displayName, $orderMessage, array(), NULL, false, $cart->secure_key);
                         # LOG
                         $this->HipayLog('######## AOK - création Commande / status : ' . (int) Configuration::get('HIPAY_AUTHORIZATION_OS') . "\r\n");
                         # ---
                     }
                 }
             } else {
                 if (trim($operation) == 'capture' && trim(strtolower($status)) == 'ok') {
                     // Capture OK
                     $orderMessage = $operation . ": " . $status . "\ndate: " . $date . " " . $time . "\ntransaction: " . $transid . "\namount: " . (double) $amount . " " . $currency . "\nid_cart: " . (int) $id_cart;
                     $id_order = Order::getOrderByCartId((int) $id_cart);
                     # LOG
                     $this->HipayLog('######## C*K - ID Commande : ' . ($id_order ? $id_order : 'Pas de commande') . "\r\n");
                     # ---
                     if ($id_order !== false) {
                         # LOG
                         $this->HipayLog('######## C*K - id_order existant' . "\r\n");
                         # ---
                         $order = new Order((int) $id_order);
                         # LOG
                         $this->HipayLog('######## C*K - objet order loadé' . "\r\n");
                         # ---
                         // si la commande est au statut Autorisation ok ou en attente de paiement
                         // on change le statut en paiement accepté
                         if ((int) $order->getCurrentState() == (int) Configuration::get('HIPAY_AUTHORIZATION_OS') || (int) $order->getCurrentState() == (int) Configuration::get('HIPAY_WAITINGPAYMENT_OS')) {
                             $statut_id = Configuration::get('PS_OS_PAYMENT');
                             $order_history = new OrderHistory();
                             $order_history->id_order = $id_order;
                             $order_history->changeIdOrderState($statut_id, $id_order);
                             $order_history->addWithemail();
                             # LOG
                             $this->HipayLog('######## C*K - Historique Commande / Change status : ' . (int) Configuration::get('PS_OS_PAYMENT') . "\r\n");
                             # ---
                         }
                     } else {
                         $this->validateOrder((int) $id_cart, Configuration::get('PS_OS_PAYMENT'), (double) $amount, $this->displayName, $orderMessage, array(), NULL, false, $cart->secure_key);
                         # LOG
                         $this->HipayLog('######## C*K - création Commande / status : ' . (int) Configuration::get('PS_OS_PAYMENT') . "\r\n");
                         # ---
                     }
                     // Commande que prestashop lance mais n'a aucune incidence dans le module...
                     // Ajouté en commentaire
                     // Configuration::updateValue('HIPAY_CONFIGURATION_OK', true);
                 } else {
                     if (trim($operation) == 'capture' && trim(strtolower($status)) == 'nok') {
                         // Capture NOK
                         $id_order = Order::getOrderByCartId((int) $id_cart);
                         # LOG
                         $this->HipayLog('######## CNOK - ID Commande : ' . ($id_order ? $id_order : 'Pas de commande') . "\r\n");
                         # ---
                         if ($id_order !== false) {
                             $order = new Order((int) $id_order);
                             if ((int) $order->getCurrentState() == (int) Configuration::get('HIPAY_AUTHORIZATION_OS')) {
                                 $statut_id = Configuration::get('PS_OS_ERROR');
                                 $order_history = new OrderHistory();
                                 $order_history->id_order = $id_order;
                                 $order_history->changeIdOrderState($statut_id, $id_order);
                                 $order_history->addWithemail();
                                 # LOG
                                 $this->HipayLog('######## CNOK - Historique Commande / Change status : ' . (int) Configuration::get('PS_OS_ERROR') . "\r\n");
                                 # ---
                             }
                         }
                     } elseif (trim($operation) == 'refund' and trim(strtolower($status)) == 'ok') {
                         /* Paiement remboursé sur Hipay */
                         if (!($id_order = Order::getOrderByCartId((int) $id_cart))) {
                             die(Tools::displayError());
                         }
                         $order = new Order((int) $id_order);
                         if (!$order->valid or $order->getCurrentState() === Configuration::get('PS_OS_REFUND')) {
                             die(Tools::displayError());
                         }
                         $statut_id = Configuration::get('PS_OS_REFUND');
                         $order_history = new OrderHistory();
                         $order_history->id_order = $id_order;
                         $order_history->changeIdOrderState($statut_id, $id_order);
                         $order_history->addWithemail();
                         # LOG
                         ${$this}->HipayLog('######## ROK - Historique Commande / Change status : ' . (int) Configuration::get('PS_OS_REFUND') . "\r\n");
                         # ---
                     }
                 }
             }
         }
     }
     #
     # Patch LOG Pour les erreurs 500
     #
     $message = '# Date Fin Validation - ' . date("d/m/Y H:i:s") . "\r\n";
     $message .= '######################################' . "\r\n";
     $this->HipayLog($message);
     # ---------------------------------------------------------
     return true;
 }
Ejemplo n.º 2
0
 public function validation()
 {
     if (!$this->active) {
         return;
     }
     if (!array_key_exists('xml', $_POST)) {
         return;
     }
     if (_PS_MAGIC_QUOTES_GPC_) {
         $_POST['xml'] = stripslashes($_POST['xml']);
     }
     require_once dirname(__FILE__) . '/mapi/mapi_package.php';
     if (HIPAY_MAPI_COMM_XML::analyzeNotificationXML($_POST['xml'], $operation, $status, $date, $time, $transid, $amount, $currency, $id_cart, $data) === false) {
         file_put_contents('logs' . Configuration::get('HIPAY_UNIQID') . '.txt', '[' . date('Y-m-d H:i:s') . '] Analysis error: ' . htmlentities($_POST['xml']) . "\n", FILE_APPEND);
         return false;
     }
     if (_PS_VERSION_ >= 1.5) {
         Context::getContext()->cart = new Cart((int) $id_cart);
     }
     $cart = new Cart((int) $id_cart);
     if (Tools::encrypt($cart->id . $cart->secure_key . Configuration::get('HIPAY_SALT')) != Tools::getValue('token')) {
         file_put_contents('logs' . Configuration::get('HIPAY_UNIQID') . '.txt', '[' . date('Y-m-d H:i:s') . '] Token error: ' . htmlentities($_POST['xml']) . "\n", FILE_APPEND);
     } else {
         if (trim($operation) == 'capture' and trim(strtolower($status)) == 'ok') {
             /* Paiement capturé sur Hipay = Paiement accepté sur Prestashop */
             $orderMessage = $operation . ': ' . $status . '\\ndate: ' . $date . ' ' . $time . '\\ntransaction: ' . $transid . '\\namount: ' . (double) $amount . ' ' . $currency . '\\nid_cart: ' . (int) $id_cart;
             $this->validateOrder((int) $id_cart, Configuration::get('PS_OS_PAYMENT'), (double) $amount, $this->displayName, $orderMessage, array(), NULL, false, $cart->secure_key);
         } elseif (trim($operation) == 'refund' and trim(strtolower($status)) == 'ok') {
             /* Paiement remboursé sur Hipay */
             if (!($id_order = Order::getOrderByCartId((int) $id_cart))) {
                 die(Tools::displayError());
             }
             $order = new Order((int) $id_order);
             if (!$order->valid or $order->getCurrentState() === Configuration::get('PS_OS_REFUND')) {
                 die(Tools::displayError());
             }
             $orderHistory = new OrderHistory();
             $orderHistory->id_order = (int) $order->id;
             $orderHistory->changeIdOrderState((int) Configuration::get('PS_OS_REFUND'), (int) $id_order);
             $orderHistory->addWithemail();
         }
     }
 }
Ejemplo n.º 3
0
 function createSinglePaymentDlg()
 {
     $params = new HIPAY_MAPI_PaymentParams();
     //The Hipay platform connection parameters. This is not the information used to connect to your Hipay
     //account, but the specific login and password used to connect to the payment platform.
     //The login is the ID of the hipay merchant account receiving the payment, and the password is
     //the « merchant password » set within your Hipay account (site info).
     $params->setLogin('22955', 'mypassword');
     // The amounts will be credited to account 22955, except the taxes which will be credited to account 23192
     $params->setAccounts(22955, 23192);
     // The payment interface will be in International French by default
     $params->setDefaultLang('de_DE');
     // The interface will be the Web interface
     $params->setMedia('WEB');
     //The order content is intended for people at least 16 years old.
     $params->setRating('16+');
     // This is a single payment
     $params->setPaymentMethod(HIPAY_MAPI_METHOD_SIMPLE);
     // The capture take place immediately
     $params->setCaptureDay(HIPAY_MAPI_CAPTURE_IMMEDIATE);
     // The amounts are expressed in Euros, this has to be the same currency as the merchant's account.
     $params->setCurrency('EUR');
     // The merchant-selected identifier for this order is REF6522
     $params->setIdForMerchant('REF6522');
     // Two data elements of type key=value are declared and will be returned to the merchant after the payment in the
     // notification data feed [C].
     $params->setMerchantDatas('id_client', '2000');
     $params->setMerchantDatas('credit', '10');
     // This order relates to the web site which the merchant declared in the Hipay platform.
     // The I.D. assigned to this website is '9'
     $params->setMerchantSiteId(9);
     // If the payment is accepted, the user will be redirected to this page
     $params->setURLOk('http://www.mywebsite.com/success.html ');
     // If the payment is refused, the user will be redirected to this page
     $params->setUrlNok('http://www.mywebsite.com/refused.html ');
     // If the user cancels the payment, he will be redirected to this page
     $params->setUrlCancel('http://www.mywebsite.com/cancel.html ');
     // The email address used to send the notifications, on top of the http notifications.
     // cf chap 19 : RECEIVING A RESULTS NOTIFICATION ABOUT A PAYMENT ACTION
     $params->setEmailAck('*****@*****.**');
     // The merchant's site will be notified of the result of the payment by a call to the script
     // "listen_hipay_notification.php"
     // cf chap 19 : RECEIVING A RESULTS NOTIFICATION ABOUT A PAYMENT ACTION
     $params->setUrlAck('http://www.mywebsite.com/listen_hipay_notification.php');
     // The background color of the interface will be #FFFFFF (default color recommended)
     $t = $params->setBackgroundColor('#FFFFFF');
     $t = $params->check();
     if (!$t) {
         echo "An error occurred while creating the paymentParams object";
         exit;
     }
     // ## Taxes ##
     // Tax at 19.6%
     $tax1 = new HIPAY_MAPI_Tax();
     $tax1->setTaxName('TVA (19.6)');
     $tax1->setTaxVal(19.6, true);
     $t = $tax1->check();
     if (!$t) {
         echo "An error occurred while creating a tax object";
         exit;
     }
     // Fixed tax of 3.50 euros
     $tax2 = new HIPAY_MAPI_Tax();
     $tax2->setTaxName('Taxe fixe');
     $tax2->setTaxVal(3.5, false);
     $t = $tax2->check();
     if (!$t) {
         echo "An error occurred while creating a tax object";
         exit;
     }
     // Tax at 5.5%
     $tax3 = new HIPAY_MAPI_Tax();
     $tax3->setTaxName('TVA (5.5)');
     $tax3->setTaxVal(5.5, true);
     $t = $tax3->check();
     if (!$t) {
         echo "An error occurred while creating a tax object";
         exit;
     }
     //		//## Affiliates ##
     //		// Affiliate who will receive 10% of all the items in the order
     //		$aff1 = new HIPAY_MAPI_Affiliate();
     //		$aff1->setCustomerId(331);
     //		$aff1->setAccountId(59074);
     //		$aff1->setValue(10.0,HIPAY_MAPI_TTARGET_ALL);
     //		$t=$aff1->check();
     //		if (!$t)
     //		{
     //			echo "An error occurred while creating an affiliate object";
     //			exit;
     //		}
     //		// Affiliate who will receive 15% of the amount of the products, insurance and delivery amounts
     //		$aff2 = new HIPAY_MAPI_Affiliate();
     //		$aff2->setCustomerId(332);
     //		$aff2->setAccountId(59075);
     //		$aff2->setValue(15.0,HIPAY_MAPI_TTARGET_ITEM | HIPAY_MAPI_TTARGET_INSURANCE | HIPAY_MAPI_TTARGET_SHIPPING);
     //		$t=$aff2->check();
     //		if (!$t)
     //		{
     //			echo "An error occurred while creating an affiliate object";
     //			exit;
     //		}
     // ##Products (order lines) ##
     // First product: 2 copies of a book at 12.5 Euros per unit on which two taxes are applied
     //(taxes $tax3 and $tax2)
     $item1 = new HIPAY_MAPI_Product();
     $item1->setName('The Fall of Hyperion');
     $item1->setInfo('Simmons, Dan – ISBN 0575076380');
     $item1->setquantity(2);
     $item1->setRef('JV005');
     $item1->setCategory(5);
     $item1->setPrice(12.5);
     $item1->setTax(array($tax3, $tax2));
     $t = $item1->check();
     if (!$t) {
         echo "An error occurred while creating a product object";
         exit;
     }
     // Second product: An example of a product at 2360 Euros, on which 3 taxes are applied
     //($tax1, $tax2 and $tax3)
     $item2 = new HIPAY_MAPI_Product();
     $item2->setName('PC Linux');
     $item2->setInfo('Computer 445');
     $item2->setquantity(1);
     $item2->setRef('PC445');
     $item2->setCategory(2);
     $item2->setPrice(2360);
     $item2->setTax(array($tax1, $tax2, $tax3));
     $t = $item2->check();
     if (!$t) {
         echo "An error occurred while creating a product object";
         exit;
     }
     // ## Order object ##
     $order = new HIPAY_MAPI_Order();
     // Order title and information
     $order->setOrderTitle('order on mywebsite.com');
     $order->setOrderInfo('best products');
     // The order category is 3 (Books)
     // Refer to annex 7 to see how to find out what category your site belongs to.
     $order->setOrderCategory(3);
     // The shipping costs are 1.50 Euros excluding taxes, and $tax1 is applied
     $order->setShipping(1.5, array($tax1));
     // The insurance costs are 2 Euros excluding taxes, and $tax1 and $tax3 are applied
     $order->setInsurance(2, array($tax3, $tax1));
     // The fixed costs are 2.25 Euros excluding taxes, and $tax3 is applied to this amount
     $order->setFixedCost(2.25, array($tax3));
     // This order has two affiliates, $aff1 and $aff2
     $order->setAffiliate(array($aff1, $aff2));
     $t = $order->check();
     if (!$t) {
         echo "An error occurred while creating a product object";
         exit;
     }
     // ## Payment object ##
     try {
         $payment = new HIPAY_MAPI_SimplePayment($params, $order, array($item1, $item2));
     } catch (Exception $e) {
         echo "Error" . $e->getMessage();
     }
     // ## XML representation of this order and sending the feed to the Hipay platform ##
     $xmlTx = $payment->getXML();
     $output = HIPAY_MAPI_SEND_XML::sendXML($xmlTx);
     // ## Processing the platform's response ##
     $r = HIPAY_MAPI_COMM_XML::analyzeResponseXML($output, &$url, &$err_msg);
     if ($r === true) {
         // The internet user is sent to the URL indicated by the Hipay platform
         //header('Location: '.$url) ;
         // echo $url;
         return $url;
     } else {
         // Une erreur est intervenue
         echo $err_msg;
         // $url_error = "/error.html";
         //header('Location: '.$url_error) ;
     }
 }
Ejemplo n.º 4
0
 public function validation()
 {
     if (!array_key_exists('xml', $_POST)) {
         return;
     }
     if (_PS_MAGIC_QUOTES_GPC_) {
         $_POST['xml'] = stripslashes($_POST['xml']);
     }
     require_once dirname(__FILE__) . '/mapi/mapi_package.php';
     if (HIPAY_MAPI_COMM_XML::analyzeNotificationXML($_POST['xml'], $operation, $status, $date, $time, $transid, $amount, $currency, $id_cart, $data) === false) {
         file_put_contents('logs' . Configuration::get('HIPAY_UNIQID') . '.txt', '[' . date('Y-m-d H:i:s') . '] ' . $_POST['xml'] . "\n", FILE_APPEND);
     }
     if (trim($operation) == 'capture' and trim(strtolower($status)) == 'ok') {
         /* Paiement capturé sur Hipay = Paiement accepté sur Prestashop */
         $orderMessage = $operation . ': ' . $status . "\n" . 'date: ' . $date . ' ' . $time . "\n" . 'transaction: ' . $transid . "\n" . 'amount: ' . (double) $amount . ' ' . $currency . "\n" . 'id_cart: ' . (int) $id_cart;
         $this->validateOrder((int) $id_cart, _PS_OS_PAYMENT_, (double) $amount, $this->displayName, $orderMessage);
     } elseif (trim($operation) == 'refund' and trim(strtolower($status)) == 'ok') {
         /* Paiement remboursé sur Hipay */
         if (!($id_order = Order::getOrderByCartId(intval($id_cart)))) {
             die(Tools::displayError());
         }
         $order = new Order(intval($id_order));
         if (!$order->valid or $order->getCurrentState() === _PS_OS_REFUND_) {
             die(Tools::displayError());
         }
         $orderHistory = new OrderHistory();
         $orderHistory->id_order = intval($order->id);
         $orderHistory->changeIdOrderState(intval(_PS_OS_REFUND_), intval($id_order));
         $orderHistory->addWithemail();
     }
 }
Ejemplo n.º 5
0
 public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result)
 {
     require_once dirname(__FILE__) . '/mapi/mapi_package.php';
     $OrderTitle = 'Order on ' . $this->getDi()->config->get('site_title');
     $OrderInfo = $invoice->getLineDescription();
     $OrderCategory = $this->getConfig('order_category');
     $params = new HIPAY_MAPI_PaymentParams();
     $params->setLogin($this->getConfig('account_id'), $this->getConfig('merchant_password'));
     $params->setAccounts($this->getConfig('account_id'));
     $params->setLocale('en_GB');
     // The payment interface will be in International French by default
     $params->setRating('ALL');
     // '+16' - The order content is intended for people at least 16 years old.
     $params->setMedia('WEB');
     // The interface will be the Web interface
     if (!$invoice->rebill_times) {
         $params->setPaymentMethod(HIPAY_MAPI_METHOD_SIMPLE);
     } else {
         $params->setPaymentMethod(HIPAY_MAPI_METHOD_MULTI);
     }
     // It is a Recurring payment
     $params->setCaptureDay(HIPAY_MAPI_CAPTURE_IMMEDIATE);
     // The capture take place immediately
     $params->setCurrency($invoice->currency);
     $params->setIdForMerchant('aMember invoice #' . $invoice->public_id);
     // The merchant-selected identifier for this order
     $params->setMerchantDatas('invoice_id', $invoice->public_id);
     //Data element of type key=value declared and will be returned to the merchant after the payment in the notification data feed [C].
     $site_id = $this->invoice->getItem(0)->getBillingPlanData('hipay_site_id');
     if (!$site_id) {
         $site_id = $this->getConfig('site_id');
     }
     // use default value
     $params->setMerchantSiteId($site_id);
     // This order relates to the web site which the merchant declared in the Hipay platform.
     $params->setURLOk($this->getReturnUrl());
     // If the payment is accepted, the user will be redirected to this page
     $params->setUrlNok($this->getCancelUrl());
     // If the payment is refused, the user will be redirected to this page
     $params->setUrlCancel($this->getCancelUrl());
     // If the user cancels the payment, he will be redirected to this page
     $params->setUrlAck($this->getPluginUrl('ipn'));
     // The merchant's site will be notified of the result of the payment by a call to the script
     $t = $params->check();
     if (!$t) {
         throw new Am_Exception_Paysystem_TransactionInvalid('An error occurred while creating the paymentParams object');
     }
     if ($invoice->tax_rate && $invoice->tax_title) {
         $tax = new HIPAY_MAPI_Tax();
         $tax->setTaxName($invoice->tax_title);
         $percentage = true;
         //$invoice->tax_type == 1;
         $tax->setTaxVal($invoice->tax_rate, $percentage);
         $t = $tax->check();
         if (!$t) {
             throw new Am_Exception_Paysystem_TransactionInvalid('An error occurred while creating a tax object');
         }
     }
     $item1 = new HIPAY_MAPI_Product();
     $item1->setName($invoice->getItem(0)->item_title);
     $item1->setCategory($OrderCategory);
     $item1->setquantity(1);
     $item1->setPrice($invoice->first_total);
     if (isset($tax)) {
         $item1->setTax(array($tax));
     }
     //$item1->setInfo('Simmons, Dan – ISBN 0575076380');
     //$item1->setRef('JV005');
     $t = $item1->check();
     if (!$t) {
         throw new Am_Exception_Paysystem_TransactionInvalid('An error occurred while creating a product object');
     }
     $order = new HIPAY_MAPI_Order();
     $order->setOrderTitle($OrderTitle);
     // Order title and information
     $order->setOrderInfo($OrderInfo);
     $order->setOrderCategory($OrderCategory);
     // The order category is 3 (Books)
     if ($invoice->hasShipping()) {
         $order->setShipping($invoice->first_shipping, isset($tax) ? array($tax) : array());
     }
     // The shipping costs are 1.50 Euros excluding taxes, and $tax1 is applied
     //$order->setInsurance(2,array($tax3,$tax1)); // The insurance costs are 2 Euros excluding taxes, and $tax1 and $tax3 are applied
     //$order->setFixedCost(2.25,array($tax3)); // The fixed costs are 2.25 Euros excluding taxes, and $tax3 is applied to this amount
     //$order->setAffiliate(array($aff1,$aff2)); // This order has two affiliates, $aff1 and $aff2
     $t = $order->check();
     if (!$t) {
         throw new Am_Exception_Paysystem_TransactionInvalid('An error occurred while creating a product object');
     }
     if (!$invoice->rebill_times) {
         try {
             $payment = new HIPAY_MAPI_SimplePayment($params, $order, array($item1));
         } catch (Exception $e) {
             throw new Am_Exception_Paysystem_TransactionInvalid($e->getMessage());
         }
     } else {
         // First payment: The payment will be made in 1 hour, in the amount of 5 Euros, excluding taxes plus tax $tax1.
         $ins1 = new HIPAY_MAPI_Installment();
         if ($invoice->first_total > 0) {
             $price = $invoice->first_total;
             $paymentDelay = '0H';
         } else {
             $price = $invoice->second_total;
             $paymentDelay = $this->getPeriod($invoice->first_period);
         }
         $ins1->setPrice($price);
         if (isset($tax)) {
             $ins1->setTax(array($tax));
         }
         $ins1->setFirst(true, $paymentDelay);
         $t = $ins1->check();
         if (!$t) {
             throw new Am_Exception_Paysystem_TransactionInvalid('An error occurred while creating an instalment object');
         }
         // Subsequent payments: The payments will be made every 30 days in the amount of 12.5 Euros excluding taxes, plus tax of $tax2.0.
         $ins2 = new HIPAY_MAPI_Installment();
         $ins2->setPrice($invoice->second_total);
         if (isset($tax)) {
             $ins2->setTax(array($tax));
         }
         $paymentDelay = $this->getPeriod($invoice->second_period);
         $ins2->setFirst(false, $paymentDelay);
         $t = $ins2->check();
         if (!$t) {
             throw new Am_Exception_Paysystem_TransactionInvalid('An error occurred while creating an instalment object');
         }
         // Initial order
         $orderins1 = new HIPAY_MAPI_Order();
         $orderins1->setOrderTitle($OrderTitle);
         // Title and information on this payment
         $orderins1->setOrderInfo($OrderInfo);
         //1 free hour
         $orderins1->setOrderCategory($OrderCategory);
         // The order category is 3 (Books)
         $t = $orderins1->check();
         if (!$t) {
             throw new Am_Exception_Paysystem_TransactionInvalid('An error occurred while creating an order object');
         }
         // Subsequent orders
         $orderins2 = new HIPAY_MAPI_Order();
         $orderins2->setOrderTitle($OrderTitle);
         // Title and information on this payment
         $orderins2->setOrderInfo($OrderInfo);
         //only 12 euros 50 monthly !
         $orderins2->setOrderCategory($OrderCategory);
         // The order category is 3 (Books)
         $t = $orderins2->check();
         if (!$t) {
             throw new Am_Exception_Paysystem_TransactionInvalid('An error occurred while creating an order object');
         }
         try {
             $payment = new HIPAY_MAPI_MultiplePayment($params, $orderins1, $ins1, $orderins2, $ins2);
         } catch (Exception $e) {
             throw new Am_Exception_Paysystem_TransactionInvalid($e->getMessage());
         }
     }
     $xmlTx = $payment->getXML();
     $output = HIPAY_MAPI_SEND_XML::sendXML($xmlTx, $this->getConfig('testing') ? self::TEST_URL : self::URL);
     $r = HIPAY_MAPI_COMM_XML::analyzeResponseXML($output, $url, $err_msg);
     if ($r === true && !$err_msg) {
         // The internet user is sent to the URL indicated by the Hipay platform
         $a = new Am_Paysystem_Action_Redirect($url);
         $result->setAction($a);
     } else {
         throw new Am_Exception_Paysystem_TransactionInvalid($err_msg);
     }
 }
Ejemplo n.º 6
0
 public function validation()
 {
     if (!$this->active) {
         return;
     }
     if (!array_key_exists('xml', $_POST)) {
         return;
     }
     if (_PS_MAGIC_QUOTES_GPC_) {
         $_POST['xml'] = stripslashes($_POST['xml']);
     }
     require_once dirname(__FILE__) . '/mapi/mapi_package.php';
     if (HIPAY_MAPI_COMM_XML::analyzeNotificationXML($_POST['xml'], $operation, $status, $date, $time, $transid, $amount, $currency, $id_cart, $data) === false) {
         file_put_contents('logs' . Configuration::get('HIPAY_UNIQID') . '.txt', '[' . date('Y-m-d H:i:s') . '] Analysis error: ' . htmlentities($_POST['xml']) . "\n", FILE_APPEND);
         return false;
     }
     if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) {
         Context::getContext()->cart = new Cart((int) $id_cart);
     }
     $cart = new Cart((int) $id_cart);
     if (Tools::encrypt($cart->id . $cart->secure_key . Configuration::get('HIPAY_SALT')) != Tools::getValue('token')) {
         file_put_contents('logs' . Configuration::get('HIPAY_UNIQID') . '.txt', '[' . date('Y-m-d H:i:s') . '] Token error: ' . htmlentities($_POST['xml']) . "\n", FILE_APPEND);
     } else {
         if (trim($operation) == 'authorization' && trim(strtolower($status)) == 'ok') {
             // Authorization OK
             $orderMessage = $operation . ": " . $status . "\ndate: " . $date . " " . $time . "\ntransaction: " . $transid . "\namount: " . (double) $amount . " " . $currency . "\nid_cart: " . (int) $id_cart;
             $this->_createAuthorizationOrderState();
             $this->validateOrder((int) $id_cart, Configuration::get('HIPAY_AUTHORIZATION_OS'), (double) $amount, $this->displayName, $orderMessage, array(), NULL, false, $cart->secure_key);
         } else {
             if (trim($operation) == 'capture' && trim(strtolower($status)) == 'ok') {
                 // Capture OK
                 $orderMessage = $operation . ": " . $status . "\ndate: " . $date . " " . $time . "\ntransaction: " . $transid . "\namount: " . (double) $amount . " " . $currency . "\nid_cart: " . (int) $id_cart;
                 $id_order = Order::getOrderByCartId((int) $id_cart);
                 if ($id_order !== false) {
                     $order = new Order((int) $id_order);
                     if ((int) $order->getCurrentState() == (int) Configuration::get('HIPAY_AUTHORIZATION_OS')) {
                         $orderHistory = new OrderHistory();
                         $orderHistory->id_order = (int) $order->id;
                         $orderHistory->changeIdOrderState((int) Configuration::get('PS_OS_PAYMENT'), (int) $id_order);
                         $orderHistory->addWithemail();
                     }
                 } else {
                     $this->validateOrder((int) $id_cart, Configuration::get('PS_OS_PAYMENT'), (double) $amount, $this->displayName, $orderMessage, array(), NULL, false, $cart->secure_key);
                 }
                 Configuration::updateValue('HIPAY_CONFIGURATION_OK', true);
             } else {
                 if (trim($operation) == 'capture' && trim(strtolower($status)) == 'nok') {
                     // Capture NOK
                     $id_order = Order::getOrderByCartId((int) $id_cart);
                     if ($id_order !== false) {
                         $order = new Order((int) $id_order);
                         if ((int) $order->getCurrentState() == (int) Configuration::get('HIPAY_AUTHORIZATION_OS')) {
                             $orderHistory = new OrderHistory();
                             $orderHistory->id_order = (int) $order->id;
                             $orderHistory->changeIdOrderState((int) Configuration::get('PS_OS_ERROR'), (int) $id_order);
                             $orderHistory->addWithemail();
                         }
                     }
                 } elseif (trim($operation) == 'refund' && trim(strtolower($status)) == 'ok') {
                     /* Paiement remboursé sur Hipay */
                     if (!($id_order = Order::getOrderByCartId((int) $id_cart))) {
                         die(Tools::displayError());
                     }
                     $order = new Order((int) $id_order);
                     if (!$order->valid or $order->getCurrentState() === Configuration::get('PS_OS_REFUND')) {
                         die(Tools::displayError());
                     }
                     $orderHistory = new OrderHistory();
                     $orderHistory->id_order = (int) $order->id;
                     $orderHistory->changeIdOrderState((int) Configuration::get('PS_OS_REFUND'), (int) $id_order);
                     $orderHistory->addWithemail();
                 }
             }
         }
     }
 }
Ejemplo n.º 7
0
 /**
  * Returns a payment URL based on the given order object
  * 
  * @param Mage_Sales_Model_Order $order
  */
 public function getSinglePaymentUrl(Mage_Sales_Model_Order $order, $token)
 {
     $orderCategory = Mage::getStoreConfig('hipay/accountsettings/ordercategory');
     $accountmode = Mage::getStoreConfig('hipay/extendedaccountsettings/accountmode');
     // ## Base params ##
     $params = $this->setupParams($order, $token);
     if ($params == null) {
         exit;
     }
     // ## Taxes ##
     //		$tax1 = $this->createTax("TVA 19.6",  19.6, true);
     //		$tax2 = $this->createTax("Taxe fixe", 3.5,  false);
     //		$tax3 = $this->createTax("TVA 5.5",   5.5,  true);
     //
     //		if(($tax1 == null) || ($tax2 == null) || ($tax3 == null)) {
     //			exit;
     //		}
     //		// ## Affiliates ##
     //		// Affiliate who will receive 10% of all the items in the order
     //		$aff1 = $this->createAffiliate(331, 59704, 10.4, HIPAY_MAPI_TTARGET_ALL);
     //		// Affiliate who will receive 15% of the amount of the products, insurance and delivery amounts
     //		$aff2 = $this->createAffiliate(332, 59705, 15.0, HIPAY_MAPI_TTARGET_ITEM | HIPAY_MAPI_TTARGET_INSURANCE | HIPAY_MAPI_TTARGET_SHIPPING);
     //
     //		if(($aff1 == null) || ($aff2 == null)) {
     //			exit;
     //		}
     // ## Products (order lines) ##
     $orderInfo = Mage::helper("hipaymod")->__("Order") . " '" . $order->getRealOrderId() . "' " . Mage::helper("hipaymod")->__("at") . " " . $order->getStore()->getFrontendName();
     $productName = Mage::helper("hipaymod")->__('Items of order') . " " . $order->getRealOrderId();
     $productInfo = "";
     $quantity = 1;
     $productSKU = "";
     $totalOrderAmount = $order->getTotalDue();
     $shippingAmount = $order->getShippingAmount();
     $reducedOrderAmount = $totalOrderAmount - $shippingAmount;
     $item = $this->createProduct($productName, $productInfo, $quantity, $productSKU, 965, $reducedOrderAmount, array());
     if ($item == null) {
         exit;
     }
     $items = array($item);
     //		$no = 0;
     //		$orderItems = $order->getAllVisibleItems();//getAllItems();
     //		foreach ($orderItems as $orderItem)
     //		{
     //			$no++;
     //			Mage::log("count : " .$no);
     //
     //			$productOptions = ($orderItem->getProductOptions());
     //			$productId = $productOptions["info_buyRequest"]["product"];
     //			$quantity = $productOptions["info_buyRequest"]["qty"];
     //
     //			// Liste zusätzlicher Attribute als Produktinfo erstellen (z.B. "Size: Large")
     //			$productInfo = "";
     //			if(array_key_exists("attributes_info", $productOptions))
     //			{
     //				$attributesInfoArray = $productOptions["attributes_info"];
     //				foreach ($attributesInfoArray as $attribute)
     //				{
     //					if(!empty($productInfo)) {
     //						$productInfo .= ", ";
     //					}
     //					$productInfo .= $attribute["label"].": ".$attribute["value"];
     //				}
     //			}
     //
     //			$product = Mage::getModel('catalog/product')->load($productId); // Mage_Catalog_Model_Product
     //
     ////			Mage::log($product);
     //
     //			$item = $this->createProduct($product->getName(),		// product name
     //										 $productInfo,  			// product info
     //										 $quantity, 				// quantity
     //										 $product->getSKU(),		// product reference (merchant)
     //										 5, 						// hipay category - TODO: richtige Kategorie ermitteln
     //										 $product->getPrice(), 		// amount
     //										 array()					// tax(es) - TODO: Steuern ermitteln
     //										 );
     //			if($item == null) {
     //				exit;
     //			}
     //			$items[] = $item;
     //		}
     //		Mage::log($items);
     //
     //
     //		//Mage::log( serialize($order) );
     //
     //		Mage::log("Total Due      :" . $order->getTotalDue());
     //		Mage::log("Base Total Due :" . $order->getBaseTotalDue());
     //
     //		Mage::log($order->getFullTaxInfo());
     //		Mage::log( $order->getShippingTaxAmount() );
     //
     //		$baseTax = $order->getBaseShippingTaxAmount();
     //        $tax = $order->getShippingTaxAmount();
     //        $shippingBaseAmount = $order->getBaseShippingAmount();
     //        $shippingAmount = $order->getShippingAmount();
     //
     //        Mage::log("Base Tax             :" . $baseTax);
     //        Mage::log("Tax                  :" . $tax);
     //        Mage::log("Shipping Base Amount :" . $shippingBaseAmount);
     //        Mage::log("Shipping Amount      :" . $shippingAmount);
     // ## Order object ##
     $hipayorder = $this->createOrder($orderInfo, '', $orderCategory, $shippingAmount, array(), 0, array(), 0.0, array(), array());
     if ($hipayorder == null) {
         exit;
     }
     // ## Payment object ##
     $payment = $this->createSimplePayment($params, $hipayorder, $items);
     // ## XML representation of this order and sending the feed to the Hipay platform ##
     $xml = $payment->getXML();
     $response = HIPAY_MAPI_SEND_XML::sendXML($xml, $this->getHipayUrl($accountmode));
     // ## Processing the platform's response ##
     $result = HIPAY_MAPI_COMM_XML::analyzeResponseXML($response, $url, $err_msg);
     if ($result === false) {
         Mage::log($err_msg);
     }
     $resultArray = array("paymentUrl" => $url, "errorMsg" => $err_msg);
     return $resultArray;
 }