· 9 years ago · Sep 07, 2016, 03:28 PM
1<?php
2
3/*
4 * 2007-2014 PrestaShop
5 *
6 * NOTICE OF LICENSE
7 *
8 0* This source file is subject to the Academic Free License (AFL 3.0)
9 * that is bundled with this package in the file LICENSE.txt.
10 * It is also available through the world-wide-web at this URL:
11 * http://opensource.org/licenses/afl-3.0.php
12 * If you did not receive a copy of the license and are unable to
13 * obtain it through the world-wide-web, please send an email
14 * to license@prestashop.com so we can send you a copy immediately.
15 *
16 * DISCLAIMER
17 *
18 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
19 * versions in the future. If you wish to customize PrestaShop for your
20 * needs please refer to http://www.prestashop.com for more information.
21 *
22 * @author PrestaShop SA <contact@prestashop.com>
23 * @copyright 2007-2014 PrestaShop SA
24 * @version Release: $Revision: 14011 $
25 * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26 * International Registered Trademark & Property of PrestaShop SA
27 */
28
29$useSSL = true;
30include(dirname(__FILE__) . '/../../config/config.inc.php');
31include(dirname(__FILE__) . '/../../init.php');
32
33
34include_once(_PS_MODULE_DIR_ . '/iatai/iatai.php');
35include_once(_PS_MODULE_DIR_ . '/iatai/secure.php');
36
37class IataiController extends FrontController {
38
39 public $ssl = true;
40
41 public function setMedia() {
42 parent::setMedia();
43 }
44
45 public function process() {
46 parent::process();
47
48 $params = $this->initParams();
49 self::$smarty->assign(array(
50 //'formLink' => Configuration::get('IATAI_DEMO') != 'yes' ? 'https://secureacceptance.allegraplatform.com/CI_Secure_Acceptance/Payment':'https://test.secureacceptance.allegraplatform.com/CI_Secure_Acceptance/Payment',
51 'formLink' => Configuration::get('IATAI_DEMO') != 'yes' ? Configuration::get('IATAI_LIVE_URL') : Configuration::get('IATAI_TEST_URL'),
52 'iataiRedirection' => $params
53 ));
54 }
55
56 public function displayContent() {
57 parent::displayContent();
58 self::$smarty->display(_PS_MODULE_DIR_ . 'iatai/tpl/redirect.tpl');
59 }
60
61 public function initParams() {
62 $tax = (float) self::$cart->getOrderTotal() - (float) self::$cart->getOrderTotal(false);
63 $base = (float) self::$cart->getOrderTotal(true, Cart::ONLY_PRODUCTS) + (float) self::$cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS) - (float) $tax;
64
65 /* if($tax == 0)
66 $base = 0; */
67
68 $currency = new Currency(self::$cart->id_currency);
69
70 $language = new Language(self::$cart->id_lang);
71
72 $customer = new Customer(self::$cart->id_customer);
73
74 $ref = (int) self::$cart->id;
75 $uniqueId = uniqid();
76
77 $profile_id = 0;
78 $access_key = 0;
79 $secret_key = 0;
80
81 if (Configuration::get('IATAI_DEMO') != 'yes') {
82 $access_key = Tools::safeOutput(Configuration::get('IATAI_ACCESS_KEY'));
83 $profile_id = Tools::safeOutput(Configuration::get('IATAI_PROFILE_ID'));
84 $secret_key = Tools::safeOutput(Configuration::get('IATAI_ACCESS_KEY'));
85 } else {
86 $access_key = Tools::safeOutput(Configuration::get('IATAI_ACCESS_KEY_TEST'));
87 $profile_id = Tools::safeOutput(Configuration::get('IATAI_PROFILE_ID_TEST'));
88 $secret_key = Tools::safeOutput(Configuration::get('IATAI_ACCESS_KEY_TEST'));
89 }
90
91 $params_atai = array(
92 "access_key" => $access_key,
93 "profile_id" => $profile_id,
94 "transaction_uuid" => $uniqueId,
95 "signed_field_names" => "access_key,profile_id,reference_number,amount,currency,locale,transaction_type,transaction_uuid,signed_date_time,unsigned_field_names",
96 "unsigned_field_names" => "",
97 "transaction_type" => "authorization",
98 "transaction_type" => "card",
99 "signed_date_time" => gmdate("Y-m-d\TH:i:s\Z"),
100 "locale" => $language->iso_code,
101 "currency" => $currency->iso_code,
102 "amount" => (float) self::$cart->getOrderTotal(),
103 // "reference_number" => $ref,
104 // "reference_number" => "DistriyaRef001",
105 "reference_number" => "PruebaRef123",
106 );
107
108 $token = sign($params_atai, $secret_key);
109 $idAddress = Address::getFirstCustomerAddressId($customer->id);
110
111
112 $params = array(
113 array('value' => (Configuration::get('IATAI_DEMO') == 'yes' ? 1 : 0), 'name' => 'test'), //como: quitar?
114 //iatai info
115 array('value' => $access_key, 'name' => 'access_key'),
116 array('value' => $profile_id, 'name' => 'profile_id'),
117 array('value' => $profile_id, 'name' => 'transaction_uuid'),
118 array('value' => 'authorization', 'name' => 'transaction_type'),
119 array('value' => 'card', 'name' => 'payment_method'),
120 array('value' => 'access_key,profile_id,reference_number,amount,currency,locale,transaction_type,transaction_uuid,signed_date_time,unsigned_field_names', 'name' => 'signed_field_names'),
121 array('value' => '', 'name' => 'unsigned_field_names'),
122 array('value' => Tools::safeOutput(gmdate("Y-m-d\TH:i:s\Z")), 'name' => 'signed_date_time'),
123 array('value' => Tools::safeOutput($token), 'name' => 'signature'),
124 array('value' => 'Compra realizada en: DISTRIYA LTDA', 'name' => 'description'),
125 array('value' => (float) self::$cart->getOrderTotal(), 'name' => 'amount'),
126 array('value' => $ref, 'name' => 'reference_number'),
127 array('value' => Tools::safeOutput($currency->iso_code), 'name' => 'currency'),
128 array('value' => (float) $tax, 'name' => 'merchant_defined_data5'), //iva
129 array('value' => (float) $base, 'name' => 'merchant_defined_data6'), //base de devolucion
130 array('value' => Tools::safeOutput($language->iso_code), 'name' => 'locale'),
131 //buyer info
132 array('value' => Tools::safeOutput($customer->email), 'name' => 'bill_to_email'),
133 array('value' => Tools::safeOutput($customer->firstname), 'name' => 'bill_to_forename'),
134 array('value' => Tools::safeOutput($customer->lastname), 'name' => 'bill_to_surname'),
135 //extras
136 //array('value' => 'PRESTASHOP', 'name' => 'merchant_defined_data1'),
137 //array('value' => 'PRESTASHOP', 'name' => 'merchant_defined_data2'),
138 //array('value' => 'http://'.htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8').__PS_BASE_URI__.'history.php', 'name' => 'responseUrl'),
139 //array('value' => 'http://'.htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8').__PS_BASE_URI__.'modules/iatai/validation.php', 'name' => 'confirmationUrl'),
140 );
141
142
143 if ($secret_key != "")
144 $params[] = array('value' => $secret_key, 'name' => 'secret_key');
145
146 if (Db::getInstance()->getValue('SELECT `token` FROM `' . _DB_PREFIX_ . 'iatai_token` WHERE `id_cart` = ' . (int) self::$cart->id))
147 Db::getInstance()->Execute('UPDATE `' . _DB_PREFIX_ . 'iatai_token` SET `token` = "' . pSQL($token) . '" WHERE `id_cart` = ' . (int) self::$cart->id);
148 else
149 Db::getInstance()->Execute('INSERT INTO `' . _DB_PREFIX_ . 'iatai_token` (`id_cart`, `token`) VALUES (' . (int) self::$cart->id . ', \'' . pSQL($token) . '\')');
150
151 return $params;
152 }
153
154 public function createPendingOrder() {
155 try {
156 $iatai = new Iatai();
157 $iatai->validateOrder((int) self::$cart->id, (int) Configuration::get('IATAI_WAITING_PAYMENT'), (float) self::$cart->getOrderTotal(), $iatai->displayName, NULL, array(), NULL, false, self::$cart->secure_key);
158 } catch (Exception $e) {
159 throw ($e);
160 }
161 }
162
163}
164
165$iataiController = new IataiController();
166
167if (isset($_GET['create-pending-order'])) {
168 try {
169 $iataiController->createPendingOrder();
170 echo json_encode(array("status" => 200));
171 } catch (Exception $e) {
172 echo json_encode(array("status" => $e->getCode(), "msg" => $e->getMessage()));
173 }
174} else {
175 $iataiController->run();
176}