3bb75778bd4c50cb2d4b617e9533962a - Version 2.0.2

Version Notes

Versión final del módulo Pay-me para Magento

Download this release

Release Info

Developer José Alexander Zapata Ruiz
Extension 3bb75778bd4c50cb2d4b617e9533962a
Version 2.0.2
Comparing to
See all releases


Version 2.0.2

app/code/local/Alignet/Payme/Block/Shared/Form.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Alignet_Payme_Block_Shared_Form extends Mage_Payment_Block_Form
4
+ {
5
+ protected function _construct()
6
+ {
7
+ $this->setTemplate('payme/shared/form.phtml');
8
+ parent::_construct();
9
+ }
10
+ }
app/code/local/Alignet/Payme/Block/Shared/Redirect.php ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Alignet_Payme_Block_Shared_Redirect extends Mage_Core_Block_Abstract {
4
+ protected function _toHtml() {
5
+ $shared = $this->getOrder()->getPayment()->getMethodInstance();
6
+
7
+ $html = '<html><body>';
8
+
9
+ if ($shared->getDebug() == 1){
10
+
11
+ $labels = array('idEntCommerce' => 'ID Wallet de Comercio', 'names' => 'Nombres', 'lastNames' => 'Apellidos', 'mail' => 'Email', 'codAsoCardHolderWallet' => 'Código del titular de la tarjeta', 'acquirerId' => 'acquirerId', 'idCommerce' => 'idCommerce', 'purchaseOperationNumber' => 'Número de Operación', 'purchaseAmount' => 'Monto', 'purchaseCurrencyCode' => 'Código de moneda', 'language' => 'Idioma', 'billingFirstName' => 'Nombres de Facturación', 'billingLastName' => 'Apellidos de Facturación', 'billingEmail' => 'Email de Facturación', 'billingAddress' => 'Dirección de Facturación', 'billingZIP' => 'ZIP de Facturación', 'billingCity' => 'Ciudad de Facturación', 'billingState' => 'Estado de Facturación', 'billingCountry' => 'País de Facturación', 'billingPhone' => 'Teléfono de Facturación', 'shippingFirstName' => 'Nombres de Envío', 'shippingLastName' => 'Apellidos de Envío', 'shippingEmail' => 'Email de Envío', 'shippingAddress' => 'Dirección de Envío', 'shippingZIP' => 'ZIP de Envío', 'shippingCity' => 'Ciudad de Envío', 'shippingState' => 'Estado de Envío', 'shippingCountry' => 'País de Envío', 'shippingPhone' => 'Teléfono de Envío', 'mcc' => 'MCC', 'commerceAssociated' => 'Comercio Asociado', 'descriptionProducts' => 'Producto(s)', 'userCodePayme' => 'Código de Usuario Payme', 'registerVerification' => 'Cifrado de registro', 'purchaseVerification' => 'Cifrado de compra', 'keyvpos2' => 'KEY VPOS 2');
12
+
13
+ $html .= 'WALLET<br>';
14
+
15
+ foreach ($shared->getFormFields() as $field=>$value) {
16
+ if ($field == 'userCommerce')
17
+ $html .= '';
18
+ elseif ($field == 'userCodePayme')
19
+ $html .= '';
20
+ elseif ($field == 'programmingLanguage')
21
+ $html .= '';
22
+ elseif ($field == 'purchaseVerification')
23
+ $html .= '';
24
+ elseif ($field == 'reserved1')
25
+ $html .= '';
26
+ elseif ($field == 'reserved2')
27
+ $html .= '';
28
+ elseif ($field == 'reserved3')
29
+ $html .= '';
30
+ elseif ($field == 'reserved4')
31
+ $html .= '';
32
+ elseif ($field == 'reserved5')
33
+ $html .= '';
34
+ elseif ($field == 'reserved6')
35
+ $html .= '';
36
+ elseif ($field == 'reserved7')
37
+ $html .= '';
38
+ elseif ($field == 'reserved8')
39
+ $html .= '';
40
+ else {
41
+ if ($field == 'acquirerId')
42
+ // $html .= '<br>VPOS2<br>' . $labels[$field] . ': ' . $value . '<br>';
43
+ $html .= '<br>VPOS2<br>' . $field . ': ' . $value . '<br>';
44
+ else
45
+ // $html .= $labels[$field] . ': ' . $value . '<br>';
46
+ $html .= $field . ': ' . $value . '<br>';
47
+ }
48
+ }
49
+ } else {
50
+ $form = new Varien_Data_Form();
51
+ $form->setAction($shared->getPaymeSharedUrl())
52
+ ->setId('payme_shared_checkout')
53
+ ->setName('payme_shared_checkout')
54
+ ->setMethod('POST')
55
+ ->setUseContainer(true);
56
+ foreach ($shared->getFormFields() as $field=>$value) {
57
+ $form->addField($field, 'hidden', array('name'=>$field, 'value'=>$value));
58
+ }
59
+ $html.= '<center><img src="https://test2.alignetsac.com/WALLET/resources/correo/logo0.png"/></br>' . $this->__('Usted sera redirigido a Payme en pocos segundos.') . '</center>';
60
+ // Se le redireccionará a la pasarela VPOS de Alignet
61
+ $html.= $form->toHtml();
62
+ $html.= '<script type="text/javascript">document.getElementById("payme_shared_checkout").submit();</script>';
63
+ }
64
+
65
+ $html.= '</body></html>';
66
+
67
+ return $html;
68
+ }
69
+ }
app/code/local/Alignet/Payme/Controller/Abstract.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ abstract class Alignet_Payme_Controller_Abstract extends Mage_Core_Controller_Front_Action
4
+ {
5
+ protected function _expireAjax()
6
+ {
7
+ if (!$this->getCheckout()->getQuote()->hasItems()) {
8
+ $this->getResponse()->setHeader('HTTP/1.1','403 Session Expired');
9
+ exit;
10
+ }
11
+ }
12
+
13
+ /**
14
+ * Redirect Block
15
+ * need to be redeclared
16
+ */
17
+ protected $_redirectBlockType;
18
+
19
+ /**
20
+ * Get singleton of Checkout Session Model
21
+ *
22
+ * @return Mage_Checkout_Model_Session
23
+ */
24
+ public function getCheckout()
25
+ {
26
+ return Mage::getSingleton('checkout/session');
27
+ }
28
+
29
+ /**
30
+ * when customer select 2CO payment method
31
+ */
32
+ public function redirectAction()
33
+ {
34
+
35
+ $session = $this->getCheckout();
36
+ $session->setPaymeQuoteId($session->getQuoteId());
37
+ $session->setPaymeRealOrderId($session->getLastRealOrderId());
38
+
39
+ $order = Mage::getModel('sales/order');
40
+ $order->loadByIncrementId($session->getLastRealOrderId());
41
+ $order->addStatusToHistory($order->getStatus(), Mage::helper('payme')->__('El cliente ha sido redirecionado a Payme.'));
42
+ $this->getResponse()->setBody(
43
+ $this->getLayout()
44
+ ->createBlock($this->_redirectBlockType)
45
+ ->setOrder($order)
46
+ ->toHtml()
47
+ );
48
+ $order->save();
49
+
50
+ $session->unsQuoteId();
51
+ $session->unsLastRealOrderId();
52
+ }
53
+
54
+ // 400000065
55
+
56
+
57
+ }
app/code/local/Alignet/Payme/Helper/Data.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class Alignet_Payme_Helper_Data extends Mage_Core_Helper_Abstract
5
+ {
6
+
7
+ }
app/code/local/Alignet/Payme/Model/Shared-org.php ADDED
@@ -0,0 +1,423 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Alignet_Payme_Model_Shared extends Mage_Payment_Model_Method_Abstract
4
+ {
5
+ protected $_code = 'payme_shared';
6
+
7
+ // protected $_isGateway = true; //false
8
+ // protected $_canAuthorize = true; //false
9
+ // protected $_canCapture = true;
10
+ // protected $_canCapturePartial = true; //false
11
+ // protected $_canRefund = true; //false
12
+ // protected $_canVoid = true; //false
13
+ // protected $_canUseInternal = true; //false
14
+ // protected $_canUseCheckout = true;
15
+ // protected $_canUseForMultishipping = true; //false
16
+
17
+ protected $_formBlockType = 'payme/shared_form';
18
+ protected $_paymentMethod = 'shared';
19
+ protected $_order;
20
+
21
+ private $descriptionProducts = 'Prpduct Information';
22
+
23
+ public function cleanString($string) {
24
+
25
+ $string_step1 = strip_tags($string);
26
+ $string_step2 = nl2br($string_step1);
27
+ $string_step3 = str_replace("<br />","<br>",$string_step2);
28
+ $cleaned_string = str_replace("\""," inch",$string_step3);
29
+ return $cleaned_string;
30
+ }
31
+
32
+
33
+ /**
34
+ * Get checkout session namespace
35
+ *
36
+ * @return Mage_Checkout_Model_Session
37
+ */
38
+ public function getCheckout()
39
+ {
40
+ return Mage::getSingleton('checkout/session');
41
+ }
42
+
43
+ /**
44
+ * Get current quote
45
+ *
46
+ * @return Mage_Sales_Model_Quote
47
+ */
48
+ public function getQuote()
49
+ {
50
+ return $this->getCheckout()->getQuote();
51
+ }
52
+
53
+
54
+ /**
55
+ * Get order model
56
+ *
57
+ * @return Mage_Sales_Model_Order
58
+ */
59
+ public function getOrder()
60
+ {
61
+ if (!$this->_order) {
62
+ $paymentInfo = $this->getInfoInstance();
63
+ $this->_order = Mage::getModel('sales/order')
64
+ ->loadByIncrementId($paymentInfo->getOrder()->getRealOrderId());
65
+ }
66
+ return $this->_order;
67
+ }
68
+
69
+ // public function getCustomerId()
70
+ // {
71
+ // return Mage::getStoreConfig('payment/' . $this->getCode() . '/customer_id');
72
+ // }
73
+
74
+ // public function getAccepteCurrency()
75
+ // {
76
+ // return Mage::getStoreConfig('payment/' . $this->getCode() . '/currency');
77
+ // }
78
+
79
+ public function getOrderPlaceRedirectUrl()
80
+ {
81
+ return Mage::getUrl('payme/shared/redirect');
82
+ }
83
+
84
+ public function setDescripcionProducts($descriptionProducts) {
85
+ $this->descriptionProducts = $descriptionProducts;
86
+ }
87
+
88
+ /**
89
+ * prepare params array to send it to gateway page via POST
90
+ *
91
+ * @return array
92
+ */
93
+ public function getFormFields()
94
+ {
95
+
96
+ $billing = $this->getOrder()->getBillingAddress();
97
+ $shipping = $this->getOrder()->getShippingAddress();
98
+ $coFields = array();
99
+
100
+ $baseCurrencyCode = Mage::app()->getStore()->getBaseCurrencyCode();
101
+ $currency_name = Mage::app()->getLocale()->currency($baseCurrencyCode)->getName();
102
+ $purchaseCurrencyCode = '';
103
+ switch ($baseCurrencyCode) {
104
+ case 'PEN':
105
+ $purchaseCurrencyCode = 604;
106
+ break;
107
+ case 'USD':
108
+ $purchaseCurrencyCode = 840;
109
+ break;
110
+ default:
111
+ $purchaseCurrencyCode = 604;
112
+ break;
113
+ }
114
+
115
+ // $locale = Mage::getStoreConfig('general/locale/code');
116
+ // $locale = Mage::app()->getStore()->getLocaleCode();
117
+ // $locale = Mage::getStoreConfig('general/locale/code', Mage::app()->getStore()->getId());
118
+ $locale = Mage::app()->getLocale()->getLocaleCode();
119
+ $locale = substr($locale, 0, 2);
120
+ $language = '';
121
+ switch ($locale) {
122
+ case 'es':
123
+ $language = 'ES';
124
+ break;
125
+ case 'en':
126
+ $language = 'EN';
127
+ break;
128
+ default:
129
+ $language = 'ES';
130
+ break;
131
+ }
132
+
133
+ // $countProducts = 0;
134
+ // $descriptionProducts = '';
135
+ // $idProducts = '';
136
+
137
+ // $session = Mage::getSingleton('checkout/session');
138
+ // foreach ($session->getQuote()->getAllItems() as $item) {
139
+ // $idProducts .= $item->getProductId() . ',';
140
+ // $descriptionProducts .= $item->getName().",";
141
+ // $countProducts++;
142
+ // }
143
+
144
+ // $order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrder()->getRealOrderId());
145
+ // $items = $order->getAllItems();
146
+ // foreach ($items as $itemId => $item) {
147
+ // $idProducts .= $item->getProductId() . ',';
148
+ // $descriptionProducts .= Mage::getModel('catalog/product')->load($item->getProductId()) . ',';
149
+ // $countProducts++;
150
+ // }
151
+
152
+ // $cart = Mage::getModel('checkout/cart')->getQuote();
153
+ // foreach ($cart->getAllItems() as $item) {
154
+ // $descriptionProducts .= $item->getProduct()->getName() . ',';
155
+ // }
156
+
157
+ // if ($countProducts == 1) {
158
+ // $descriptionProducts = substr(trim($descriptionProducts, ','), 0, 30);
159
+ // } else {
160
+ // $descriptionProducts = "Varios ($countProducts Productos)";
161
+ // }
162
+
163
+ $ALIGNET_DEBUG = $this->getDebug();
164
+ $ALIGNET_IDENTCOMMERCE = Mage::getStoreConfig('payment/payme_shared/ALIGNET_IDENTCOMMERCE');
165
+ $ALIGNET_KEYWALLET = Mage::getStoreConfig('payment/payme_shared/ALIGNET_KEYWALLET');
166
+ $ALIGNET_IDACQUIRER = Mage::getStoreConfig('payment/payme_shared/ALIGNET_IDACQUIRER');
167
+ $ALIGNET_IDCOMMERCE = Mage::getStoreConfig('payment/payme_shared/ALIGNET_IDCOMMERCE');
168
+ $ALIGNET_MCC = Mage::getStoreConfig('payment/payme_shared/ALIGNET_MCC');
169
+ $ALIGNET_KEY = Mage::getStoreConfig('payment/payme_shared/ALIGNET_KEY');
170
+ $ALIGNET_URLTPV = Mage::getStoreConfig('payment/payme_shared/ALIGNET_URLTPV');
171
+
172
+ $long = 0;
173
+ $num_ope = number_format($this->getOrder()->getRealOrderId(),0,'','');
174
+ $purchaseOperationNumber = 0;
175
+ if ($ALIGNET_IDACQUIRER == 144 || $ALIGNET_IDACQUIRER == 29) {
176
+ $long = 5;
177
+ $purchaseOperationNumber = str_pad($num_ope, $long, "0", STR_PAD_LEFT);
178
+ $purchaseOperationNumber = substr($purchaseOperationNumber, 4, 5)
179
+ } elseif ($ALIGNET_IDACQUIRER == 84 || $ALIGNET_IDACQUIRER == 10) {
180
+ $long = 9;
181
+ $purchaseOperationNumber = str_pad($num_ope, $long, "0", STR_PAD_LEFT);
182
+ }
183
+ $commerceAssociated = '';
184
+ if ($ALIGNET_IDACQUIRER == 144 || $ALIGNET_IDACQUIRER == 29) {
185
+ switch ($purchaseCurrencyCode) {
186
+ case 604:
187
+ $commerceAssociated = 'MALL ALIGNET-PSP SOLES';
188
+ break;
189
+ case 840:
190
+ $commerceAssociated = 'MALL ALIGNET-PSP DOLARES';
191
+ break;
192
+ default:
193
+ $commerceAssociated = 'MALL ALIGNET-PSP';
194
+ break;
195
+ }
196
+ }
197
+
198
+ $purchaseAmount = floatval(str_replace('.','',number_format($this->getOrder()->getBaseGrandTotal(), 2, '.', '')));
199
+
200
+ if (phpversion() >= 5.3) {
201
+ $registerVerification = openssl_digest($ALIGNET_IDENTCOMMERCE . $this->getOrder()->getCustomerId() . $this->getOrder()->getCustomerEmail() . $ALIGNET_KEYWALLET, 'sha512');
202
+
203
+ $purchaseVerification = openssl_digest($ALIGNET_IDACQUIRER . $ALIGNET_IDENTCOMMERCE . $purchaseOperationNumber . $purchaseAmount . $purchaseCurrencyCode . $ALIGNET_KEYWALLET, 'sha512');
204
+ } else {
205
+ $registerVerification = hash('sha512', $ALIGNET_IDENTCOMMERCE . $this->getOrder()->getCustomerId() . $this->getOrder()->getCustomerEmail() . $ALIGNET_KEYWALLET);
206
+ $purchaseVerification = hash('sha512', $ALIGNET_IDACQUIRER . $ALIGNET_IDENTCOMMERCE . $purchaseOperationNumber . $purchaseAmount . $purchaseCurrencyCode . $ALIGNET_KEYWALLET);
207
+ }
208
+
209
+ $codAsoCardHolderWallet = '';
210
+
211
+ switch($ALIGNET_URLTPV){
212
+ case 0:
213
+ $wsdl = "https://test2.alignetsac.com/WALLETWS/services/WalletCommerce?wsdl";
214
+ break;
215
+ case 1:
216
+ $wsdl = "https://www.pay-me.pe/WALLETWS/services/WalletCommerce?wsdl";
217
+ break;
218
+ }
219
+ $client = new SoapClient($wsdl);
220
+ $params = array(
221
+ 'idEntCommerce'=>(string)$ALIGNET_IDENTCOMMERCE,
222
+ 'codCardHolderCommerce'=>(string)$this->getOrder()->getCustomerId(),
223
+ 'names'=>$billing->getFirstname(),
224
+ 'lastNames'=>$billing->getLastname(),
225
+ 'mail'=>$billing->getEmail(),
226
+ 'reserved1'=>'',
227
+ 'reserved2'=>'',
228
+ 'reserved3'=>'',
229
+ 'registerVerification'=>$registerVerification
230
+ );
231
+ $result = $client->RegisterCardHolder($params);
232
+ $codAsoCardHolderWallet = $result->codAsoCardHolderWallet;
233
+
234
+ $coFields["codAsoCardHolderWallet"] = $this->getOrder()->getCustomerId();
235
+ $coFields["names"] = $billing->getFirstname();
236
+ $coFields["lastNames"] = $billing->getLastname();
237
+ $coFields["mail"] = $billing->getEmail();
238
+
239
+ $coFields["acquirerId"] = $ALIGNET_IDACQUIRER;
240
+ $coFields["idCommerce"] = $ALIGNET_IDCOMMERCE;
241
+ $coFields["purchaseOperationNumber"] = $purchaseOperationNumber;
242
+ $coFields["purchaseAmount"] = $purchaseAmount;
243
+ $coFields["purchaseCurrencyCode"] = $purchaseCurrencyCode;
244
+ $coFields["language"] = $language;
245
+ $coFields['billingFirstName'] = $billing->getFirstname();
246
+ $coFields['billingLastName'] = $billing->getLastname();
247
+ $coFields['billingEmail'] = $billing->getEmail();
248
+ $coFields['billingAddress'] = $billing->getStreet()[0];
249
+ $coFields['billingZip'] = $billing->getPostcode();
250
+ $coFields['billingCity'] = $billing->getCity();
251
+ $coFields['billingState'] = $billing->getRegion();
252
+ $coFields['billingCountry'] = $billing->getCountry();
253
+ $coFields['billingPhone'] = $billing->getTelephone();
254
+ $coFields['shippingFirstName'] = $shipping->getFirstname();
255
+ $coFields['shippingLastName'] = $shipping->getLastname();
256
+ $coFields['shippingEmail'] = $shipping->getEmail();
257
+ $coFields['shippingAddress'] = $shipping->getStreet()[0];
258
+ $coFields['shippingZip'] = $shipping->getPostcode();
259
+ $coFields['shippingCity'] = $shipping->getCity();
260
+ $coFields['shippingState'] = $shipping->getRegion();
261
+ $coFields['shippingCountry'] = $shipping->getCountry();
262
+ $coFields['shippingPhone'] = $shipping->getTelephone();
263
+ $coFields["userCommerce"] = $this->getOrder()->getCustomerId();
264
+ $coFields["userCodePayme"] = $codAsoCardHolderWallet;
265
+ if ($ALIGNET_IDACQUIRER == 144 || $ALIGNET_IDACQUIRER == 29) {
266
+ $coFields["mcc"] = $ALIGNET_MCC;
267
+ $coFields['commerceAssociated'] = $commerceAssociated;
268
+ }
269
+ $coFields['descriptionProducts'] = $this->descriptionProducts;
270
+ $coFields['programmingLanguage'] = 'PHP';
271
+ $coFields['reserved1'] = $num_ope;
272
+ $coFields['reserved2'] = '';
273
+ $coFields['reserved3'] = $purchaseAmount;
274
+ $coFields['reserved4'] = $currency_name;
275
+ $coFields["purchaseVerification"] = $purchaseVerification;
276
+ return $coFields;
277
+ }
278
+
279
+ /**
280
+ * Get url of Payu payment
281
+ *
282
+ * @return string
283
+ */
284
+ public function getPaymeSharedUrl()
285
+ {
286
+ $ALIGNET_URLTPV = Mage::getStoreConfig('payment/payme_shared/ALIGNET_URLTPV');
287
+
288
+ $url = 'https://test2.alignetsac.com/VPOS2/faces/pages/startPayme.xhtml';
289
+
290
+ if($ALIGNET_URLTPV == 1) {
291
+ $url = 'https://vpayment.verifika.com/VPOS2/faces/pages/startPayme.xhtml';
292
+ }
293
+
294
+ return $url;
295
+ }
296
+
297
+
298
+ /**
299
+ * Get debug flag
300
+ *
301
+ * @return string
302
+ */
303
+ public function getDebug()
304
+ {
305
+ return Mage::getStoreConfig('payment/payme_shared/ALIGNET_DEBUG');
306
+ }
307
+
308
+ public function capture(Varien_Object $payment, $amount)
309
+ {
310
+ $payment->setStatus(self::STATUS_APPROVED)
311
+ ->setLastTransId($this->getTransactionId());
312
+
313
+ return $this;
314
+ }
315
+
316
+ public function cancel(Varien_Object $payment)
317
+ {
318
+ $payment->setStatus(self::STATUS_DECLINED)
319
+ ->setLastTransId($this->getTransactionId());
320
+
321
+ return $this;
322
+ }
323
+
324
+ /**
325
+ * parse response POST array from gateway page and return payment status
326
+ *
327
+ * @return bool
328
+ */
329
+ public function parseResponse()
330
+ {
331
+
332
+ return true;
333
+
334
+ }
335
+
336
+ /**
337
+ * Return redirect block type
338
+ *
339
+ * @return string
340
+ */
341
+ public function getRedirectBlockType()
342
+ {
343
+ return $this->_redirectBlockType;
344
+ }
345
+
346
+ /**
347
+ * Return payment method type string
348
+ *
349
+ * @return string
350
+ */
351
+ public function getPaymentMethodType()
352
+ {
353
+ return $this->_paymentMethod;
354
+ }
355
+
356
+
357
+ public function getResponseOperation($response) {
358
+ $authorizationResult = trim($response['authorizationResult']) == "" ? "-" : $response['authorizationResult'];
359
+ $authorizationCode = trim($response['authorizationCode']) == "" ? "-" : $response['authorizationCode'];
360
+ $errorCode = trim($response['errorCode']) == "" ? "-" : $response['errorCode'];
361
+ $errorMessage = trim($_POST['errorMessage']) == "" ? "-" : $_POST['errorMessage'];
362
+ $bin = trim($response['bin']) == "" ? "-" : $response['bin'];
363
+ $brand = trim($response['brand']) == "" ? "-" : $response['brand'];
364
+ $paymentReferenceCode = trim($response['paymentReferenceCode']) == "" ? "-" : $response['paymentReferenceCode'];
365
+ $reserved1 = trim($response['reserved1']) == "" ? "-" : $response['reserved1'];
366
+ $reserved2 = trim($response['reserved2']) == "" ? "-" : $response['reserved2'];
367
+ $reserved3 = trim($response['reserved3']) == "" ? "-" : $response['reserved3'];
368
+ $reserved4 = trim($response['reserved4']) == "" ? "-" : $response['reserved4'];
369
+ $order = Mage::getModel('sales/order');
370
+ // return $reserved1;
371
+ if ($authorizationResult == '00') {
372
+ $fechaHora = date("d/m/Y H:i:s");
373
+ $message = Mage::helper('payme')->__('Número de Operación de Compra') . ": " . $reserved1 . " | ";
374
+ $message .= Mage::helper('payme')->__('Resultado de la Operación: Operación autorizada y exitosa') . " | ";
375
+ $message .= Mage::helper('payme')->__('Fecha y Hora de la Operación') . ": " . $fechaHora . " | ";
376
+ $message .= Mage::helper('payme')->__('Monto') . ": " . $reserved3 . " | ";
377
+ $message .= Mage::helper('payme')->__('Moneda') . ": " . $reserved4 . " | ";
378
+ $message .= Mage::helper('payme')->__('Marca de la Tarjeta') . ": " . $brand . "";
379
+
380
+ $order->loadByIncrementId($reserved1);
381
+ // $order->setState(Mage_Sales_Model_Order::STATE_COMPLETE, true);
382
+ $order->setData('state', "Complete");
383
+ $order->setStatus("Complete");
384
+ $history = $order->addStatusHistoryComment(Mage::helper('payme')->__('El estado del pedido: "Complete"'), false);
385
+ $history = $order->addStatusHistoryComment($message, false);
386
+ $history->setIsCustomerNotified(false);
387
+ $order->save();
388
+ $order->sendNewOrderEmail();
389
+ return 'checkout/onepage/success';
390
+ } elseif ($authorizationResult == '01'){
391
+ $order->loadByIncrementId($reserved1);
392
+ $order->setState(Mage_Sales_Model_Order::STATE_CANCELED, true);
393
+ $this->updateInventory($reserved1);
394
+ $order->cancel()->save();
395
+ return 'checkout/onepage/failure';
396
+ } elseif ($authorizationResult == '05') {
397
+ $order->loadByIncrementId($reserved1);
398
+ $order->setState(Mage_Sales_Model_Order::STATE_CANCELED, true);
399
+ $this->updateInventory($reserved1);
400
+ $order->cancel()->save();
401
+ return 'checkout/onepage/failure';
402
+ // return 'canceled';
403
+ }
404
+ }
405
+
406
+ public function updateInventory($orderId) {
407
+ $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
408
+ $items = $order->getAllItems();
409
+ foreach ($items as $itemId => $item) {
410
+ $orderedQuantity = $item->getQtyToInvoice();
411
+ $sku = $item->getSku();
412
+ $product = Mage::getModel('catalog/product')->load($item->getProductId());
413
+ $qtyStock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product->getId())->getQty();
414
+
415
+ $updatedInventory=$qtyStock+ $orderedQuantity;
416
+
417
+ $stockData = $product->getStockItem();
418
+ $stockData->setData('qty',$updatedInventory);
419
+ $stockData->save();
420
+ }
421
+ }
422
+
423
+ }
app/code/local/Alignet/Payme/Model/Shared.php ADDED
@@ -0,0 +1,449 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Alignet_Payme_Model_Shared extends Mage_Payment_Model_Method_Abstract
4
+ {
5
+ protected $_code = 'payme_shared';
6
+
7
+ protected $_formBlockType = 'payme/shared_form';
8
+ protected $_paymentMethod = 'shared';
9
+ protected $_order;
10
+
11
+ // private $descriptionProducts = 'Producto(s) ' . Mage::getBaseUrl();
12
+ private $descriptionProducts = 'Producto(s)';
13
+
14
+ public function cleanString($string) {
15
+
16
+ $string_step1 = strip_tags($string);
17
+ $string_step2 = nl2br($string_step1);
18
+ $string_step3 = str_replace("<br />","<br>",$string_step2);
19
+ $cleaned_string = str_replace("\""," inch",$string_step3);
20
+ return $cleaned_string;
21
+ }
22
+
23
+
24
+ /**
25
+ * Get checkout session namespace
26
+ *
27
+ * @return Mage_Checkout_Model_Session
28
+ */
29
+ public function getCheckout()
30
+ {
31
+ return Mage::getSingleton('checkout/session');
32
+ }
33
+
34
+ /**
35
+ * Get checkout session namespace
36
+ *
37
+ * @return Mage_Checkout_Model_Session
38
+ */
39
+ public function getConnexion()
40
+ {
41
+ return Mage::getSingleton('core/resource')->getConnection('core_read');
42
+ }
43
+
44
+ /**
45
+ * Get current quote
46
+ *
47
+ * @return Mage_Sales_Model_Quote
48
+ */
49
+ public function getQuote()
50
+ {
51
+ return $this->getCheckout()->getQuote();
52
+ }
53
+
54
+
55
+ /**
56
+ * Get order model
57
+ *
58
+ * @return Mage_Sales_Model_Order
59
+ */
60
+ public function getOrder()
61
+ {
62
+ if (!$this->_order) {
63
+ $paymentInfo = $this->getInfoInstance();
64
+ $this->_order = Mage::getModel('sales/order')
65
+ ->loadByIncrementId($paymentInfo->getOrder()->getRealOrderId());
66
+ }
67
+ return $this->_order;
68
+ }
69
+
70
+ // public function getCustomerId()
71
+ // {
72
+ // return Mage::getStoreConfig('payment/' . $this->getCode() . '/customer_id');
73
+ // }
74
+
75
+ // public function getAccepteCurrency()
76
+ // {
77
+ // return Mage::getStoreConfig('payment/' . $this->getCode() . '/currency');
78
+ // }
79
+
80
+ public function getOrderPlaceRedirectUrl()
81
+ {
82
+ return Mage::getUrl('payme/shared/redirect');
83
+ }
84
+
85
+ public function setDescripcionProducts($descriptionProducts) {
86
+ $this->descriptionProducts = $descriptionProducts;
87
+ }
88
+
89
+ /**
90
+ * prepare params array to send it to gateway page via POST
91
+ *
92
+ * @return array
93
+ */
94
+ public function getFormFields()
95
+ {
96
+
97
+ $billing = $this->getOrder()->getBillingAddress();
98
+ $shipping = $this->getOrder()->getShippingAddress();
99
+ $coFields = array();
100
+
101
+ $baseCurrencyCode = Mage::app()->getStore()->getBaseCurrencyCode();
102
+ $currency_name = Mage::app()->getLocale()->currency($baseCurrencyCode)->getName();
103
+ $purchaseCurrencyCode = '';
104
+ switch ($baseCurrencyCode) {
105
+ case 'PEN':
106
+ $purchaseCurrencyCode = '604';
107
+ break;
108
+ case 'USD':
109
+ $purchaseCurrencyCode = '840';
110
+ break;
111
+ default:
112
+ $purchaseCurrencyCode = '604';
113
+ break;
114
+ }
115
+
116
+ $locale = Mage::app()->getLocale()->getLocaleCode();
117
+ $locale = substr($locale, 0, 2);
118
+ $language = '';
119
+ switch ($locale) {
120
+ case 'es':
121
+ $language = 'ES';
122
+ break;
123
+ case 'en':
124
+ $language = 'EN';
125
+ break;
126
+ default:
127
+ $language = 'ES';
128
+ break;
129
+ }
130
+
131
+ $ALIGNET_DEBUG = $this->getDebug();
132
+ $ALIGNET_IDENTCOMMERCE = Mage::getStoreConfig('payment/payme_shared/ALIGNET_IDENTCOMMERCE');
133
+ $ALIGNET_KEYWALLET = Mage::getStoreConfig('payment/payme_shared/ALIGNET_KEYWALLET');
134
+ $ALIGNET_IDACQUIRER = Mage::getStoreConfig('payment/payme_shared/ALIGNET_IDACQUIRER');
135
+ $ALIGNET_IDCOMMERCE = Mage::getStoreConfig('payment/payme_shared/ALIGNET_IDCOMMERCE');
136
+ $ALIGNET_MCC = Mage::getStoreConfig('payment/payme_shared/ALIGNET_MCC');
137
+ $ALIGNET_KEY = Mage::getStoreConfig('payment/payme_shared/ALIGNET_KEY');
138
+ $ALIGNET_URLTPV = Mage::getStoreConfig('payment/payme_shared/ALIGNET_URLTPV');
139
+
140
+ $long = 0;
141
+ /* NUEVO DE PEDIDO QUE GENERA MAGENTO */
142
+ $num_ope_mgt = number_format($this->getOrder()->getRealOrderId(),0,'','');
143
+
144
+ /* NUMERO GENERADO POR MI */
145
+ $connection = $this->getConnexion();
146
+
147
+ $select = $connection->select()->from('sales_flat_order', array('entity_id'))->order(array('entity_id DESC'))->limit(1);
148
+
149
+ // $rowsArray = $connection->fetchAll($select); // return all rows
150
+ $rowArray =$connection->fetchRow($select); //return row
151
+ $num_ope = 0;
152
+
153
+ if (is_null($rowArray["entity_id"]) || $rowArray["entity_id"] == '' || $rowArray["entity_id"] == null)
154
+ $num_ope = 1;
155
+ else
156
+ $num_ope = $rowArray["entity_id"];
157
+
158
+ $purchaseOperationNumber = 0;
159
+ if ($ALIGNET_IDACQUIRER == 144 || $ALIGNET_IDACQUIRER == 29) {
160
+ $long = 5;
161
+ $purchaseOperationNumber = str_pad($num_ope, $long, "0", STR_PAD_LEFT);
162
+ // $purchaseOperationNumber = substr($purchaseOperationNumber, 4, 5);
163
+ } elseif ($ALIGNET_IDACQUIRER == 84 || $ALIGNET_IDACQUIRER == 123 || $ALIGNET_IDACQUIRER == 10 || $ALIGNET_IDACQUIRER == 23) {
164
+ $long = 9;
165
+ $purchaseOperationNumber = str_pad($num_ope, $long, "0", STR_PAD_LEFT);
166
+ }
167
+ $commerceAssociated = '';
168
+ if ($ALIGNET_IDACQUIRER == 144 || $ALIGNET_IDACQUIRER == 29) {
169
+ switch ($purchaseCurrencyCode) {
170
+ case 604:
171
+ $commerceAssociated = 'MALL ALIGNET-PSP SOLES';
172
+ break;
173
+ case 840:
174
+ $commerceAssociated = 'MALL ALIGNET-PSP DOLARES';
175
+ break;
176
+ default:
177
+ $commerceAssociated = 'MALL ALIGNET-PSP';
178
+ break;
179
+ }
180
+ }
181
+
182
+ $purchaseAmount = floatval(str_replace('.','',number_format($this->getOrder()->getBaseGrandTotal(), 2, '.', '')));
183
+ $purchaseAmountFormat = number_format(floatval($this->getOrder()->getBaseGrandTotal()), 2, '.', '');
184
+
185
+ $purchaseVerification = "";
186
+
187
+ if (phpversion() >= 5.3) {
188
+ $registerVerification = openssl_digest($ALIGNET_IDENTCOMMERCE . $this->getOrder()->getCustomerId() . $billing->getEmail() . $ALIGNET_KEYWALLET, 'sha512');
189
+ $purchaseVerification = openssl_digest($ALIGNET_IDACQUIRER . $ALIGNET_IDCOMMERCE . $purchaseOperationNumber . $purchaseAmount . $purchaseCurrencyCode . $ALIGNET_KEY, 'sha512');
190
+ } else {
191
+ $registerVerification = hash('sha512', $ALIGNET_IDENTCOMMERCE . $this->getOrder()->getCustomerId() . $billing->getEmail() . $ALIGNET_KEYWALLET);
192
+ $purchaseVerification = hash('sha512', $ALIGNET_IDACQUIRER . $ALIGNET_IDCOMMERCE . $purchaseOperationNumber . $purchaseAmount . $purchaseCurrencyCode . $ALIGNET_KEY);
193
+ }
194
+
195
+ $coFields['purchaseVerification'] = $purchaseVerification;
196
+
197
+ $codAsoCardHolderWallet = '';
198
+
199
+ switch($ALIGNET_URLTPV){
200
+ case 0:
201
+ $wsdl = "https://integracion.alignetsac.com/WALLETWS/services/WalletCommerce?wsdl";
202
+ break;
203
+ case 1:
204
+ $wsdl = "https://www.pay-me.pe/WALLETWS/services/WalletCommerce?wsdl";
205
+ break;
206
+ }
207
+ $client = new SoapClient($wsdl);
208
+ $params = array(
209
+ 'idEntCommerce'=>(string)$ALIGNET_IDENTCOMMERCE,
210
+ 'codCardHolderCommerce'=>(string)$this->getOrder()->getCustomerId(),
211
+ 'names'=>$billing->getFirstname(),
212
+ 'lastNames'=>$billing->getLastname(),
213
+ 'mail'=>$billing->getEmail(),
214
+ 'reserved1'=>'',
215
+ 'reserved2'=>'',
216
+ 'reserved3'=>'',
217
+ 'registerVerification'=>$registerVerification
218
+ );
219
+ $result = $client->RegisterCardHolder($params);
220
+ $codAsoCardHolderWallet = $result->codAsoCardHolderWallet;
221
+
222
+ $coFields["codAsoCardHolderWallet"] = $this->getOrder()->getCustomerId();
223
+ $coFields["names"] = $billing->getFirstname();
224
+ $coFields["lastNames"] = $billing->getLastname();
225
+ $coFields["mail"] = $billing->getEmail();
226
+
227
+ $coFields["acquirerId"] = $ALIGNET_IDACQUIRER;
228
+ $coFields["idCommerce"] = $ALIGNET_IDCOMMERCE;
229
+ $coFields["purchaseOperationNumber"] = $purchaseOperationNumber;
230
+ $coFields["purchaseAmount"] = $purchaseAmount;
231
+ $coFields["purchaseCurrencyCode"] = $purchaseCurrencyCode;
232
+ $coFields["language"] = $language;
233
+ $coFields['billingFirstName'] = $billing->getFirstname();
234
+ $coFields['billingLastName'] = $billing->getLastname();
235
+ $coFields['billingEmail'] = $billing->getEmail();
236
+ $coFields['billingAddress'] = $billing->getStreet()[0];
237
+ $coFields['billingZIP'] = $billing->getPostcode();
238
+ $coFields['billingCity'] = $billing->getCity();
239
+ $coFields['billingState'] = ($billing->getRegion() == "") ? $billing->getCity() : $billing->getRegion();
240
+ $coFields['billingCountry'] = $billing->getCountry();
241
+ $coFields['billingPhone'] = $billing->getTelephone();
242
+ $coFields['shippingFirstName'] = $shipping->getFirstname();
243
+ $coFields['shippingLastName'] = $shipping->getLastname();
244
+ $coFields['shippingEmail'] = $shipping->getEmail();
245
+ $coFields['shippingAddress'] = $shipping->getStreet()[0];
246
+ $coFields['shippingZIP'] = $shipping->getPostcode();
247
+ $coFields['shippingCity'] = $shipping->getCity();
248
+ $coFields['shippingState'] = ($shipping->getRegion() == "") ? $shipping->getCity() : $shipping->getRegion();
249
+ $coFields['shippingCountry'] = $shipping->getCountry();
250
+ $coFields['shippingPhone'] = $shipping->getTelephone();
251
+ $coFields["userCommerce"] = $this->getOrder()->getCustomerId();
252
+ $coFields["userCodePayme"] = $codAsoCardHolderWallet;
253
+ if ($ALIGNET_IDACQUIRER == 144 || $ALIGNET_IDACQUIRER == 29) {
254
+ $coFields["mcc"] = $ALIGNET_MCC;
255
+ $coFields['commerceAssociated'] = $commerceAssociated;
256
+ }
257
+ $coFields['descriptionProducts'] = $this->descriptionProducts.' '.Mage::app()->getStore()->getFrontendName();
258
+ $coFields['programmingLanguage'] = 'PHP';
259
+ $coFields['reserved1'] = $purchaseOperationNumber;
260
+ $coFields['reserved2'] = $num_ope_mgt;
261
+ $coFields['reserved3'] = $purchaseAmountFormat;
262
+ $coFields['reserved4'] = $currency_name;
263
+ $coFields['reserved5'] = Mage::getVersion();
264
+ $coFields['reserved6'] = Mage::getConfig()->getNode()->modules->Alignet_Payme->version;
265
+ $coFields['reserved7'] = phpversion();
266
+ $coFields['reserved8'] = php_uname();
267
+ $coFields['reserved9'] = date("d/m/Y");
268
+ $coFields['reserved10'] = date("H:i:s");
269
+ $coFields['purchaseVerification'] = $purchaseVerification;
270
+ return $coFields;
271
+ }
272
+
273
+ /**
274
+ * Get url of Payu payment
275
+ *
276
+ * @return string
277
+ */
278
+ public function getPaymeSharedUrl()
279
+ {
280
+ $ALIGNET_URLTPV = Mage::getStoreConfig('payment/payme_shared/ALIGNET_URLTPV');
281
+
282
+ $url = 'https://integracion.alignetsac.com/VPOS2/faces/pages/startPayme.xhtml';
283
+
284
+ if($ALIGNET_URLTPV == 1) {
285
+ $url = 'https://vpayment.verifika.com/VPOS2/faces/pages/startPayme.xhtml';
286
+ }
287
+
288
+ return $url;
289
+ }
290
+
291
+
292
+ /**
293
+ * Get debug flag
294
+ *
295
+ * @return string
296
+ */
297
+ public function getDebug()
298
+ {
299
+ return Mage::getStoreConfig('payment/payme_shared/ALIGNET_DEBUG');
300
+ }
301
+
302
+ public function capture(Varien_Object $payment, $amount)
303
+ {
304
+ $payment->setStatus(self::STATUS_APPROVED)
305
+ ->setLastTransId($this->getTransactionId());
306
+
307
+ return $this;
308
+ }
309
+
310
+ public function cancel(Varien_Object $payment)
311
+ {
312
+ $payment->setStatus(self::STATUS_DECLINED)
313
+ ->setLastTransId($this->getTransactionId());
314
+
315
+ return $this;
316
+ }
317
+
318
+ /**
319
+ * parse response POST array from gateway page and return payment status
320
+ *
321
+ * @return bool
322
+ */
323
+ public function parseResponse()
324
+ {
325
+
326
+ return true;
327
+
328
+ }
329
+
330
+ /**
331
+ * Return redirect block type
332
+ *
333
+ * @return string
334
+ */
335
+ public function getRedirectBlockType()
336
+ {
337
+ return $this->_redirectBlockType;
338
+ }
339
+
340
+ /**
341
+ * Return payment method type string
342
+ *
343
+ * @return string
344
+ */
345
+ public function getPaymentMethodType()
346
+ {
347
+ return $this->_paymentMethod;
348
+ }
349
+
350
+
351
+ public function getResponseOperation($response) {
352
+ $authorizationResult = trim($response['authorizationResult']) == "" ? "-" : $response['authorizationResult'];
353
+ $authorizationCode = trim($response['authorizationCode']) == "" ? "-" : $response['authorizationCode'];
354
+ $errorCode = trim($response['errorCode']) == "" ? "-" : $response['errorCode'];
355
+ $errorMessage = trim($_POST['errorMessage']) == "" ? "-" : $_POST['errorMessage'];
356
+ $bin = trim($response['bin']) == "" ? "-" : $response['bin'];
357
+ $brand = trim($response['brand']) == "" ? "-" : $response['brand'];
358
+ $paymentReferenceCode = trim($response['paymentReferenceCode']) == "" ? "-" : $response['paymentReferenceCode'];
359
+ $reserved1 = trim($response['reserved1']) == "" ? "-" : $response['reserved1'];
360
+ $reserved2 = trim($response['reserved2']) == "" ? "-" : $response['reserved2'];
361
+ $reserved3 = trim($response['reserved3']) == "" ? "-" : $response['reserved3'];
362
+ $reserved4 = trim($response['reserved4']) == "" ? "-" : $response['reserved4'];
363
+ $order = Mage::getModel('sales/order');
364
+ if ($authorizationResult == '00') {
365
+ $fechaHora = $response['reserved9'] . " " . $response['reserved9'];
366
+ $message = Mage::helper('payme')->__('Número de Operación de Compra') . ": " . $reserved1 . " | ";
367
+ $message .= Mage::helper('payme')->__('Resultado de la Operación: Operación Autorizada') . " | ";
368
+ $message .= Mage::helper('payme')->__('Fecha y Hora de la Operación') . ": " . $fechaHora . " | ";
369
+ $message .= Mage::helper('payme')->__('Monto') . ": " . $reserved3 . " | ";
370
+ $message .= Mage::helper('payme')->__('Moneda') . ": " . $reserved4 . " | ";
371
+ $message .= Mage::helper('payme')->__('Marca de la Tarjeta') . ": " . $brand . " | ";
372
+ $message .= Mage::helper('payme')->__('Número de Tarjeta') . ": " . $paymentReferenceCode . "";
373
+ $order->loadByIncrementId($reserved2);
374
+ /*$order->setState(Mage_Sales_Model_Order::STATE_COMPLETE, true);*/
375
+ $order->setData('state', "Complete");
376
+ $order->setStatus("Complete");
377
+ $history = $order->addStatusHistoryComment(Mage::helper('payme')->__('El estado del pedido: "Complete"'), false);
378
+ $history = $order->addStatusHistoryComment($message, false);
379
+ $history->setIsCustomerNotified(false);
380
+ $order->save();
381
+ $order->sendNewOrderEmail();
382
+ return 'checkout/onepage/success';
383
+ } elseif ($authorizationResult == '01'){
384
+ $fechaHora = date("d/m/Y H:i:s");
385
+ $message = Mage::helper('payme')->__('Número de Operación de Compra') . ": " . $reserved1 . " | ";
386
+ $message .= Mage::helper('payme')->__('Resultado de la Operación: Denegada') . " | ";
387
+ $message .= Mage::helper('payme')->__('Fecha y Hora de la Operación') . ": " . $fechaHora . " | ";
388
+ $message .= Mage::helper('payme')->__('Monto') . ": " . $reserved3 . " | ";
389
+ $message .= Mage::helper('payme')->__('Moneda') . ": " . $reserved4 . " | ";
390
+ $message .= Mage::helper('payme')->__('Marca de la Tarjeta') . ": " . $brand . " | ";
391
+ $message .= Mage::helper('payme')->__('Número de Tarjeta') . ": " . $paymentReferenceCode . "";
392
+ $order->loadByIncrementId($reserved2);
393
+ $order->setState(Mage_Sales_Model_Order::STATE_CANCELED, true);
394
+ $history = $order->addStatusHistoryComment($message, false);
395
+ $history->setIsCustomerNotified(false);
396
+ $this->updateInventory($reserved2);
397
+ $order->cancel()->save();
398
+ return 'checkout/onepage/failure';
399
+ } elseif ($authorizationResult == '05') {
400
+ $fechaHora = date("d/m/Y H:i:s");
401
+ $message = Mage::helper('payme')->__('Número de Operación de Compra') . ": " . $reserved1 . " | ";
402
+ $message .= Mage::helper('payme')->__('Resultado de la Operación: Rechazada') . " | ";
403
+ $message .= Mage::helper('payme')->__('Detalle de la transacción') . ": " . $errorMessage . " | ";
404
+ $message .= Mage::helper('payme')->__('Fecha y Hora de la Operación') . ": " . $fechaHora . " | ";
405
+ $message .= Mage::helper('payme')->__('Monto') . ": " . $reserved3 . " | ";
406
+ $message .= Mage::helper('payme')->__('Moneda') . ": " . $reserved4 . " | ";
407
+ $message .= Mage::helper('payme')->__('Marca de la Tarjeta') . ": " . $brand . " | ";
408
+ $message .= Mage::helper('payme')->__('Número de Tarjeta') . ": " . $paymentReferenceCode . "";
409
+ $order->loadByIncrementId($reserved2);
410
+ $order->setState(Mage_Sales_Model_Order::STATE_CANCELED, true);
411
+ $history = $order->addStatusHistoryComment($message, false);
412
+ $history->setIsCustomerNotified(false);
413
+ $this->updateInventory($reserved2);
414
+ $order->cancel()->save();
415
+ return 'checkout/onepage/failure';
416
+ /*return 'canceled';*/
417
+ } else {
418
+ $fechaHora = date("d/m/Y H:i:s");
419
+ $message = Mage::helper('payme')->__('Número de Operación de Compra') . ": " . $reserved1 . " | ";
420
+ $message .= Mage::helper('payme')->__('Resultado de la Operación: Operación Incompleta') . " | ";
421
+ $message .= Mage::helper('payme')->__('Detalle de la transacción') . ": " . $errorMessage . "";
422
+ $order->loadByIncrementId($reserved2);
423
+ $order->setState(Mage_Sales_Model_Order::STATE_CANCELED, true);
424
+ $history = $order->addStatusHistoryComment($message, false);
425
+ $history->setIsCustomerNotified(false);
426
+ $this->updateInventory($reserved2);
427
+ $order->cancel()->save();
428
+ return 'checkout/onepage/failure';
429
+ }
430
+ }
431
+
432
+ public function updateInventory($orderId) {
433
+ $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
434
+ $items = $order->getAllItems();
435
+ foreach ($items as $itemId => $item) {
436
+ $orderedQuantity = $item->getQtyToInvoice();
437
+ $sku = $item->getSku();
438
+ $product = Mage::getModel('catalog/product')->load($item->getProductId());
439
+ $qtyStock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product->getId())->getQty();
440
+
441
+ $updatedInventory=$qtyStock+ $orderedQuantity;
442
+
443
+ $stockData = $product->getStockItem();
444
+ $stockData->setData('qty',$updatedInventory);
445
+ $stockData->save();
446
+ }
447
+ }
448
+
449
+ }
app/code/local/Alignet/Payme/Model/Source/Ambiente.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Alignet_Payme_Model_Source_Ambiente
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ return array(
8
+ array('value' => '0', 'label' => 'Testing (Desarrollo)'),
9
+ array('value' => '1', 'label' => 'Producción'),
10
+ );
11
+ }
12
+ }
app/code/local/Alignet/Payme/controllers/SharedController.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Alignet_Payme_SharedController extends Alignet_Payme_Controller_Abstract
4
+ {
5
+
6
+ protected $_redirectBlockType = 'payme/shared_redirect';
7
+ protected $_paymentInst = NULL;
8
+
9
+ public function successAction() {
10
+ $response = $this->getRequest()->getPost();
11
+ $retorno = Mage::getModel('payme/shared')->getResponseOperation($response);
12
+ // if ($retorno == 'canceled') {
13
+ // $this->getCheckout()->clear();
14
+ // $this->loadLayout();
15
+ // $this->renderLayout();
16
+ // Zend_Debug::dump($this->getLayout()->getUpdate()->getHandles());
17
+ // } else {
18
+ $this->_redirect($retorno);
19
+ // }
20
+ // return $retorno;
21
+ }
22
+
23
+
24
+
25
+ // public function failureAction()
26
+ // {
27
+
28
+ // $arrParams = $this->getRequest()->getPost();
29
+ // Mage::getModel('payme/shared')->getResponseOperation($arrParams);
30
+ // $this->getCheckout()->clear();
31
+ // $this->_redirect('checkout/onepage/failure');
32
+ // }
33
+
34
+
35
+ // public function canceledAction()
36
+ // {
37
+ // $arrParams = $this->getRequest()->getParams();
38
+
39
+
40
+ // Mage::getModel('payme/shared')->getResponseOperation($arrParams);
41
+
42
+ // $this->getCheckout()->clear();
43
+ // $this->loadLayout();
44
+ // $this->renderLayout();
45
+ // }
46
+
47
+
48
+
49
+
50
+
51
+ }
52
+
53
+
app/code/local/Alignet/Payme/etc/config.xml ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <Alignet_Payme>
5
+ <version>1.0.0</version>
6
+ </Alignet_Payme>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <payme>
11
+ <class>Alignet_Payme_Model</class>
12
+ </payme>
13
+ </models>
14
+ <helpers>
15
+ <payme>
16
+ <class>Alignet_Payme_Helper</class>
17
+ </payme>
18
+ </helpers>
19
+ <blocks>
20
+ <payme>
21
+ <class>Alignet_Payme_Block</class>
22
+ </payme>
23
+ </blocks>
24
+ </global>
25
+ <frontend>
26
+ <secure_url>
27
+ <payme_shared>/payme/shared/</payme_shared>
28
+ </secure_url>
29
+ <routers>
30
+ <payme>
31
+ <use>standard</use>
32
+ <args>
33
+ <module>Alignet_Payme</module>
34
+ <frontName>payme</frontName>
35
+ </args>
36
+ </payme>
37
+ </routers>
38
+ <translate>
39
+ <modules>
40
+ <Alignet_Payme>
41
+ <files>
42
+ <default>Alignet_Payme.csv</default>
43
+ </files>
44
+ </Alignet_Payme>
45
+ </modules>
46
+ </translate>
47
+ <layout>
48
+ <updates>
49
+ <payme>
50
+ <file>payme.xml</file>
51
+ </payme>
52
+ </updates>
53
+ </layout>
54
+ </frontend>
55
+ <adminhtml>
56
+ <translate>
57
+ <modules>
58
+ <Alignet_Payme>
59
+ <files>
60
+ <default>Alignet_Payme.csv</default>
61
+ </files>
62
+ </Alignet_Payme>
63
+ </modules>
64
+ </translate>
65
+ </adminhtml>
66
+ <default>
67
+ <payment>
68
+ <payme_shared>
69
+ <model>payme/shared</model>
70
+ <title>Payme</title>
71
+ <ALIGNET_URLTPV>1</ALIGNET_URLTPV>
72
+ <ALIGNET_DEBUG>1</ALIGNET_DEBUG>
73
+ <ALIGNET_IDENTCOMMERCE></ALIGNET_IDENTCOMMERCE>
74
+ <ALIGNET_KEYWALLET></ALIGNET_KEYWALLET>
75
+ <ALIGNET_IDACQUIRER></ALIGNET_IDACQUIRER>
76
+ <ALIGNET_IDCOMMERCE></ALIGNET_IDCOMMERCE>
77
+ <ALIGNET_MCC></ALIGNET_MCC>
78
+ <ALIGNET_KEY></ALIGNET_KEY>
79
+ </payme_shared>
80
+ </payment>
81
+ </default>
82
+ </config>
app/code/local/Alignet/Payme/etc/system.xml ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+
3
+ <config>
4
+ <sections>
5
+ <payment>
6
+ <groups>
7
+ <payme_shared translate="label" module="payme">
8
+ <label>Pay-me</label>
9
+ <frontend_type>text</frontend_type>
10
+ <sort_order>303</sort_order>
11
+ <show_in_default>1</show_in_default>
12
+ <show_in_website>1</show_in_website>
13
+ <show_in_store>0</show_in_store>
14
+ <fields>
15
+ <active translate="label">
16
+ <label>Habilitar</label>
17
+ <frontend_type>select</frontend_type>
18
+ <source_model>adminhtml/system_config_source_yesno</source_model>
19
+ <sort_order>1</sort_order>
20
+ <show_in_default>1</show_in_default>
21
+ <show_in_website>1</show_in_website>
22
+ <show_in_store>0</show_in_store>
23
+ </active>
24
+ <ALIGNET_URLTPV translate="label">
25
+ <label>Ambiente</label>
26
+ <frontend_type>select</frontend_type>
27
+ <source_model>payme/source_Ambiente</source_model>
28
+ <sort_order>2</sort_order>
29
+ <show_in_default>1</show_in_default>
30
+ <show_in_website>1</show_in_website>
31
+ <show_in_store>0</show_in_store>
32
+ </ALIGNET_URLTPV>
33
+ <ALIGNET_DEBUG translate="label">
34
+ <label>Activar Depuración</label>
35
+ <comment>Activar esta funcionalidad para realizar pruebas. Cuando se activa, se muestran los valores enviados a la pasarela de pagos.</comment>
36
+ <frontend_type>select</frontend_type>
37
+ <source_model>adminhtml/system_config_source_yesno</source_model>
38
+ <sort_order>3</sort_order>
39
+ <show_in_default>1</show_in_default>
40
+ <show_in_website>1</show_in_website>
41
+ <show_in_store>0</show_in_store>
42
+ </ALIGNET_DEBUG>
43
+ <ALIGNET_IDENTCOMMERCE translate="label">
44
+ <label>ID Wallet</label>
45
+ <frontend_type>text</frontend_type>
46
+ <sort_order>4</sort_order>
47
+ <show_in_default>2</show_in_default>
48
+ <show_in_website>2</show_in_website>
49
+ <show_in_store>0</show_in_store>
50
+ </ALIGNET_IDENTCOMMERCE>
51
+ <ALIGNET_KEYWALLET translate="label">
52
+ <label>Clave Wallet</label>
53
+ <frontend_type>text</frontend_type>
54
+ <sort_order>5</sort_order>
55
+ <show_in_default>2</show_in_default>
56
+ <show_in_website>2</show_in_website>
57
+ <show_in_store>0</show_in_store>
58
+ </ALIGNET_KEYWALLET>
59
+ <ALIGNET_IDACQUIRER translate="label">
60
+ <label>ID Adquirente</label>
61
+ <frontend_type>text</frontend_type>
62
+ <sort_order>6</sort_order>
63
+ <show_in_default>2</show_in_default>
64
+ <show_in_website>2</show_in_website>
65
+ <show_in_store>0</show_in_store>
66
+ </ALIGNET_IDACQUIRER>
67
+ <ALIGNET_IDCOMMERCE translate="label">
68
+ <label>ID de Comercio VPOS2</label>
69
+ <frontend_type>text</frontend_type>
70
+ <sort_order>7</sort_order>
71
+ <show_in_default>2</show_in_default>
72
+ <show_in_website>2</show_in_website>
73
+ <show_in_store>0</show_in_store>
74
+ </ALIGNET_IDCOMMERCE>
75
+ <ALIGNET_MCC translate="label">
76
+ <label>MCC</label>
77
+ <frontend_type>text</frontend_type>
78
+ <sort_order>8</sort_order>
79
+ <show_in_default>2</show_in_default>
80
+ <show_in_website>2</show_in_website>
81
+ <show_in_store>0</show_in_store>
82
+ </ALIGNET_MCC>
83
+ <ALIGNET_KEY translate="label">
84
+ <label>Clave VPOS2</label>
85
+ <frontend_type>text</frontend_type>
86
+ <sort_order>9</sort_order>
87
+ <show_in_default>2</show_in_default>
88
+ <show_in_website>2</show_in_website>
89
+ <show_in_store>0</show_in_store>
90
+ </ALIGNET_KEY>
91
+ </fields>
92
+ </payme_shared>
93
+ </groups>
94
+ </payment>
95
+ </sections>
96
+ </config>
app/code/local/Alignet/Payme/restricciones.txt ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ Restricciones en el desarrollado de Magento:
2
+ 1. No se puede validar el formulario de Administración del Módulo Payme.
3
+ 2. Magento bloquea el acceso a los productos del carrito de compras.
4
+ 3. El idioma esta en función al Idioma General de la Tienda configurable en al Administrador. El idioma que selecciona el usuario en el frontend sólo es visual.
5
+ 4. La página de respuesta es la predeterminada de Magento.
6
+ 5. Una ves redirecionada a la pasarela de Alignet, el pedido se registra con estado pendiente. Eliminando los datos de la sesión, y por ende el del carrito.
7
+ 6. Si la operación es cancelada, el carrito no se puede cargar de nuevo pues magento no da acceso a los productos del carrito.
8
+
9
+ Recomendaciones:
10
+ 1. Eliminar la opción 'Debug' en la Administración del Módulo Payme.
app/design/frontend/base/default/template/payme/form.phtml ADDED
@@ -0,0 +1 @@
 
1
+
app/design/frontend/base/default/template/payme/info.phtml ADDED
File without changes
app/design/frontend/base/default/template/payme/shared/canceled.phtml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+
2
+ <div class="page-head">
3
+ <h3><?php echo $this->__('Payment transaction has been canceled.') ?></h3>
4
+ </div>
5
+ <p><?php //echo $this->getErrorMessage() ?>.</p>
6
+ <p><?php echo $this->__('Please <a href="%s">continue shopping</a>.', $this->getContinueShoppingUrl()) ?></p>
app/design/frontend/base/default/template/payme/shared/failure.phtml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+
2
+ <div class="page-head">
3
+ <h3><?php echo $this->__('Order payment has been failed') ?></h3>
4
+ </div>
5
+ <p><?php echo $this->getErrorMessage() ?>.</p>
6
+ <p><?php echo $this->__('Please <a href="%s">continue shopping</a>.', $this->getContinueShoppingUrl()) ?></p>
app/design/frontend/base/default/template/payme/shared/form.phtml ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <fieldset class="form-list">
2
+ <?php
3
+ $_code=$this->getMethodCode();
4
+ $ALIGNET_IDACQUIRER = Mage::getStoreConfig('payment/payme_shared/ALIGNET_IDACQUIRER');
5
+ ?>
6
+ <ul id="payment_form_<?php echo $_code ?>" style="display:none">
7
+ <li>
8
+ <?php
9
+ if ($ALIGNET_IDACQUIRER==144 || $ALIGNET_IDACQUIRER==84 || $ALIGNET_IDACQUIRER==29 || $ALIGNET_IDACQUIRER==10) {
10
+ ?>
11
+ <img src="http://desarrolloweb2r.com/Forma_Pago_Pay-me_PST_PSP.png"/>
12
+ <?php
13
+ } elseif ($ALIGNET_IDACQUIRER==123 || $ALIGNET_IDACQUIRER==23) {
14
+ ?>
15
+ <img src="http://desarrolloweb2r.com/Forma_Pago_Pay-me_BIZLINKS_ALTERNATIVO.png"/>
16
+ <?php
17
+ }
18
+ ?>
19
+ </li>
20
+ </ul>
21
+ </fieldset>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Payme</name>
4
+ <version>2.0.1</version>
5
+ <stability>stable</stability>
6
+ <license>GNU</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Este m&#xF3;dulo facilita pagos mediante tarjeta de cr&#xE9;dito utilizando la plataforma Payme de Alignet.</summary>
10
+ <description>Este m&#xF3;dulo facilita pagos mediante tarjeta de cr&#xE9;dito utilizando la plataforma Payme de Alignet.</description>
11
+ <notes>Versi&#xF3;n final del m&#xF3;dulo Pay-me para Magento</notes>
12
+ <authors><author><name>Jos&#xE9; Alexander Zapata Ruiz</name><user>josezapataruiz</user><email>josezapataruiz@outlook.com</email></author></authors>
13
+ <date>2016-02-13</date>
14
+ <time>00:42:31</time>
15
+ <contents><target name="magelocal"><dir name="Alignet"><dir name="Payme"><dir name="Block"><dir name="Shared"><file name="Form.php" hash="b37f8154ec6e7f9feb9ae88886d6f12c"/><file name="Redirect.php" hash="d813fc6bd2b4d008a77e9b91a38defb7"/></dir></dir><dir name="Controller"><file name="Abstract.php" hash="bf265579912ab96ddfe35b5f7814608b"/></dir><dir name="Helper"><file name="Data.php" hash="9404bfcb67c1fbe45e65d17f98f682d5"/></dir><dir name="Model"><file name="Shared-org.php" hash="869a23c530290c145ab11034efd3a415"/><file name="Shared.php" hash="c5101c8dd62cbc3f735d018170d0226d"/><dir name="Source"><file name="Ambiente.php" hash="6668aff0de4375c3068d0cfa44a97591"/></dir></dir><dir name="controllers"><file name="SharedController.php" hash="4b9d75c6120d9ef08b25b0e55cc4a896"/></dir><dir name="etc"><file name="config.xml" hash="48c0fa6b919abf81fb0dde16d75f4995"/><file name="system.xml" hash="9ffcbcf2b4af6b514db6df0172ecea3d"/></dir><file name="restricciones.txt" hash="548e1a10a261e95221cb102b5bb0b111"/></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="payme"><file name="form.phtml" hash="68b329da9893e34099c7d8ad5cb9c940"/><file name="info.phtml" hash="d41d8cd98f00b204e9800998ecf8427e"/><dir name="shared"><file name="canceled.phtml" hash="bdef89131c08a83d3c1742399d58b433"/><file name="failure.phtml" hash="a54ece778621c5e2b35f4983923bfeb3"/><file name="form.phtml" hash="eb8baadc62d27620ad14361ec5a8bed2"/></dir></dir></dir></dir></dir></dir><dir name="modules"><file name="Alignet_Payme.xml" hash=""/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.0.0</min><max>7.0.0</max></php></required></dependencies>
18
+ </package>