Pagantis_Pagantis - Version 2.0.1

Version Notes

First public release

Download this release

Release Info

Developer Albert Fatsini
Extension Pagantis_Pagantis
Version 2.0.1
Comparing to
See all releases


Version 2.0.1

Files changed (31) hide show
  1. app/code/community/Pagantis/Pagantis/Block/Adminhtml/System/Config/Fieldset/Payment.php +27 -0
  2. app/code/community/Pagantis/Pagantis/Block/Form.php +63 -0
  3. app/code/community/Pagantis/Pagantis/Block/Redirect.php +36 -0
  4. app/code/community/Pagantis/Pagantis/Helper/Data.php +237 -0
  5. app/code/community/Pagantis/Pagantis/Model/Currency.php +17 -0
  6. app/code/community/Pagantis/Pagantis/Model/Observer.php +111 -0
  7. app/code/community/Pagantis/Pagantis/Model/Payment.php +108 -0
  8. app/code/community/Pagantis/Pagantis/Model/Source/Payment/Currency.php +49 -0
  9. app/code/community/Pagantis/Pagantis/Model/Source/Payment/Environment.php +48 -0
  10. app/code/community/Pagantis/Pagantis/Model/Webservice/Client.php +116 -0
  11. app/code/community/Pagantis/Pagantis/Model/Webservice/Paymentrequest.php +76 -0
  12. app/code/community/Pagantis/Pagantis/Model/Webservice/Request.php +353 -0
  13. app/code/community/Pagantis/Pagantis/Model/Webservice/Requestloan.php +421 -0
  14. app/code/community/Pagantis/Pagantis/Model/Webservice/Response.php +15 -0
  15. app/code/community/Pagantis/Pagantis/controllers/PagantisController.php +163 -0
  16. app/code/community/Pagantis/Pagantis/etc/config.xml +122 -0
  17. app/code/community/Pagantis/Pagantis/etc/system.xml +212 -0
  18. app/code/community/Pagantis/Pagantis/sql/pagantis_setup/mysql4-install-1.0.0.php +7 -0
  19. app/design/adminhtml/default/default/layout/pagantis.xml +8 -0
  20. app/design/frontend/base/default/layout/pagantis.xml +8 -0
  21. app/design/frontend/base/default/template/pagantis/form.phtml +22 -0
  22. app/design/frontend/base/default/template/pagantis/pagantis.phtml +42 -0
  23. app/design/frontend/base/default/template/pagantis/redirect.phtml +7 -0
  24. app/etc/modules/Pagantis_Pagantis.xml +10 -0
  25. package.xml +18 -0
  26. skin/adminhtml/base/default/pagantis.css +6 -0
  27. skin/adminhtml/default/default/images/pagantis/logopagamastarde.png +0 -0
  28. skin/adminhtml/default/default/images/pagantis/pagantis.png +0 -0
  29. skin/frontend/base/default/images/pagantis/logopagamastarde.png +0 -0
  30. skin/frontend/base/default/images/pagantis/pagantis-fav.png +0 -0
  31. skin/frontend/base/default/images/pagantis/pagantis.png +0 -0
app/code/community/Pagantis/Pagantis/Block/Adminhtml/System/Config/Fieldset/Payment.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Pagantis_Pagantis payment form
5
+ *
6
+ * @package Pagantis_Pagantis
7
+ * @copyright Copyright (c) 2015 Yameveo (http://www.yameveo.com)
8
+ * @author Yameveo <yameveo@yameveo.com>
9
+ * @link http://www.yameveo.com
10
+ */
11
+ class Pagantis_Pagantis_Block_Adminhtml_System_Config_Fieldset_Payment
12
+ extends Mage_Adminhtml_Block_System_Config_Form_Fieldset
13
+ {
14
+
15
+ /**
16
+ * Return header comment part of html for payment solution
17
+ *
18
+ * @param Varien_Data_Form_Element_Abstract $element
19
+ * @return string
20
+ */
21
+ protected function _getHeaderCommentHtml($element)
22
+ {
23
+ return '<div class="adminLogoPagantis"></div>';
24
+ }
25
+
26
+
27
+ }
app/code/community/Pagantis/Pagantis/Block/Form.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Pagantis_Pagantis payment form
5
+ *
6
+ * @package Pagantis_Pagantis
7
+ * @copyright Copyright (c) 2015 Yameveo (http://www.yameveo.com)
8
+ * @author Yameveo <yameveo@yameveo.com>
9
+ * @link http://www.yameveo.com
10
+ */
11
+ class Pagantis_Pagantis_Block_Form extends Mage_Payment_Block_Form
12
+ {
13
+
14
+ protected function _construct()
15
+ {
16
+
17
+ $title="Financiación:";
18
+ $session = Mage::getSingleton('checkout/session');
19
+ $mark = Mage::getConfig()->getBlockClassName('core/template');
20
+ $mark = new $mark;
21
+ $mark->setData('inst2',$this->instAmount(2));
22
+ $mark->setData('inst3',$this->instAmount(3));
23
+ $mark->setData('inst4',$this->instAmount(4));
24
+ $mark->setData('inst5',$this->instAmount(5));
25
+ $mark->setData('inst6',$this->instAmount(6));
26
+ $mark->setTemplate('pagantis/form.phtml');
27
+ $this->setTemplate('pagantis/pagantis.phtml')
28
+ ->setMethodLabelAfterHtml($mark->toHtml())
29
+ ->setMethodTitle($title)
30
+
31
+ ;
32
+ return parent::_construct();
33
+ }
34
+
35
+ /*
36
+ * function instAmount
37
+ * calculate the price of the installment
38
+ * param $amount : amount in cents of the total loan
39
+ * param $num_installments: number of installments, integer
40
+ * return float with amount of the installment
41
+ */
42
+ protected function instAmount ($num_installments) {
43
+ $quote = Mage::getModel('checkout/session')->getQuote();
44
+ $quoteData= $quote->getData();
45
+ $amount=$quoteData['grand_total']*100;
46
+ $config = Mage::getStoreConfig('payment/pagantis');
47
+ $discount = $config['discount'];
48
+ if ( $discount ){
49
+ $result= ($amount/100) / $num_installments;
50
+ }else{
51
+ $r = 0.25/365; #daily int
52
+ $X = $amount/100; #total loan
53
+ $aux = 1; #first inst value
54
+ for ($i=0; $i<= $num_installments-2;$i++) {
55
+ $aux = $aux + pow(1/(1+$r) ,(45+30*$i));
56
+ }
57
+ $result= (float)($X/$aux);
58
+ }
59
+ //add result to template
60
+ return $result;
61
+ }
62
+
63
+ }
app/code/community/Pagantis/Pagantis/Block/Redirect.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Pagantis_Pagantis payment form
5
+ *
6
+ * @package Pagantis_Pagantis
7
+ * @copyright Copyright (c) 2015 Yameveo (http://www.yameveo.com)
8
+ * @author Yameveo <yameveo@yameveo.com>
9
+ * @link http://www.yameveo.com
10
+ */
11
+ class Pagantis_Pagantis_Block_Redirect extends Mage_Core_Block_Template
12
+ {
13
+
14
+ protected function _construct()
15
+ {
16
+ parent::_construct();
17
+ $helperPagantis = Mage::helper('pagantis_pagantis');
18
+ $urlPagantis = $helperPagantis->getUrlPagantis();
19
+ $paymentMethod = Mage::getModel('pagantis_pagantis/payment');
20
+ $form = new Varien_Data_Form();
21
+
22
+
23
+ $form->setAction($urlPagantis)
24
+ ->setId('pagantis_pagantis_checkout')
25
+ ->setLabel('Pagantis')
26
+ ->setMethod('POST')
27
+ ->setUseContainer(true);
28
+
29
+ foreach ($paymentMethod->getFormFields() as $field => $value) {
30
+ $form->addField($field, 'hidden', array('name' => $field, 'value' => $value));
31
+ }
32
+ $form->addField('submitButton', 'submit', array('name' => 'submitButton', 'value' => 'Continue'));
33
+ $this->setFormRedirect($form->toHtml());
34
+ }
35
+
36
+ }
app/code/community/Pagantis/Pagantis/Helper/Data.php ADDED
@@ -0,0 +1,237 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Pagantis_Pagantis Helper
5
+ *
6
+ * @package Pagantis_Pagantis
7
+ * @copyright Copyright (c) 2015 Yameveo (http://www.yameveo.com)
8
+ * @author Yameveo <yameveo@yameveo.com>
9
+ * @link http://www.yameveo.com
10
+ */
11
+ class Pagantis_Pagantis_Helper_Data extends Mage_Core_Helper_Abstract
12
+ {
13
+
14
+ private $languages = array(
15
+ 'es_ES' => 'es',
16
+ 'en_US' => 'en',
17
+ 'en_UK' => 'en',
18
+ 'ca_ES' => 'ca',
19
+ 'eu_ES' => 'es',
20
+ 'gl_ES' => 'es',
21
+ 'fr_FR' => 'fr',
22
+ 'it_IT' => 'it',
23
+ 'ru_RU' => 'ru'
24
+ );
25
+
26
+ public function __construct()
27
+ {
28
+ $this->_config = Mage::getStoreConfig('payment/pagantis');
29
+ }
30
+
31
+ /**
32
+ * Restore last active quote based on checkout session
33
+ *
34
+ * @return bool True if quote restored successfully, false otherwise
35
+ */
36
+ public function restoreQuote()
37
+ {
38
+ $lastOrderId = $this->_getCheckoutSession()->getLastRealOrderId();
39
+ if ($lastOrderId) {
40
+ $order = Mage::getModel('sales/order')->loadByIncrementId($lastOrderId);
41
+ if ($order->getId()) {
42
+ $quote = $this->_getQuote($order->getQuoteId());
43
+ if ($quote->getId()) {
44
+ $quote->setIsActive(1)
45
+ ->setReservedOrderId(null)
46
+ ->save();
47
+ $this->_getCheckoutSession()
48
+ ->replaceQuote($quote)
49
+ ->unsLastRealOrderId();
50
+ return true;
51
+ }
52
+ }
53
+ }
54
+ return false;
55
+ }
56
+
57
+ /**
58
+ * Return checkout session instance
59
+ *
60
+ * @return Mage_Checkout_Model_Session
61
+ */
62
+ protected function _getCheckoutSession()
63
+ {
64
+ return Mage::getSingleton('checkout/session');
65
+ }
66
+
67
+ /**
68
+ * Return sales quote instance for specified ID
69
+ *
70
+ * @param int $quoteId Quote identifier
71
+ * @return Mage_Sales_Model_Quote
72
+ */
73
+ protected function _getQuote($quoteId)
74
+ {
75
+ return Mage::getModel('sales/quote')->load($quoteId);
76
+ }
77
+
78
+
79
+ /**
80
+ * Returns a Request object with common parameters
81
+ * @todo Retrieve language, currency based on config
82
+ * @param float $amount
83
+ * @param string $orderId
84
+ * @param string $localeCode TBD
85
+ * @return Pagantis_Pagantis_Model_Webservice_Request
86
+ */
87
+ public function getRequest($amount, $orderId, $localeCode)
88
+ {
89
+ $language = $this->getConsumerLanguage($localeCode);
90
+ $request = Mage::getModel('pagantis_pagantis/webservice_request');
91
+ $request->setAmount($amount);
92
+ $request->setLanguagePagantis($language);
93
+ $request->setUrlPagantis($this->_config['url_pagantis']);
94
+ $request->setAuthMethod($this->_config['auth_method']);
95
+ $request->setOrderId($orderId);
96
+ $request->setAmount($amount);
97
+ $request->setDiscount($this->_config['discount']);
98
+ switch($this->_config['environment']) {
99
+ case Pagantis_Pagantis_Model_Webservice_Client::ENV_TESTING:
100
+ $request->setAccountCode($this->_config['account_code_test']);
101
+ $request->setAccountKey($this->_config['account_key_test']);
102
+ //$request->setAccountApiKey($this->_config['account_api_key_test']);
103
+ break;
104
+ case Pagantis_Pagantis_Model_Webservice_Client::ENV_PRODUCTION:
105
+ $request->setAccountCode($this->_config['account_code_real']);
106
+ $request->setAccountKey($this->_config['account_key_real']);
107
+ //$request->setAccountApiKey($this->_config['account_api_key_real']);
108
+ break;
109
+ }
110
+ $request->setUrlOk();
111
+ $request->setUrlKo();
112
+ $request->setCacllbackUrl();
113
+ $request->setFirma();
114
+ return $request;
115
+ }
116
+
117
+ /**
118
+ * Returns a Request object with common parameters
119
+ * @todo Retrieve language, currency based on config
120
+ * @param float $amount
121
+ * @param string $orderId
122
+ * @param string $localeCode TBD
123
+ * @return Pagantis_Pagantis_Model_Webservice_Request
124
+ */
125
+ public function getRequestloan($amount, $orderId, $localeCode)
126
+ {
127
+ $language = $this->getConsumerLanguage($localeCode);
128
+ $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
129
+ $addressId = $order->getShippingAddress()->getId();
130
+
131
+
132
+ $request = Mage::getModel('pagantis_pagantis/webservice_requestloan');
133
+ $request->setOrderId($orderId);
134
+ $request->setAmount($amount);
135
+ $request->setLanguagePagantis($language);
136
+ //$request->setUrlPagantis($this->_config['url_pagantis_mastarde']);
137
+ $request->setUrlPagantis (Pagantis_Pagantis_Model_Payment::PMT_URL);
138
+ $request->setUserData($addressId);
139
+ $request->setOrderItems($orderId);
140
+ $request->setAmount($amount);
141
+ $request->setDiscount($this->_config['discount']);
142
+ switch($this->_config['environment']) {
143
+ case Pagantis_Pagantis_Model_Webservice_Client::ENV_TESTING:
144
+ $request->setAccountCode($this->_config['account_code_test']);
145
+ $request->setAccountKey($this->_config['account_key_test']);
146
+ break;
147
+ case Pagantis_Pagantis_Model_Webservice_Client::ENV_PRODUCTION:
148
+ $request->setAccountCode($this->_config['account_code_real']);
149
+ $request->setAccountKey($this->_config['account_key_real']);
150
+ break;
151
+ }
152
+ $request->setUrlOk();
153
+ $request->setUrlKo();
154
+ $request->setCacllbackUrl();
155
+ $request->setFirma();
156
+
157
+ return $request;
158
+ }
159
+
160
+ /**
161
+ * Returns a Request object with common parameters
162
+ * @todo Retrieve language, currency based on config
163
+ * @param float $amount
164
+ * @param string $orderId
165
+ * @param string $localeCode TBD
166
+ * @return Pagantis_Pagantis_Model_Webservice_Request
167
+ */
168
+ public function getTransactionInfo($transaction)
169
+ {
170
+ $paymentRequest = Mage::getModel('pagantis_pagantis/webservice_paymentrequest');
171
+ switch($this->_config['environment']) {
172
+ case Pagantis_Pagantis_Model_Webservice_Client::ENV_TESTING:
173
+ $paymentRequest->setBearer($this->_config['account_api_key_test']);
174
+ break;
175
+ case Pagantis_Pagantis_Model_Webservice_Client::ENV_PRODUCTION:
176
+ $paymentRequest->setBearer($this->_config['account_api_key_real']);
177
+ break;
178
+ }
179
+ $paymentRequest->setTransaction($transaction);
180
+ $client = Mage::getModel('pagantis_pagantis/webservice_client');
181
+ $result = $client->getCurlResultPaymentRequest($paymentRequest);
182
+ return $result;
183
+ }
184
+
185
+
186
+ public function getUrlPagantis() {
187
+
188
+ return Pagantis_Pagantis_Model_Payment::PMT_URL;
189
+ //allways same url, no need to make this check
190
+ /*
191
+ $paymentDetails = $this->_getCheckoutSession()->getPaymentMethodDetail();
192
+ switch($paymentDetails) {
193
+ case Pagantis_Pagantis_Model_Payment::PAYMENT_UNIQUE:
194
+ return $this->_config['url_pagantis'];
195
+ break;
196
+ case Pagantis_Pagantis_Model_Payment::PAYMENT_LOAN:
197
+ return $this->_config['url_pagantis_mastarde'];
198
+ break;
199
+ }
200
+ */
201
+ }
202
+
203
+ /**
204
+ * Returns a string with the corresponding CECA consumer language, given a ISO locale code
205
+ * Eg. es_ES
206
+ *
207
+ * @param $localeCode
208
+ * @return mixed
209
+ */
210
+ private function getConsumerLanguage($localeCode)
211
+ {
212
+ return $this->languages[$localeCode];
213
+ }
214
+
215
+ /**
216
+ * @param $states
217
+ * @param $statuses
218
+ * @return mixed
219
+ */
220
+ public function getOrdersToExport($states)
221
+ {
222
+ $methodPayment = $this->_config['title'];
223
+
224
+ $pendingProcessingOrdersPagantis = Mage::getModel('sales/order')
225
+ ->getCollection()
226
+ ->join(
227
+ array('payment' => 'sales/order_payment'),
228
+ 'main_table.entity_id=payment.parent_id',
229
+ array('payment_method' => 'payment.method')
230
+ );
231
+ $pendingProcessingOrdersPagantis->addFieldToFilter('payment.method',array('like'=>$methodPayment))
232
+ ->addFieldToFilter('state',array('in'=>$states));
233
+
234
+ return $pendingProcessingOrdersPagantis;
235
+ }
236
+
237
+ }
app/code/community/Pagantis/Pagantis/Model/Currency.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @package Pagantis_Pagantis
5
+ * @copyright Copyright (c) 2015 Yameveo (http://www.yameveo.com)
6
+ * @author Yameveo <yameveo@yameveo.com>
7
+ * @link http://www.yameveo.com
8
+ */
9
+
10
+ class Pagantis_Pagantis_Model_Currency
11
+ {
12
+
13
+ const EUR = 'EUR';
14
+ const USD = 'USD';
15
+ const GBP = 'GBP';
16
+
17
+ }
app/code/community/Pagantis/Pagantis/Model/Observer.php ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Observer for cron jobs
5
+ *
6
+ * @package Pagantis_Pagantis
7
+ * @author Yameveo <support@yameveo.com>
8
+ * @link http://www.yameveo.com
9
+ */
10
+ class Pagantis_Pagantis_Model_Observer
11
+ {
12
+
13
+ const PAGANTIS_TR_ERROR = 'Error';
14
+
15
+
16
+ public function exportOrders()
17
+ {
18
+ $start = $this->chrono();
19
+ $startGetCollection = $this->chrono();
20
+
21
+ $orders = Mage::helper('pagantis_pagantis')->getOrdersToExport(array(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT));//,Mage_Sales_Model_Order::STATE_PROCESSING));//, array(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT,Mage_Sales_Model_Order::STATE_PROCESSING));
22
+
23
+ $endGetCollection = $this->chrono();
24
+ $chronoCollection = round($endGetCollection - $startGetCollection, 3);
25
+ Mage::log("Loading orders collection executed in $chronoCollection seconds.", Zend_Log::DEBUG, $this->_logFile);
26
+ $ordersCount = $orders->count();
27
+ Mage::log("Exporting $ordersCount orders", Zend_Log::DEBUG, $this->_logFile);
28
+
29
+ $count = 1;
30
+ $result = array();
31
+ $orderCanceled = 0;
32
+ $orderProcessing = 0;
33
+ foreach ($orders as $order) {
34
+ $transaction = $order->getPagantisTransaction();
35
+ if ($transaction) {
36
+ $paymentRequestResult = Mage::helper('pagantis_pagantis')->getTransactionInfo($transaction);
37
+ if (!$paymentRequestResult['paid']) {
38
+ $order->setState(Mage_Sales_Model_Order::STATE_CANCELED,true);
39
+ $order->save();
40
+ $orderCanceled++;
41
+ } else {
42
+ // @todo move this try in helper
43
+ try {
44
+ $sendMail = (int) Mage::getStoreConfig('payment/pagantis/sendmail');
45
+ $createInvoice = (int) Mage::getStoreConfig('payment/pagantis/invoice');
46
+ if ($order->getId()) {
47
+ //if ($response->isDsValid()) {
48
+ $orderStatus = Mage_Sales_Model_Order::STATE_PROCESSING;
49
+ if ($order->canInvoice() && $createInvoice) {
50
+ $invoice = $this->_createInvoice($order);
51
+ $comment = Mage::helper('pagantis_pagantis')->__('Authorized transaction. Created invoice %s', $invoice->getIncrementId());
52
+ } else {
53
+ $comment = Mage::helper('pagantis_pagantis')->__('Authorized transaction, but invoice not created');
54
+ }
55
+ $order->setState($orderStatus, $orderStatus, $comment, true);
56
+ $order->save();
57
+ if ($sendMail) {
58
+ if ($orderStatus == Mage_Sales_Model_Order::STATE_PROCESSING) {
59
+ $order->sendNewOrderEmail();
60
+ } else {
61
+ $order->sendOrderUpdateEmail(true);
62
+ }
63
+ }
64
+ }
65
+ $orderProcessing++;
66
+ } catch (Exception $e) {
67
+ Mage::logException($e);
68
+ }
69
+ }
70
+ }
71
+ }
72
+ return "Updated " . $orderCanceled . " orders in steta Canceled and " . $orderProcessing . " orders in Processing";
73
+ }
74
+
75
+ /**
76
+ * Create an invoice for the order and send an email
77
+ * @todo move to helper
78
+ * @param Mage_Sales_Model_Order $order
79
+ * @return Mage_Sales_Model_Order_Invoice
80
+ */
81
+ private function _createInvoice($order)
82
+ {
83
+ $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
84
+ if (!$invoice->getTotalQty()) {
85
+ Mage::throwException(Mage::helper('core')->__('Cannot create an invoice without products.'));
86
+ }
87
+
88
+ $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
89
+ $invoice->register();
90
+ $transactionSave = Mage::getModel('core/resource_transaction')
91
+ ->addObject($invoice)
92
+ ->addObject($invoice->getOrder());
93
+
94
+ $transactionSave->save();
95
+ $invoice->sendEmail();
96
+ return $invoice;
97
+ }
98
+
99
+ /**
100
+ * Returns the actual microtime in seconds
101
+ * @return float seconds
102
+ */
103
+ protected function chrono()
104
+ {
105
+ list($msec, $sec) = explode(' ', microtime());
106
+ return ((float)$msec + (float)$sec);
107
+ }
108
+
109
+
110
+
111
+ }
app/code/community/Pagantis/Pagantis/Model/Payment.php ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Payment class
5
+ *
6
+ * @package Pagantis_Pagantis
7
+ * @copyright Copyright (c) 2015 Yameveo (http://www.yameveo.com)
8
+ * @author Yameveo <yameveo@yameveo.com>
9
+ * @link http://www.yameveo.com
10
+ */
11
+
12
+ class Pagantis_Pagantis_Model_Payment extends Mage_Payment_Model_Method_Abstract
13
+ {
14
+
15
+ protected $_code = 'pagantis';
16
+ protected $_formBlockType = 'pagantis_pagantis/form';
17
+ protected $_isInitializeNeeded = true;
18
+ protected $_canUseInternal = false;
19
+ protected $_canUseForMultishipping = false;
20
+ protected $_config = null;
21
+
22
+ const PAYMENT_UNIQUE = 'unico';
23
+ const PAYMENT_LOAN = 'financiacion';
24
+ const PMT_URL = 'https://pmt.pagantis.com/v1/installments/';
25
+
26
+ /**
27
+ * Get checkout session namespace
28
+ *
29
+ * @return Mage_Checkout_Model_Session
30
+ */
31
+ public function getCheckout()
32
+ {
33
+ return Mage::getSingleton('checkout/session');
34
+ }
35
+
36
+ /**
37
+ * Get current quote
38
+ *
39
+ * @return Mage_Sales_Model_Quote
40
+ */
41
+ public function getQuote()
42
+ {
43
+ return $this->getCheckout()->getQuote();
44
+ }
45
+
46
+ /**
47
+ * Create main block for standard form
48
+ *
49
+ */
50
+ public function createFormBlock($name)
51
+ {
52
+ $block = $this->getLayout()->createBlock($this->_formBlockType, $name)
53
+ ->setMethod('pagantis')
54
+ ->setPayment($this->getPayment())
55
+ ->setTemplate('pagantis/form.phtml');
56
+
57
+ return $block;
58
+ }
59
+
60
+ /**
61
+ * Return Order place redirect url
62
+ *
63
+ * @return string
64
+ */
65
+ public function getOrderPlaceRedirectUrl()
66
+ {
67
+ return Mage::getUrl('pagantis/pagantis/redirect', array('_secure' => true));
68
+ }
69
+
70
+ /**
71
+ * Instantiate state and set it to state object
72
+ * @param string $paymentAction
73
+ * @param Varien_Object
74
+ */
75
+ public function initialize($paymentAction, $stateObject)
76
+ {
77
+ $state = Mage_Sales_Model_Order::STATE_PENDING_PAYMENT;
78
+ $paymentDetailArray = Mage::app()->getRequest()->getPost('paymentdetail');
79
+ $paymentDetail = $paymentDetailArray[0];
80
+ $this->getCheckout()->setPaymentMethodDetail($paymentDetail);
81
+ $stateObject->setState($state);
82
+ $stateObject->setStatus('pending_payment');
83
+ $stateObject->setIsNotified(false);
84
+ }
85
+
86
+ public function getFormFields()
87
+ {
88
+ $orderIncrementId = $this->getCheckout()->getLastRealOrderId();
89
+ $paymentDetails = $this->getCheckout()->getPaymentMethodDetail();
90
+ $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
91
+ // For EUR last 2 position are considered decimals
92
+ $amount = $order->getTotalDue() * 100;
93
+ $orderId = $order->increment_id;
94
+
95
+ $localeCode = Mage::app()->getLocale()->getLocaleCode();
96
+ switch($paymentDetails) {
97
+ case self::PAYMENT_UNIQUE:
98
+ $request = Mage::helper('pagantis_pagantis')->getRequest($amount, $orderId, $localeCode);
99
+ break;
100
+ case self::PAYMENT_LOAN:
101
+ $request = Mage::helper('pagantis_pagantis')->getRequestloan($amount, $orderId, $localeCode);
102
+ break;
103
+ }
104
+ return $request->toArray();
105
+ }
106
+
107
+
108
+ }
app/code/community/Pagantis/Pagantis/Model/Source/Payment/Currency.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Currencies for Pagantis_Pagantis config
5
+ *
6
+ * @package Pagantis_Pagantis
7
+ * @copyright Copyright (c) 2015 Yameveo (http://www.yameveo.com)
8
+ * @author Yameveo <yameveo@yameveo.com>
9
+ * @link http://www.yameveo.com
10
+ */
11
+ class Pagantis_Pagantis_Model_Source_Payment_Currency
12
+ {
13
+
14
+ /**
15
+ * Options list as array
16
+ *
17
+ * @var array
18
+ */
19
+ protected $_options = null;
20
+
21
+ /**
22
+ * Retrieve all currencies
23
+ *
24
+ * @return array
25
+ */
26
+ public function getAllOptions()
27
+ {
28
+ if ($this->_options === null) {
29
+ $this->_options = array();
30
+
31
+ $this->_options[] = array('label' => Mage::helper('pagantis_pagantis')->__('Euro'), 'value' => Pagantis_Pagantis_Model_Currency::EUR);
32
+ $this->_options[] = array('label' => Mage::helper('pagantis_pagantis')->__('Pound'), 'value' => Pagantis_Pagantis_Model_Currency::GBP);
33
+ $this->_options[] = array('label' => Mage::helper('pagantis_pagantis')->__('US Dollar'), 'value' => Pagantis_Pagantis_Model_Currency::USD);
34
+ }
35
+
36
+ return $this->_options;
37
+ }
38
+
39
+ /**
40
+ * To option array conversion
41
+ *
42
+ * @return array
43
+ */
44
+ public function toOptionArray()
45
+ {
46
+ return $this->getAllOptions();
47
+ }
48
+
49
+ }
app/code/community/Pagantis/Pagantis/Model/Source/Payment/Environment.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Enviroments for Pagantis_Pagantis config
5
+ *
6
+ * @package Pagantis_Pagantis
7
+ * @copyright Copyright (c) 2015 Yameveo (http://www.yameveo.com)
8
+ * @author Yameveo <yameveo@yameveo.com>
9
+ * @link http://www.yameveo.com
10
+ */
11
+ class Pagantis_Pagantis_Model_Source_Payment_Environment
12
+ {
13
+
14
+ /**
15
+ * Options list as array
16
+ *
17
+ * @var array
18
+ */
19
+ protected $_options = null;
20
+
21
+ /**
22
+ * Retrieve all environments
23
+ *
24
+ * @return array
25
+ */
26
+ public function getAllOptions()
27
+ {
28
+ if ($this->_options === null) {
29
+ $this->_options = array();
30
+
31
+ $this->_options[] = array('label' => Mage::helper('pagantis_pagantis')->__('Real'), 'value' => Pagantis_Pagantis_Model_Webservice_Client::ENV_PRODUCTION);
32
+ $this->_options[] = array('label' => Mage::helper('pagantis_pagantis')->__('Testing'), 'value' => Pagantis_Pagantis_Model_Webservice_Client::ENV_TESTING);
33
+ }
34
+
35
+ return $this->_options;
36
+ }
37
+
38
+ /**
39
+ * To option array conversion
40
+ *
41
+ * @return array
42
+ */
43
+ public function toOptionArray()
44
+ {
45
+ return $this->getAllOptions();
46
+ }
47
+
48
+ }
app/code/community/Pagantis/Pagantis/Model/Webservice/Client.php ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Pagantis_Pagantis_Model_Webservice_Client
5
+ *
6
+ * @package Pagantis_Pagantis
7
+ * @copyright Copyright (c) 2015 Yameveo (http://www.yameveo.com)
8
+ * @author Yameveo <yameveo@yameveo.com>
9
+ * @link http://www.yameveo.com
10
+ */
11
+
12
+ class Pagantis_Pagantis_Model_Webservice_Client
13
+ {
14
+
15
+ // Environments
16
+ const ENV_TESTING = 'testing';
17
+ const ENV_PRODUCTION = 'production';
18
+
19
+
20
+
21
+
22
+ private $_pathConfig;
23
+
24
+ /**
25
+ * Pagantis_Pagantis_Model_Webservice_Client constructor
26
+ * @param array $path_config
27
+ */
28
+ public function __construct($path_config = null)
29
+ {
30
+ if ($path_config != null) {
31
+ $this->_pathConfig = $path_config['config'];
32
+ }
33
+ $this->_session = Mage::getSingleton('checkout/session');
34
+ }
35
+
36
+ /**
37
+ * Send a request and process response
38
+ *
39
+ * @param Pagantis_Pagantis_Model_Webservice_Request $request
40
+ * @return Pagantis_Pagantis_Model_Webservice_Response
41
+ */
42
+ public function makeRequest(Pagantis_Pagantis_Model_Webservice_Request $request)
43
+ {
44
+ $response = $this->sendRequest($request);
45
+ return $this->processResponse($response);
46
+ }
47
+
48
+ /**
49
+ * Send a request and process response
50
+ *
51
+ * @param Pagantis_Pagantis_Model_Webservice_Request $request
52
+ * @return array
53
+ */
54
+ public function getCurlResultPaymentRequest(Pagantis_Pagantis_Model_Webservice_PaymentRequest $paymentRequest)
55
+ {
56
+ $bearer = (string)$paymentRequest->getBearer();
57
+ $urlApi = (string)$paymentRequest->getUrlPagantis().$paymentRequest->getTransaction();
58
+
59
+ $crl = curl_init();
60
+
61
+ $header = array();
62
+ $header[] = 'Content-length: 0';
63
+ $header[] = 'Content-type: application/json';
64
+ $header[] = 'Authorization: Bearer '.$bearer;
65
+
66
+ curl_setopt($crl, CURLOPT_HTTPHEADER,$header);
67
+ curl_setopt($crl,CURLOPT_RETURNTRANSFER, 1);
68
+ curl_setopt($crl,CURLOPT_URL, $urlApi);
69
+ $result = json_decode(curl_exec($crl),true);
70
+ curl_close($crl);
71
+ return $result['response'];
72
+ }
73
+
74
+ /**
75
+ * Send a request
76
+ *
77
+ * @param Pagantis_Pagantis_Model_Webservice_Request $request
78
+ * @return Object
79
+ */
80
+ private function sendPaymentRequest(Pagantis_Pagantis_Model_Webservice_PaymentRequest $request)
81
+ {
82
+
83
+ $xmlRequest = $request->toXml();
84
+ $response = $this->trataPeticion(array(
85
+ self::SOAP_REQUEST_WRAPPER => $xmlRequest
86
+ ));
87
+
88
+ return $response;
89
+ }
90
+
91
+ /**
92
+ * Process response
93
+ *
94
+ * @param Pagantis_Pagantis_Model_Webservice_Response $response
95
+ */
96
+ /*private function processResponse($response)
97
+ {
98
+ $response = new Pagantis_Pagantis_Model_Webservice_Response($response->trataPeticionReturn);
99
+ return $response;
100
+ }*/
101
+
102
+ public function getUrl()
103
+ {
104
+ $conf = Mage::getStoreConfig('payment/pagantis');
105
+ $environment = $conf['environment'];
106
+ switch($environment){
107
+ case Pagantis_Pagantis_Model_Webservice_Client::ENV_TESTING:
108
+ return $conf['url_pagantis_test'];
109
+ break;
110
+ case Pagantis_Pagantis_Model_Webservice_Client::ENV_PRODUCTION:
111
+ return $conf['url_pagantis_real'];
112
+ break;
113
+ }
114
+ }
115
+
116
+ }
app/code/community/Pagantis/Pagantis/Model/Webservice/Paymentrequest.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Pagantis_Pagantis_Model_Webservice_Request
5
+ *
6
+ * @package Pagantis_Pagantis
7
+ * @copyright Copyright (c) 2015 Yameveo (http://www.yameveo.com)
8
+ * @author Yameveo <yameveo@yameveo.com>
9
+ * @link http://www.yameveo.com
10
+ */
11
+
12
+ class Pagantis_Pagantis_Model_Webservice_Paymentrequest
13
+ {
14
+ const BASE = 'pagantis/pagantis';
15
+ const URL_PAYMENT_REQUEST = 'https://psp.pagantis.com/api/1/charges/';
16
+
17
+ /**
18
+ * @var string $_urlPagantis Redirect url for payment
19
+ */
20
+ protected $_urlPagantis;
21
+
22
+ /**
23
+ * @var string $_amount Order Amount
24
+ */
25
+ protected $_bearer;
26
+
27
+ /**
28
+ * @var string $_currency Order Amount
29
+ */
30
+ protected $_transaction;
31
+
32
+
33
+
34
+ public function __construct()
35
+ {
36
+ $this->_urlPagantis = self::URL_PAYMENT_REQUEST;
37
+ }
38
+
39
+ /**
40
+ * Assign bearer for call
41
+ * @param string $bearer
42
+ * @throws Exception
43
+ */
44
+ public function setBearer($bearer = '')
45
+ {
46
+ if (strlen(trim($bearer)) > 0) {
47
+ $this->_bearer = $bearer;
48
+ } else {
49
+ throw new \Exception('Missing bearer for call');
50
+ }
51
+ }
52
+
53
+ /**
54
+ * Assign transaction for call
55
+ * @param string $transaction
56
+ * @throws Exception
57
+ */
58
+ public function setTransaction($transaction = '')
59
+ {
60
+ if (strlen(trim($transaction)) > 0) {
61
+ $this->_transaction = $transaction;
62
+ } else {
63
+ throw new \Exception('Missing transaction for call');
64
+ }
65
+ }
66
+
67
+ public function getTransaction(){
68
+ return $this->_transaction;
69
+ }
70
+ public function getBearer(){
71
+ return $this->_bearer;
72
+ }
73
+ public function getUrlPagantis(){
74
+ return $this->_urlPagantis;
75
+ }
76
+ }
app/code/community/Pagantis/Pagantis/Model/Webservice/Request.php ADDED
@@ -0,0 +1,353 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Pagantis_Pagantis_Model_Webservice_Request
5
+ * @package Pagantis_Pagantis
6
+ * @copyright Copyright (c) 2015 Yameveo (http://www.yameveo.com)
7
+ * @author Yameveo <yameveo@yameveo.com>
8
+ * @link http://www.yameveo.com
9
+ */
10
+
11
+ class Pagantis_Pagantis_Model_Webservice_Request
12
+ {
13
+ const BASE = 'pagantis/pagantis';
14
+
15
+ /**
16
+ * @var string $_urlPagantis Redirect url for payment
17
+ */
18
+ protected $_urlPagantis;
19
+
20
+ /**
21
+ * @var string $_amount Order Amount
22
+ */
23
+ protected $_amount;
24
+
25
+ /**
26
+ * @var string $_currency Order Amount
27
+ */
28
+ protected $_currency;
29
+
30
+ /**
31
+ * @var string $_orderId Increment order Id
32
+ */
33
+ protected $_orderId;
34
+ /**
35
+ * @var string $_languagePagantis Force language on bank page
36
+ */
37
+ protected $_languagePagantis;
38
+
39
+ /**
40
+ * @var string $_authMethod Authentication method for payment redirect.
41
+ */
42
+ protected $_authMethod;
43
+
44
+ /**
45
+ * @var string $_accountCode
46
+ */
47
+ protected $_accountCode;
48
+
49
+ /**
50
+ * @var string $accountKey
51
+ */
52
+ protected $_accountKey;
53
+
54
+ /**
55
+ * @var string $_accountApiKey
56
+ */
57
+ protected $_accountApiKey;
58
+
59
+ /**
60
+ * @var string $_urlOk Requerido 500 URL completa.
61
+ */
62
+ protected $_urlOk;
63
+
64
+ /**
65
+ *
66
+ * @var string $_urlKo Requerido 500 URL completa.
67
+ */
68
+ protected $_urlKo;
69
+
70
+ /**
71
+ *
72
+ * @var string $_callback_url Requerido 500 URL completa.
73
+ */
74
+ protected $_callback_url;
75
+
76
+ /**
77
+ * @var string $_firma created by clave_de_firma + account_id + order_id + amount + currency + auth_method + ok_url + nok_url
78
+ */
79
+ protected $_firma;
80
+
81
+ /**
82
+ * @var dicount
83
+ */
84
+ protected $_dicount;
85
+
86
+
87
+ public function __construct()
88
+ {
89
+ $this->_languagePagantis = $this->setLanguagePagantis(); //Por defecto español
90
+ $this->_currency = $this->setCurrency();
91
+ }
92
+
93
+ /**
94
+ * Return the array version of the Request to be sent through the form
95
+ *
96
+ * @return string
97
+ */
98
+ public function toArray()
99
+ {
100
+ $array = array();
101
+ $array['locale'] = $this->_languagePagantis;
102
+ $array['ok_url'] = $this->_urlOk;
103
+ $array['nok_url'] = $this->_urlKo;
104
+ $array['callback_url'] = $this->_callback_url;
105
+ $array['discount'] = $this->_discount;
106
+ //$array['urlPagantis'] = $this->_urlPagantis;
107
+ $array['account_id'] = $this->_accountCode;
108
+ $array['amount'] = $this->_amount;
109
+ $array['auth_method'] = $this->_authMethod;
110
+ $array['currency'] = $this->_currency;
111
+ $array['signature'] = $this->_firma;
112
+ $array['order_id'] = $this->_orderId;
113
+ return $array;
114
+ }
115
+
116
+ /**
117
+ * Assign url for redirect
118
+ * @param string $urlPagantis
119
+ * @throws Exception
120
+ */
121
+ public function setUrlPagantis($urlPagantis = '')
122
+ {
123
+ if (strlen(trim($urlPagantis)) > 0) {
124
+ $this->_urlPagantis = $urlPagantis;
125
+ } else {
126
+ throw new \Exception('Missing url for redirect to page bank');
127
+ }
128
+ }
129
+
130
+ /**
131
+ * Assign url for redirect
132
+ * @param string $urlPagantis
133
+ * @throws Exception
134
+ */
135
+ public function setOrderId($orderId = '')
136
+ {
137
+ if (strlen(trim($orderId)) > 0) {
138
+ $this->_orderId = $orderId;
139
+ } else {
140
+ throw new \Exception('Missing orderId');
141
+ }
142
+ }
143
+
144
+ /**
145
+ * Assign currency for redirect
146
+ * @param string $currency
147
+ * @throws Exception
148
+ */
149
+ public function setCurrency()
150
+ {
151
+ return Pagantis_Pagantis_Model_Currency::EUR;
152
+ }
153
+
154
+ /**
155
+ * Assign url for redirect
156
+ * @param string $urlPagantis
157
+ * @throws Exception
158
+ */
159
+ public function setAmount($amount = '')
160
+ {
161
+ if (strlen(trim($amount)) > 0) {
162
+ $this->_amount = $amount;
163
+ } else {
164
+ throw new \Exception('Missing amount');
165
+ }
166
+ }
167
+
168
+ /**
169
+ * Assign language for bank page
170
+ * @param string $language Language for bank page
171
+ */
172
+ public function setLanguagePagantis($language = 'es')
173
+ {
174
+ return $language;
175
+ }
176
+
177
+ /**
178
+ * Assign authentication method
179
+ * @param string $authMethod Auth method.
180
+ */
181
+ public function setAuthMethod($authMethod = 'SHA1')
182
+ {
183
+ $this->_authMethod = $authMethod;
184
+ }
185
+
186
+ /**
187
+ * Assign account code
188
+ * @param string $accountCode
189
+ * @throws Exception
190
+ */
191
+ public function setAccountCode($accountCode=''){
192
+ if (strlen(trim($accountCode)) > 0) {
193
+ $this->_accountCode = $accountCode;
194
+ } else {
195
+ throw new \Exception('Missing account code');
196
+ }
197
+ }
198
+
199
+ /**
200
+ * Assign discount
201
+ * @param string $discount
202
+ * @throws Exception
203
+ */
204
+ public function setDiscount($discount=''){
205
+ if ($discount == 1) {
206
+ $this->_discount = 'true';
207
+ } else {
208
+ $this->_discount = 'false';
209
+ }
210
+ }
211
+
212
+ /**
213
+ * Assign account key
214
+ * @param string $accountKey
215
+ * @throws Exception
216
+ */
217
+ public function setAccountKey($accountKey=''){
218
+ if (strlen(trim($accountKey)) > 0) {
219
+ $this->_accountKey = $accountKey;
220
+ } else {
221
+ throw new \Exception('Missing account key');
222
+ }
223
+ }
224
+
225
+ /**
226
+ * Assign account key
227
+ * @param string $accountApiKey
228
+ * @throws Exception
229
+ */
230
+ public function setAccountApiKey($accountApiKey=''){
231
+ if (strlen(trim($accountApiKey)) > 0) {
232
+ $this->_accountApiKey = $accountApiKey;
233
+ } else {
234
+ throw new \Exception('Missing account API key');
235
+ }
236
+ }
237
+
238
+ /**
239
+ * @param string $urlok
240
+ * @throws Exception
241
+ */
242
+ public function setUrlOk()
243
+ {
244
+ $urlOk = $this->getUrl('success');
245
+ if (strlen(trim($urlOk)) > 0) {
246
+ $this->_urlOk = $urlOk;
247
+ } else {
248
+ throw new \Exception('UrlOk not defined');
249
+ }
250
+
251
+ }
252
+
253
+ /**
254
+ * @param string $urlnok
255
+ * @throws Exception
256
+ */
257
+ public function setUrlKo($urlKo = '')
258
+ {
259
+ $urlKo = $this->getUrl('cancel');
260
+ if (strlen(trim($urlKo)) > 0) {
261
+ $this->_urlKo = $urlKo;
262
+ } else {
263
+ throw new \Exception('UrlKo not defined');
264
+ }
265
+ }
266
+
267
+ /**
268
+ * @param string $urlnok
269
+ * @throws Exception
270
+ */
271
+ public function setCacllbackUrl($url = '')
272
+ {
273
+ $this->_callback_url=Mage::getBaseUrl()."/pagantis/pagantis/notification";
274
+ }
275
+
276
+ /**
277
+ * Firm generation
278
+ * Generated with SHA1 of _accountKey + _accountCode + _orderId + _amount + _currency + _authMethod + _urlOk + _urlKo
279
+ * @throws Exception
280
+ * @return string
281
+ */
282
+ public function setFirma()
283
+ {
284
+
285
+ if (strlen(trim($textToEncode)) > 0) {
286
+ // Retrieve del SHA1
287
+ $this->_firma = sha1($textToEncode);
288
+ } else {
289
+ throw new Exception('Missing SHA1');
290
+ }
291
+ }
292
+
293
+ //Utilities
294
+ //http://stackoverflow.com/a/9111049/444225
295
+ private function priceToSQL($price)
296
+ {
297
+ $price = preg_replace('/[^0-9\.,]*/i', '', $price);
298
+ $price = str_replace(',', '.', $price);
299
+
300
+ if (substr($price, -3, 1) == '.') {
301
+ $price = explode('.', $price);
302
+ $last = array_pop($price);
303
+ $price = join($price, '') . '.' . $last;
304
+ } else {
305
+ $price = str_replace('.', '', $price);
306
+ }
307
+
308
+ return $price;
309
+ }
310
+
311
+ public function getUrl($path)
312
+ {
313
+ $url = Mage::getUrl(self::BASE . "/$path");
314
+ return Mage::getModel('core/url')->sessionUrlVar($url);
315
+ }
316
+
317
+ /**
318
+ * Converts field names for setters and getters
319
+ *
320
+ * @param string $name
321
+ * @return string
322
+ */
323
+ private function underscore($name)
324
+ {
325
+ $result = strtolower(preg_replace('/(.)([A-Z])/', "$1_$2", $name));
326
+ return $result;
327
+ }
328
+
329
+ /**
330
+ * Checks if received response is correct
331
+ * Clave_encriptacion+MerchantID+AcquirerBIN+TerminalID+Num_operacion+Importe+TipoMoneda+ Exponente+Referencia
332
+ * @param Yameveo_Ceca_Model_Webservice_Response $response
333
+ * @return boolean
334
+ */
335
+ /*public function checkResponseSignature(Pagantis_Pagantis_Model_Webservice_Response $response)
336
+ {
337
+ $txt = $this->_clave_encriptacion;
338
+ $txt .= $response->getMerchantId();
339
+ $txt .= $response->getAcquirerBin();
340
+ $txt .= $response->getTerminalId();
341
+ $txt .= $response->getNumOperacion();
342
+ $txt .= $response->getImporte();
343
+ $txt .= $response->getTipoMoneda();
344
+ $txt .= $response->getExponente();
345
+ $txt .= $response->getReferencia();
346
+
347
+ // Calculate signature
348
+ $signature = sha1($txt);
349
+
350
+ // Compare received signature with calculated
351
+ return strtolower($signature) === strtolower($response->getFirma());
352
+ }*/
353
+ }
app/code/community/Pagantis/Pagantis/Model/Webservice/Requestloan.php ADDED
@@ -0,0 +1,421 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Pagantis_Pagantis_Model_Webservice_Request
5
+ *
6
+ * @package Pagantis_Pagantis
7
+ * @copyright Copyright (c) 2015 Yameveo (http://www.yameveo.com)
8
+ * @author Yameveo <yameveo@yameveo.com>
9
+ * @link http://www.yameveo.com
10
+ */
11
+
12
+ class Pagantis_Pagantis_Model_Webservice_Requestloan
13
+ {
14
+ const BASE = 'pagantis/pagantis';
15
+
16
+ /**
17
+ * @var string $_urlPagantis Redirect url for payment
18
+ */
19
+ protected $_urlPagantis;
20
+
21
+ /**
22
+ * @var string $_amount Order Amount
23
+ */
24
+ protected $_amount;
25
+
26
+ /**
27
+ * @var string $_currency Order Amount
28
+ */
29
+ protected $_currency;
30
+
31
+ /**
32
+ * @var string $_orderId Increment order Id
33
+ */
34
+ protected $_orderId;
35
+ /**
36
+ * @var string $_languagePagantis Force language on bank page
37
+ */
38
+ protected $_languagePagantis;
39
+
40
+ /**
41
+ * @var string $_authMethod Authentication method for payment redirect.
42
+ */
43
+ protected $_authMethod;
44
+
45
+ /**
46
+ * @var string $_accountCode
47
+ */
48
+ protected $_accountCode;
49
+
50
+ /**
51
+ * @var string $accountKey
52
+ */
53
+ protected $_accountKey;
54
+
55
+
56
+ /**
57
+ * @var string $_urlOk Requerido 500 URL completa.
58
+ */
59
+ protected $_urlOk;
60
+
61
+ /**
62
+ *
63
+ * @var string $_urlKo Requerido 500 URL completa.
64
+ */
65
+ protected $_urlKo;
66
+
67
+ /**
68
+ *
69
+ * @var string $_urlKo Requerido 500 URL completa.
70
+ */
71
+ protected $_callback_url;
72
+
73
+
74
+ /**
75
+ * @var string $_firma created by clave_de_firma + account_id + order_id + amount + currency + ok_url + nok_url
76
+ */
77
+ protected $_firma;
78
+
79
+ /**
80
+ * @var array
81
+ */
82
+ protected $_userData;
83
+
84
+ /**
85
+ * @var array
86
+ */
87
+ protected $_items;
88
+
89
+ /**
90
+ * @var dicount
91
+ */
92
+ protected $_dicount;
93
+
94
+ public function __construct()
95
+ {
96
+ $this->_languagePagantis = $this->setLanguagePagantis(); //Por defecto español
97
+ $this->_currency = $this->setCurrency();
98
+ }
99
+
100
+ /**
101
+ * Return the array version of the Request to be sent through the form
102
+ *
103
+ * @return string
104
+ */
105
+ public function toArray()
106
+ {
107
+ $array = array();
108
+ $array['order_id'] = $this->_orderId;
109
+ $array['amount'] = $this->_amount;
110
+ $array['currency'] = $this->_currency;
111
+
112
+ $array['ok_url'] = $this->_urlOk;
113
+ $array['nok_url'] = $this->_urlKo;
114
+ $array['callback_url'] = $this->_callback_url;
115
+ $array['discount[full]'] = $this->_discount;
116
+
117
+ $array['locale'] = $this->_languagePagantis;
118
+
119
+ $array['full_name'] = $this->_userData['full_name'];
120
+ $array['email'] = $this->_userData['email'];
121
+ $array['address[street]'] = $this->_userData['street'];
122
+ $array['address[city]'] = $this->_userData['city'];
123
+ $array['address[province]'] = $this->_userData['province'];
124
+ $array['address[zipcode]'] = $this->_userData['zipcode'];
125
+ $array['dni'] = $this->_userData['dni'];
126
+
127
+ foreach($this->_items as $key => $value){
128
+ $array['items[' . $key . '][description]'] = $value['description'];
129
+ $array['items[' . $key . '][quantity]'] = $value['quantity'];
130
+ $array['items[' . $key . '][amount]'] = $value['amount'];
131
+ }
132
+
133
+ $array['account_id'] = $this->_accountCode;
134
+ $array['signature'] = $this->_firma;
135
+
136
+ return $array;
137
+ }
138
+
139
+ /**
140
+ * Assign url for redirect
141
+ * @param string $urlPagantis
142
+ * @throws Exception
143
+ */
144
+ public function setUrlPagantis($urlPagantis = '')
145
+ {
146
+ if (strlen(trim($urlPagantis)) > 0) {
147
+ $this->_urlPagantis = $urlPagantis;
148
+ } else {
149
+ throw new \Exception('Missing url for redirect to page bank');
150
+ }
151
+ }
152
+
153
+ /**
154
+ * Assign url for redirect
155
+ * @param string $urlPagantis
156
+ * @throws Exception
157
+ */
158
+ public function setOrderId($orderId = '')
159
+ {
160
+ if (strlen(trim($orderId)) > 0) {
161
+ $this->_orderId = $orderId;
162
+ } else {
163
+ throw new \Exception('Missing orderId');
164
+ }
165
+ }
166
+
167
+ /**
168
+ * Assign currency for redirect
169
+ * @param string $currency
170
+ * @throws Exception
171
+ */
172
+ public function setCurrency()
173
+ {
174
+ return Pagantis_Pagantis_Model_Currency::EUR;
175
+ }
176
+
177
+ /**
178
+ * Assign url for redirect
179
+ * @param string $urlPagantis
180
+ * @throws Exception
181
+ */
182
+ public function setAmount($amount = '')
183
+ {
184
+ if (strlen(trim($amount)) > 0) {
185
+ $this->_amount = $amount;
186
+ } else {
187
+ throw new \Exception('Missing amount');
188
+ }
189
+ }
190
+
191
+ /**
192
+ * Assign language for bank page
193
+ * @param string $language Language for bank page
194
+ */
195
+ public function setLanguagePagantis($language = 'es')
196
+ {
197
+ return $language;
198
+ }
199
+
200
+ /**
201
+ * Assign user data
202
+ * @param string $addressId
203
+ * @throws Exception
204
+ */
205
+ public function setUserData($addressId)
206
+ {
207
+ if ($addressId) {
208
+ $address = Mage::getModel('sales/order_address')->load($addressId);
209
+ $street = $address->getStreet();
210
+ if ($street){
211
+ $this->_userData['street'] = $street[0];
212
+ }
213
+ $this->_userData['city'] = $address->getCity();
214
+ $this->_userData['province'] = $address->getCity();
215
+ $this->_userData['zipcode'] = $address->getPostcode();
216
+ $this->_userData['dni'] = $address->getVatId();
217
+ $this->_userData['full_name'] = $address->getFirstname() . ' ' . $address->getLastname();
218
+ $this->_userData['email'] = $address->getEmail();
219
+ } else {
220
+ throw new \Exception('Missing user data info');
221
+ }
222
+ }
223
+
224
+ /**
225
+ * Assign user data
226
+ * @param string $addressId
227
+ * @throws Exception
228
+ */
229
+ public function setOrderItems($orderId)
230
+ {
231
+ if ($orderId) {
232
+ $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
233
+ $items = $order->getAllVisibleItems();
234
+ $i = 0;
235
+ foreach($items as $item){
236
+ $amount = round($item->getPriceInclTax(),2);
237
+ $quantity = round($item->getQtyOrdered());
238
+ $this->_items[$i]['description'] = $item->getName();
239
+ $this->_items[$i]['quantity'] = $quantity;
240
+ $this->_items[$i]['amount'] = round($amount*$quantity,2);
241
+ $i++;
242
+ }
243
+ $shippingAmount = round($order->getShippingAmount(),2);
244
+ if($shippingAmount){
245
+ $this->_items[$i]['description'] = "Gastos de envío";
246
+ $this->_items[$i]['quantity'] = "1";
247
+ $this->_items[$i]['amount'] = $shippingAmount;
248
+ $i++;
249
+ }
250
+ $discountAmount = round($order->getBaseDiscountAmount(),2);
251
+ if($discountAmount){
252
+ $this->_items[$i]['description'] = "Descuento";
253
+ $this->_items[$i]['quantity'] = "1";
254
+ $this->_items[$i]['amount'] = $discountAmount;
255
+ }
256
+
257
+ } else {
258
+ throw new \Exception('Missing user data info');
259
+ }
260
+ }
261
+
262
+ /**
263
+ * Assign account code
264
+ * @param string $accountCode
265
+ * @throws Exception
266
+ */
267
+ public function setAccountCode($accountCode=''){
268
+ if (strlen(trim($accountCode)) > 0) {
269
+ $this->_accountCode = $accountCode;
270
+ } else {
271
+ throw new \Exception('Missing account code');
272
+ }
273
+ }
274
+
275
+ /**
276
+ * Assign discount
277
+ * @param string $discount
278
+ * @throws Exception
279
+ */
280
+ public function setDiscount($discount=''){
281
+ if ($discount == 1) {
282
+ $this->_discount = 'true';
283
+ } else {
284
+ $this->_discount = 'false';
285
+ }
286
+ }
287
+ /**
288
+ * Assign account key
289
+ * @param string $accountKey
290
+ * @throws Exception
291
+ */
292
+ public function setAccountKey($accountKey=''){
293
+ if (strlen(trim($accountKey)) > 0) {
294
+ $this->_accountKey = $accountKey;
295
+ } else {
296
+ throw new \Exception('Missing account key');
297
+ }
298
+ }
299
+
300
+
301
+ /**
302
+ * @param string $urlok
303
+ * @throws Exception
304
+ */
305
+ public function setUrlOk()
306
+ {
307
+ $urlOk = $this->getUrl('success');
308
+ if (strlen(trim($urlOk)) > 0) {
309
+ $this->_urlOk = $urlOk;
310
+ } else {
311
+ throw new \Exception('UrlOk not defined');
312
+ }
313
+
314
+ }
315
+
316
+ /**
317
+ * @param string $urlnok
318
+ * @throws Exception
319
+ */
320
+ public function setUrlKo($urlKo = '')
321
+ {
322
+ $urlKo = $this->getUrl('cancel');
323
+ if (strlen(trim($urlKo)) > 0) {
324
+ $this->_urlKo = $urlKo;
325
+ } else {
326
+ throw new \Exception('UrlKo not defined');
327
+ }
328
+ }
329
+
330
+ /**
331
+ * @param string $urlnok
332
+ * @throws Exception
333
+ */
334
+ public function setCacllbackUrl($ur = '')
335
+ {
336
+ $this->_callback_url=Mage::getBaseUrl()."/pagantis/pagantis/notification";
337
+ }
338
+
339
+
340
+ /**
341
+ * Firm generation
342
+ * Generated with SHA1 of _accountKey + _accountCode + _orderId + _amount + _currency + _urlOk + _urlKo
343
+ * @throws Exception
344
+ * @return string
345
+ */
346
+ public function setFirma()
347
+ {
348
+ $textToEncode = $this->_accountKey . $this->_accountCode . $this->_orderId . $this->_amount . $this->_currency . $this->_urlOk . $this->_urlKo . $this->_callback_url . $this->_discount;
349
+ //encoding is SHA1
350
+ $this->_firma = sha1($textToEncode);
351
+ /*
352
+ if (strlen(trim($textToEncode)) > 0) {
353
+ // Retrieve del SHA1
354
+ $this->_firma = sha1($textToEncode);
355
+ } else {
356
+ throw new Exception('Missing SHA1');
357
+ }
358
+ */
359
+ }
360
+
361
+ //Utilities
362
+ //http://stackoverflow.com/a/9111049/444225
363
+ private function priceToSQL($price)
364
+ {
365
+ $price = preg_replace('/[^0-9\.,]*/i', '', $price);
366
+ $price = str_replace(',', '.', $price);
367
+
368
+ if (substr($price, -3, 1) == '.') {
369
+ $price = explode('.', $price);
370
+ $last = array_pop($price);
371
+ $price = join($price, '') . '.' . $last;
372
+ } else {
373
+ $price = str_replace('.', '', $price);
374
+ }
375
+
376
+ return $price;
377
+ }
378
+
379
+ public function getUrl($path)
380
+ {
381
+ $url = Mage::getUrl(self::BASE . "/$path");
382
+ return Mage::getModel('core/url')->sessionUrlVar($url);
383
+ }
384
+
385
+ /**
386
+ * Converts field names for setters and getters
387
+ *
388
+ * @param string $name
389
+ * @return string
390
+ */
391
+ private function underscore($name)
392
+ {
393
+ $result = strtolower(preg_replace('/(.)([A-Z])/', "$1_$2", $name));
394
+ return $result;
395
+ }
396
+
397
+ /**
398
+ * Checks if received response is correct
399
+ * Clave_encriptacion+MerchantID+AcquirerBIN+TerminalID+Num_operacion+Importe+TipoMoneda+ Exponente+Referencia
400
+ * @param Yameveo_Ceca_Model_Webservice_Response $response
401
+ * @return boolean
402
+ */
403
+ /*public function checkResponseSignature(Pagantis_Pagantis_Model_Webservice_Response $response)
404
+ {
405
+ $txt = $this->_clave_encriptacion;
406
+ $txt .= $response->getMerchantId();
407
+ $txt .= $response->getAcquirerBin();
408
+ $txt .= $response->getTerminalId();
409
+ $txt .= $response->getNumOperacion();
410
+ $txt .= $response->getImporte();
411
+ $txt .= $response->getTipoMoneda();
412
+ $txt .= $response->getExponente();
413
+ $txt .= $response->getReferencia();
414
+
415
+ // Calculate signature
416
+ $signature = sha1($txt);
417
+
418
+ // Compare received signature with calculated
419
+ return strtolower($signature) === strtolower($response->getFirma());
420
+ }*/
421
+ }
app/code/community/Pagantis/Pagantis/Model/Webservice/Response.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ *
5
+ * @package Pagantis_Pagantis
6
+ * @copyright Copyright (c) 2015 Yameveo (http://www.yameveo.com)
7
+ * @author Yameveo <yameveo@yameveo.com>
8
+ * @link http://www.yameveo.com
9
+ */
10
+
11
+ class Pagantis_Pagantis_Model_Webservice_Response
12
+ {
13
+
14
+
15
+ }
app/code/community/Pagantis/Pagantis/controllers/PagantisController.php ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Pagantis Checkout Controller
5
+ *
6
+ * @package Pagantis_Pagantis
7
+ * @copyright Copyright (c) 2015 Yameveo (http://www.yameveo.com)
8
+ * @author Yameveo <yameveo@yameveo.com>
9
+ * @link http://www.yameveo.com
10
+ */
11
+ class Pagantis_Pagantis_PagantisController extends Mage_Core_Controller_Front_Action
12
+ {
13
+ /**
14
+ * When a customer chooses Pagantis on Checkout/Payment page
15
+ *
16
+ */
17
+ public function redirectAction()
18
+ {
19
+ $state = Mage_Sales_Model_Order::STATE_PENDING_PAYMENT;
20
+ $session = Mage::getSingleton('checkout/session');
21
+ $order = Mage::getModel('sales/order')->load($session->getLastOrderId());
22
+ $order->setState($state, $state, Mage::helper('pagantis_pagantis')->__('Redirected to Pagantis'), false);
23
+ $order->save();
24
+ $this->loadLayout();
25
+ $this->renderLayout();
26
+ }
27
+
28
+ /**
29
+ * When customer cancel payment from CECA (UrlKO)
30
+ *
31
+ */
32
+ public function cancelAction()
33
+ {
34
+ $session = Mage::getSingleton('checkout/session');
35
+ //Mage::getSingleton(‘core/session’)->addError(‘Error message’);
36
+ $session->addError('Lo sentimos, se ha producido algún error en el pago, le agradeceríamos que volviera a intentarlo.');
37
+ if ($session->getLastRealOrderId()) {
38
+ $order = Mage::getModel('sales/order')->loadByIncrementId($session->getLastRealOrderId());
39
+ if ($order->getId()) {
40
+ $order->cancel()->save();
41
+ }
42
+ Mage::helper('pagantis_pagantis')->restoreQuote();
43
+ }
44
+ $this->_redirect('checkout/cart');
45
+ }
46
+
47
+ public function notificationAction(){
48
+ //$json = json_decode(file_get_contents(Mage::getBaseDir().'/charge.created.txt'),true);
49
+ //Notification url mush be like http://mydomain.com/pagantis/pagantis/notification
50
+
51
+ $json = file_get_contents('php://input');
52
+ $temp = json_decode($json,true);
53
+ $data = $temp['data'];
54
+ $orderId = $data['order_id'];
55
+ $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
56
+ Mage::log('Pagantis notification received for orderId '.$orderId);
57
+ //Mage::log($data,null,'logfile.txt');
58
+ if ($order->getId()) {
59
+ switch ($temp['event']) {
60
+ case 'charge.created':
61
+ $order->setPagantisTransaction($data['id']);
62
+ $order->save();
63
+ $this->_processOrder($order);
64
+ break;
65
+ case 'charge.failed':
66
+ $order->setPagantisTransaction($data['id']);
67
+ $order->setState(Mage_Sales_Model_Order::STATE_CANCELED,true);
68
+ $order->save();
69
+ break;
70
+ }
71
+ }
72
+ }
73
+
74
+ /**
75
+ * When customer returns from Pagantis (UrlOK)
76
+ * The order information at this point is in POST
77
+ * variables. Order processing is done on callbackAction
78
+ */
79
+ public function successAction()
80
+ {
81
+ Mage::getSingleton('checkout/session')->getQuote()->setIsActive(false)->save();
82
+ $this->_redirect('checkout/onepage/success', array('_secure' => true));
83
+ }
84
+
85
+ public function callbackAction()
86
+ {
87
+ $params = $this->getRequest()->getPost();
88
+ $response = Mage::getModel('pagantis_pagantis/webservice_response', $params);
89
+ $request = Mage::helper('pagantis_pagantis')->getRequest();
90
+
91
+ if ($request->checkResponseSignature($response)) {
92
+ // Process order
93
+ $this->_processOrder($response->getOrder(), $response);
94
+ } else {
95
+ // Log invalid signature and redirect to home
96
+ Mage::log('Pagantis: invalid signature on callback', Zend_Log::WARN);
97
+ $this->_redirect('');
98
+ }
99
+ }
100
+
101
+ /**
102
+ * Process order
103
+ *
104
+ * @param $order
105
+ */
106
+ private function _processOrder($order)
107
+ {
108
+ try {
109
+ $sendMail = (int) Mage::getStoreConfig('payment/pagantis/sendmail');
110
+ $createInvoice = (int) Mage::getStoreConfig('payment/pagantis/invoice');
111
+ if ($order->getId()) {
112
+ //if ($response->isDsValid()) {
113
+ $orderStatus = Mage_Sales_Model_Order::STATE_PROCESSING;
114
+ if ($order->canInvoice() && $createInvoice) {
115
+ $invoice = $this->_createInvoice($order);
116
+ $comment = Mage::helper('pagantis_pagantis')->__('Transacción authorizada. Creada factura %s', $invoice->getIncrementId());
117
+ } else {
118
+ $comment = Mage::helper('pagantis_pagantis')->__('Transacción authorizada, factura no creada');
119
+ }
120
+ // } else {
121
+ // $orderStatus = Mage_Sales_Model_Order::STATE_CANCELED;
122
+ // $comment = Mage::helper('yameveo_ceca')->__($response->getErrorMessage());
123
+ // }
124
+ $order->setState($orderStatus, $orderStatus, $comment, true);
125
+ $order->save();
126
+ if ($sendMail) {
127
+ if ($orderStatus == Mage_Sales_Model_Order::STATE_PROCESSING) {
128
+ $order->sendNewOrderEmail();
129
+ } else {
130
+ $order->sendOrderUpdateEmail(true);
131
+ }
132
+ }
133
+ }
134
+ } catch (Exception $e) {
135
+ Mage::logException($e);
136
+ }
137
+ }
138
+
139
+ /**
140
+ * Create an invoice for the order and send an email
141
+ *
142
+ * @param Mage_Sales_Model_Order $order
143
+ * @return Mage_Sales_Model_Order_Invoice
144
+ */
145
+ private function _createInvoice($order)
146
+ {
147
+ $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
148
+ if (!$invoice->getTotalQty()) {
149
+ Mage::throwException(Mage::helper('core')->__('No se puede crear una factura sin productos.'));
150
+ }
151
+
152
+ $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
153
+ $invoice->register();
154
+ $transactionSave = Mage::getModel('core/resource_transaction')
155
+ ->addObject($invoice)
156
+ ->addObject($invoice->getOrder());
157
+
158
+ $transactionSave->save();
159
+ $invoice->sendEmail();
160
+ return $invoice;
161
+ }
162
+
163
+ }
app/code/community/Pagantis/Pagantis/etc/config.xml ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Pagantis_Pagantis>
5
+ <version>1.0.0</version>
6
+ </Pagantis_Pagantis>
7
+ </modules>
8
+ <adminhtml>
9
+ <layout>
10
+ <updates>
11
+ <bar>
12
+ <file>pagantis.xml</file>
13
+ </bar>
14
+ </updates>
15
+ </layout>
16
+ <translate>
17
+ <modules>
18
+ <pagantis_pagantis>
19
+ <files>
20
+ <default>Pagantis_Pagantis.csv</default>
21
+ </files>
22
+ </pagantis_pagantis>
23
+ </modules>
24
+ </translate>
25
+ </adminhtml>
26
+ <global>
27
+ <resources>
28
+ <pagantis_setup>
29
+ <setup>
30
+ <module>Pagantis_Pagantis</module>
31
+ <class>Mage_Sales_Model_Mysql4_Setup</class>
32
+ </setup>
33
+ <connection>
34
+ <use>core_setup</use>
35
+ </connection>
36
+ </pagantis_setup>
37
+ </resources>
38
+ <blocks>
39
+ <pagantis_pagantis>
40
+ <class>Pagantis_Pagantis_Block</class>
41
+ </pagantis_pagantis>
42
+ </blocks>
43
+ <helpers>
44
+ <pagantis_pagantis>
45
+ <class>Pagantis_Pagantis_Helper</class>
46
+ </pagantis_pagantis>
47
+ </helpers>
48
+ <models>
49
+ <pagantis_pagantis>
50
+ <class>Pagantis_Pagantis_Model</class>
51
+ </pagantis_pagantis>
52
+ </models>
53
+ </global>
54
+ <default>
55
+ <payment>
56
+ <pagantis>
57
+ <active>1</active>
58
+ <model>pagantis_pagantis/payment</model>
59
+ <order_status>1</order_status>
60
+ <title>Paga Mas Tarde</title>
61
+ <url_pagantis>https://psp.pagantis.com/2/charges</url_pagantis>
62
+ <url_pagantis_mastarde>https://pmt.pagantis.com/v1/installments</url_pagantis_mastarde>
63
+ <environment></environment>
64
+ <language_payment_page>ES</language_payment_page>
65
+ <auth_method>SHA1</auth_method>
66
+ <account_code_test></account_code_test>
67
+ <account_key_test></account_key_test>
68
+ <account_api_key_test></account_api_key_test>
69
+ <account_code_real></account_code_real>
70
+ <account_key_real></account_key_real>
71
+ <discount></discount>
72
+ <account_api_key_real></account_api_key_real>
73
+ <sendmail>1</sendmail>
74
+ <invoice>1</invoice>
75
+ <!--<sort_order></sort_order>-->
76
+ <payment_action>authorize_capture</payment_action>
77
+ </pagantis>
78
+ </payment>
79
+ </default>
80
+ <frontend>
81
+ <translate>
82
+ <modules>
83
+ <pagantis_pagantis>
84
+ <files>
85
+ <default>Pagantis_Pagantis.csv</default>
86
+ </files>
87
+ </pagantis_pagantis>
88
+ </modules>
89
+ </translate>
90
+ <secure_url>
91
+ <pagantis>/pagantis/pagantis</pagantis>
92
+ </secure_url>
93
+ <routers>
94
+ <pagantis>
95
+ <use>standard</use>
96
+ <args>
97
+ <module>Pagantis_Pagantis</module>
98
+ <frontName>pagantis</frontName>
99
+ </args>
100
+ </pagantis>
101
+ </routers>
102
+ <layout>
103
+ <updates>
104
+ <pagantis_pagantis_redirect>
105
+ <file>pagantis.xml</file>
106
+ </pagantis_pagantis_redirect>
107
+ </updates>
108
+ </layout>
109
+ </frontend>
110
+ <!--<crontab>
111
+ <jobs>
112
+ <pagantis_pagantis>
113
+ <schedule>
114
+ <config_path>pagantis_config/settings/cron_settings</config_path>
115
+ </schedule>
116
+ <run>
117
+ <model>pagantis_pagantis/observer::exportOrders</model>
118
+ </run>
119
+ </pagantis_pagantis>
120
+ </jobs>
121
+ </crontab>-->
122
+ </config>
app/code/community/Pagantis/Pagantis/etc/system.xml ADDED
@@ -0,0 +1,212 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <sections>
4
+ <payment>
5
+ <groups>
6
+ <pagantis translate="label" module="pagantis_pagantis">
7
+ <label>Pagamastarde Payment</label>
8
+ <sort_order>10</sort_order>
9
+ <show_in_default>1</show_in_default>
10
+ <show_in_website>1</show_in_website>
11
+ <show_in_store>1</show_in_store>
12
+ <frontend_model>pagantis_pagantis/adminhtml_system_config_fieldset_payment</frontend_model>
13
+ <fields>
14
+ <active translate="label" module="pagantis_pagantis">
15
+ <label>Habilitado</label>
16
+ <comment>Habilitar esta forma de pago?</comment>
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>1</show_in_store>
23
+ </active>
24
+ <title translate="label" module="pagantis_pagantis">
25
+ <label>Título</label>
26
+ <sort_order>2</sort_order>
27
+ <show_in_default>1</show_in_default>
28
+ <show_in_website>1</show_in_website>
29
+ <show_in_store>1</show_in_store>
30
+ </title>
31
+ <!--<title_pagamastarde translate="label" module="pagantis_pagantis">
32
+ <label>Título Paga Mas Tarde</label>
33
+ <sort_order>3</sort_order>
34
+ <show_in_default>1</show_in_default>
35
+ <show_in_website>1</show_in_website>
36
+ <show_in_store>1</show_in_store>
37
+ </title_pagamastarde>-->
38
+ <!-- remove pagantis payment, pmt url moved to settings and automatically enabled -->
39
+ <!-- <url_pagantis translate="label" module="pagantis_pagantis">
40
+ <label>URL Pago Cobro Único</label>
41
+ <frontend_type>text</frontend_type>
42
+ <sort_order>10</sort_order>
43
+ <show_in_default>1</show_in_default>
44
+ <show_in_website>1</show_in_website>
45
+ <show_in_store>1</show_in_store>
46
+ </url_pagantis>
47
+ <url_pagantis_activated translate="label" module="pagantis_pagantis">
48
+ <label>Activar forma de Pago Cobro Único</label>
49
+ <comment>Abilitando esta forma de pago el cliente podrá eligirla al momento de la compra</comment>
50
+ <frontend_type>select</frontend_type>
51
+ <source_model>adminhtml/system_config_source_yesno</source_model>
52
+ <sort_order>11</sort_order>
53
+ <show_in_default>1</show_in_default>
54
+ <show_in_website>1</show_in_website>
55
+ <show_in_store>1</show_in_store>
56
+ </url_pagantis_activated>
57
+ <url_pagantis_mastarde translate="label" module="pagantis_pagantis">
58
+ <label>URL Paga+Tarde</label>
59
+ <frontend_type>text</frontend_type>
60
+ <sort_order>12</sort_order>
61
+ <show_in_default>1</show_in_default>
62
+ <show_in_website>1</show_in_website>
63
+ <show_in_store>1</show_in_store>
64
+ </url_pagantis_mastarde>
65
+ <url_pagantis_mastarde_activated translate="label" module="pagantis_pagantis">
66
+ <label>Activar forma de Paga+Tarde</label>
67
+ <comment>Abilitando esta forma de pago el cliente podrá eligirla al momento de la compra</comment>
68
+ <frontend_type>select</frontend_type>
69
+ <source_model>adminhtml/system_config_source_yesno</source_model>
70
+ <sort_order>13</sort_order>
71
+ <show_in_default>1</show_in_default>
72
+ <show_in_website>1</show_in_website>
73
+ <show_in_store>1</show_in_store>
74
+ </url_pagantis_mastarde_activated>
75
+ -->
76
+ <environment translate="label" module="pagantis_pagantis">
77
+ <label>Entorno</label>
78
+ <comment>Elegir entorno de Test o Real</comment>
79
+ <frontend_type>select</frontend_type>
80
+ <source_model>pagantis_pagantis/source_payment_environment</source_model>
81
+ <sort_order>14</sort_order>
82
+ <show_in_default>1</show_in_default>
83
+ <show_in_website>1</show_in_website>
84
+ <show_in_store>1</show_in_store>
85
+ </environment>
86
+ <!-- we remove this to have easier config and same template in all modules, we try to get user locale -->
87
+ <!--
88
+ <language_payment_page translate="label" module="pagantis_pagantis">
89
+ <label>Idioma Pagina De Pago</label>
90
+ <comment>Elegir el idioma con el cual se abrirá la pagina de pago Pagantis. Por ejemplo ES, FR, EN</comment>
91
+ <frontend_type>text</frontend_type>
92
+ <sort_order>25</sort_order>
93
+ <show_in_default>1</show_in_default>
94
+ <show_in_website>1</show_in_website>
95
+ <show_in_store>1</show_in_store>
96
+ </language_payment_page>
97
+
98
+ -->
99
+ <!-- sha1 customer don't care about this -->
100
+ <!--
101
+ <auth_method translate="label" module="pagantis_pagantis">
102
+ <label>Metodo de autenticación</label>
103
+ <comment>Valor necesario para pagos con cobro único (SHA1)</comment>
104
+ <frontend_type>text</frontend_type>
105
+ <sort_order>15</sort_order>
106
+ <show_in_default>1</show_in_default>
107
+ <show_in_website>1</show_in_website>
108
+ <show_in_store>1</show_in_store>
109
+ </auth_method>
110
+ -->
111
+ <account_code_test translate="label" module="pagantis_pagantis">
112
+ <label>Código de cuenta de Test</label>
113
+ <frontend_type>text</frontend_type>
114
+ <sort_order>17</sort_order>
115
+ <show_in_default>1</show_in_default>
116
+ <show_in_website>1</show_in_website>
117
+ <show_in_store>1</show_in_store>
118
+ </account_code_test>
119
+ <account_key_test translate="label" module="pagantis_pagantis">
120
+ <label>Clave de cuenta de Test</label>
121
+ <frontend_type>text</frontend_type>
122
+ <sort_order>18</sort_order>
123
+ <show_in_default>1</show_in_default>
124
+ <show_in_website>1</show_in_website>
125
+ <show_in_store>1</show_in_store>
126
+ </account_key_test>
127
+ <!-- api key not needed to perform payment -->
128
+ <!--
129
+ <account_api_key_test translate="label" module="pagantis_pagantis">
130
+ <label>API Key Test</label>
131
+ <frontend_type>text</frontend_type>
132
+ <sort_order>19</sort_order>
133
+ <show_in_default>1</show_in_default>
134
+ <show_in_website>1</show_in_website>
135
+ <show_in_store>1</show_in_store>
136
+ </account_api_key_test>
137
+ -->
138
+ <account_code_real translate="label" module="pagantis_pagantis">
139
+ <label>Código de cuenta Real</label>
140
+ <frontend_type>text</frontend_type>
141
+ <sort_order>20</sort_order>
142
+ <show_in_default>1</show_in_default>
143
+ <show_in_website>1</show_in_website>
144
+ <show_in_store>1</show_in_store>
145
+ </account_code_real>
146
+ <account_key_real translate="label" module="pagantis_pagantis">
147
+ <label>Clave de cuenta Real</label>
148
+ <frontend_type>text</frontend_type>
149
+ <sort_order>21</sort_order>
150
+ <show_in_default>1</show_in_default>
151
+ <show_in_website>1</show_in_website>
152
+ <show_in_store>1</show_in_store>
153
+ </account_key_real>
154
+ <!--
155
+ <account_api_key_real translate="label" module="pagantis_pagantis">
156
+ <label>API Key Real</label>
157
+ <frontend_type>text</frontend_type>
158
+ <sort_order>22</sort_order>
159
+ <show_in_default>1</show_in_default>
160
+ <show_in_website>1</show_in_website>
161
+ <show_in_store>1</show_in_store>
162
+ </account_api_key_real>
163
+ -->
164
+ <discount translate="label" module="pagantis_pagantis">
165
+ <label>Descuento - asumir comisiones</label>
166
+ <frontend_type>Select</frontend_type>
167
+ <source_model>adminhtml/system_config_source_yesno</source_model>
168
+ <sort_order>22</sort_order>
169
+ <show_in_default>1</show_in_default>
170
+ <show_in_website>1</show_in_website>
171
+ <show_in_store>1</show_in_store>
172
+ </discount>
173
+ <sendmail translate="label" module="pagantis_pagantis">
174
+ <label>Envía correo de confirma</label>
175
+ <frontend_type>Select</frontend_type>
176
+ <sort_order>40</sort_order>
177
+ <source_model>adminhtml/system_config_source_yesno</source_model>
178
+ <show_in_default>1</show_in_default>
179
+ <show_in_website>1</show_in_website>
180
+ <show_in_store>1</show_in_store>
181
+ </sendmail>
182
+ <invoice translate="label" module="pagantis_pagantis">
183
+ <label>Crea factura automaticamente</label>
184
+ <frontend_type>Select</frontend_type>
185
+ <sort_order>50</sort_order>
186
+ <source_model>adminhtml/system_config_source_yesno</source_model>
187
+ <show_in_default>1</show_in_default>
188
+ <show_in_website>1</show_in_website>
189
+ <show_in_store>1</show_in_store>
190
+ </invoice>
191
+ <sort_order translate="label" module="pagantis_pagantis">
192
+ <label>Ordenación metodo de pago</label>
193
+ <comment>Elegir en que posición tiene que salir el metodo de Pago Pagantis en el checkout</comment>
194
+ <frontend_type>text</frontend_type>
195
+ <sort_order>100</sort_order>
196
+ <show_in_default>1</show_in_default>
197
+ <show_in_website>1</show_in_website>
198
+ <show_in_store>1</show_in_store>
199
+ </sort_order>
200
+ <!--<cron_settings translate="label comment" module="pagantis_pagantis">
201
+ <label>Cuantas veces quieres ejecutar el proceso de sincronización de los pedidos?</label>
202
+ <frontend_type>text</frontend_type>
203
+ <sort_order>60</sort_order>
204
+ <comment>Utiliza el formato Crontab (p.e. "0 4 * * *" para cada día a las 4 a.m.)</comment>
205
+ <show_in_default>1</show_in_default>
206
+ </cron_settings>-->
207
+ </fields>
208
+ </pagantis>
209
+ </groups>
210
+ </payment>
211
+ </sections>
212
+ </config>
app/code/community/Pagantis/Pagantis/sql/pagantis_setup/mysql4-install-1.0.0.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+ $installer->startSetup();
5
+ $installer->addAttribute("order", "pagantis_transaction", array("type" => "varchar"));
6
+ $installer->getConnection()->addColumn($installer->getTable('sales_flat_order_grid'), 'pagantis_transaction', 'varchar(255)');
7
+ $installer->endSetup();
app/design/adminhtml/default/default/layout/pagantis.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout>
3
+ <default>
4
+ <reference name="head">
5
+ <action method="addCss"><name>pagantis.css</name></action>
6
+ </reference>
7
+ </default>
8
+ </layout>
app/design/frontend/base/default/layout/pagantis.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <pagantis_pagantis_redirect>
4
+ <reference name="content">
5
+ <block type="pagantis_pagantis/redirect" name="redirect" template="pagantis/redirect.phtml"></block>
6
+ </reference>
7
+ </pagantis_pagantis_redirect>
8
+ </layout>
app/design/frontend/base/default/template/pagantis/form.phtml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <img id="imgpagantisfront" src="<?php echo $this->getSkinUrl('images/pagantis/logopagamastarde.png') ?>"/>
2
+ <?php $_code = $this->getMethodCode() ?>
3
+
4
+
5
+
6
+ <span id="int_amount2"><?=round($this->inst6,2)?></span> € / mes en
7
+ <!--<select style="width:50px" name="num_inst2" disabled="enabled" id="num_inst2" onChange="document.getElementById('int_amount2').innerHTML=document.getElementById('instAmount2'+this.value).innerHTML;" >
8
+ <option value="6">6</option>
9
+ <option value="5">5</option>
10
+ <option value="4">4</option>
11
+ <option value="3">3</option>
12
+ <option value="2">2</option>
13
+ </select> -->
14
+
15
+ 6 plazos
16
+
17
+
18
+ <div style="display:none" id="instAmount22"><?=round ($this->inst2,2)?></div>
19
+ <div style="display:none" id="instAmount23"><?=round ($this->inst3,2)?></div>
20
+ <div style="display:none" id="instAmount24"><?=round ($this->inst4,2)?></div>
21
+ <div style="display:none" id="instAmount25"><?=round ($this->inst5,2)?></div>
22
+ <div style="display:none" id="instAmount26"><?=round ($this->inst6,2)?></div>
app/design/frontend/base/default/template/pagantis/pagantis.phtml ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <fieldset class="form-list">
2
+ <?php $_code = $this->getMethodCode() ?>
3
+ <?php $activeMethodUnique = Mage::getStoreConfig('payment/pagantis/url_pagantis_activated'); ?>
4
+ <?php $activeMethodLoan = Mage::getStoreConfig('payment/pagantis/url_pagantis_mastarde_activated'); ?>
5
+ </fieldset>
6
+ <div id="payment_form_<?php echo $_code ?>" style="display: none">
7
+ <div id="innerpagantis">
8
+ <?php if($activeMethodUnique) : ?>
9
+ <?php if ($activeMethodLoan) :?>
10
+ <input type="radio" class="pagantisradio" name="paymentdetail[]" value="unico" checked>Paga con cobro único<br />
11
+ <input type="radio" class="pagantisradio" name="paymentdetail[]" value="financiacion">Financialo con Paga+Tarde<br />
12
+ <?php else : ?>
13
+ <input type="hidden" class="pagantisradio" name="paymentdetail[]" value="unico">
14
+ <?php endif; ?>
15
+ <?php else: ?>
16
+ <input type="hidden" class="pagantisradio" name="paymentdetail[]" value="financiacion">
17
+ <?php endif; ?>
18
+ <p>Paga
19
+ <span id="int_amount"><?=round($this->instAmount(6),2)?></span> € / mes en
20
+ <select style="width:50px" name="num_inst" id="num_inst" onChange="document.getElementById('int_amount').innerHTML=document.getElementById('instAmount'+this.value).innerHTML;" >
21
+ <option value="6">6</option>
22
+ <option value="5">5</option>
23
+ <option value="4">4</option>
24
+ <option value="3">3</option>
25
+ <option value="2">2</option>
26
+ </select> plazos </p>
27
+
28
+ <div style="display:none" id="instAmount2"><?=round ($this->instAmount(2),2)?></div>
29
+ <div style="display:none" id="instAmount3"><?=round ($this->instAmount(3),2)?></div>
30
+ <div style="display:none" id="instAmount4"><?=round ($this->instAmount(4),2)?></div>
31
+ <div style="display:none" id="instAmount5"><?=round ($this->instAmount(5),2)?></div>
32
+ <div style="display:none" id="instAmount6"><?=round ($this->instAmount(6),2)?></div>
33
+
34
+ </div>
35
+ </div>
36
+
37
+ <style>
38
+ #innerpagantis {margin-left: 20px}
39
+ .pagantisradio {margin-right:10px}
40
+ #imgpagantisfront {height:20px; margin-right: 10px;}
41
+ #imgpagantisform {height: 30%;width: 30%;margin-left: 20%;}
42
+ </style>
app/design/frontend/base/default/template/pagantis/redirect.phtml ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <div style="text-align: center">
2
+ <h3><?php echo $this->__('Haciendo click en continuar será redirigido a la pasarela de pago seguro de Pagantis.') ?></h3>
3
+ <?php echo $this->getFormRedirect(); ?>
4
+ </div>
5
+ <script type='text/javascript'>
6
+ $('pagantis_pagantis_checkout').submit();
7
+ </script>
app/etc/modules/Pagantis_Pagantis.xml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Pagantis_Pagantis>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ <depends></depends>
8
+ </Pagantis_Pagantis>
9
+ </modules>
10
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Pagantis_Pagantis</name>
4
+ <version>2.0.1</version>
5
+ <stability>stable</stability>
6
+ <license uri="https://www.gnu.org/licenses/gpl-2.0.html">GPL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Modulo de Magento para abilitar la pasarela de pago PagaMasTarde en Magento.</summary>
10
+ <description>Este es el m&#xF3;dulo Paga M&#xE1;s Tarde para Magento que permite activar el pago fraccionado ( por cuotas ) en tu tienda y potenciar las ventas.</description>
11
+ <notes>First public release</notes>
12
+ <authors><author><name>Albert Fatsini</name><user>afatsini</user><email>afatsini@digitalorigin.com</email></author></authors>
13
+ <date>2015-10-28</date>
14
+ <time>08:26:52</time>
15
+ <contents><target name="magecommunity"><dir name="Pagantis"><dir name="Pagantis"><dir name="Block"><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Fieldset"><file name="Payment.php" hash="285814ecab6b4e338e75a370f41fdc12"/></dir></dir></dir></dir><file name="Form.php" hash="1a1d25b576972aafcd4287ede540fa2e"/><file name="Redirect.php" hash="24fef0caf8b76c629b75e2d4acc81443"/></dir><dir name="Helper"><file name="Data.php" hash="e90849a9b9310979d58f7a092d2d2a28"/></dir><dir name="Model"><file name="Currency.php" hash="a5557e10938898b0213a90dd7be15540"/><file name="Observer.php" hash="bcdfc2c88533aa0242d1eedae9b0e5ce"/><file name="Payment.php" hash="191a611492496b066ae0477807ef13e4"/><dir name="Source"><dir name="Payment"><file name="Currency.php" hash="7e51124f09e2028198fb9587df820809"/><file name="Environment.php" hash="30d6400967acdd8975c5748994c100e6"/></dir></dir><dir name="Webservice"><file name="Client.php" hash="6a14e0ae7ef5180445a3a99aec4717bb"/><file name="Paymentrequest.php" hash="dcf473ea7211a82b55b5374549c3cfc0"/><file name="Request.php" hash="76506a6627d6523aae845169854f4ece"/><file name="Requestloan.php" hash="9312cb25b175c1b8c2983e8af8dcd24d"/><file name="Response.php" hash="bb1ade5931c5580f4585fc0fdb2bc4b0"/></dir></dir><dir name="controllers"><file name="PagantisController.php" hash="ab15e9f5ef018e04e597056bccf8ed97"/></dir><dir name="etc"><file name="config.xml" hash="4d05f079419556a9521d76b2e58c7f66"/><file name="system.xml" hash="6d15f34f3aa3429501cb6d1f9b8ec458"/></dir><dir name="sql"><dir name="pagantis_setup"><file name="mysql4-install-1.0.0.php" hash="4ec10724709f8d381758409f55cff99d"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="pagantis.xml" hash="c77059d571376c7d4b35f48d5115e11b"/></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="pagantis"><file name="form.phtml" hash="30dd654c52c8a310a732f161c8325f51"/><file name="pagantis.phtml" hash="a84fa4e8feae06f001fc13dd4df3e3cd"/><file name="redirect.phtml" hash="3d7d1a5076fc98269e5a7f476be27650"/></dir></dir><dir name="layout"><file name="pagantis.xml" hash="b678ae1013b95f0401b30fe9762601ac"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Pagantis_Pagantis.xml" hash="c57db60bd03314d7a45f27acc9a9475a"/></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="base"><dir name="default"><file name="pagantis.css" hash="45ca2308011ed481b8a649fe170ccb8a"/></dir></dir><dir name="default"><dir name="default"><dir name="images"><dir name="pagantis"><file name="logopagamastarde.png" hash="d51fa42e42d9811653df55710a395d07"/><file name="pagantis.png" hash="292403ede1f62affccf06df004ddfe12"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="images"><dir name="pagantis"><file name="logopagamastarde.png" hash="d51fa42e42d9811653df55710a395d07"/><file name="pagantis-fav.png" hash="c4e162b51c0792ff25385506d7998818"/><file name="pagantis.png" hash="292403ede1f62affccf06df004ddfe12"/></dir></dir></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>
skin/adminhtml/base/default/pagantis.css ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ .adminLogoPagantis {
2
+ width:160px;
3
+ height:100px;
4
+ background:url(../../default/default/images/pagantis/logopagamastarde.png) no-repeat 0 2px;
5
+ background-size: 150px;
6
+ }
skin/adminhtml/default/default/images/pagantis/logopagamastarde.png ADDED
Binary file
skin/adminhtml/default/default/images/pagantis/pagantis.png ADDED
Binary file
skin/frontend/base/default/images/pagantis/logopagamastarde.png ADDED
Binary file
skin/frontend/base/default/images/pagantis/pagantis-fav.png ADDED
Binary file
skin/frontend/base/default/images/pagantis/pagantis.png ADDED
Binary file