Tpv_Ceca - Version 1.0.0

Version Notes

testing

Download this release

Release Info

Developer Magento Desarrollo
Extension Tpv_Ceca
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/community/Magentodesarrollo/Ceca/Helper/Data.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Magentodesarrollo_Ceca_Helper_Data extends
4
+ Mage_Core_Helper_Abstract
5
+ {
6
+
7
+
8
+ /**
9
+
10
+ */
11
+ }
app/code/community/Magentodesarrollo/Ceca/Model/Paymentmethod.php ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ *
5
+ * TPV Ceca
6
+ */
7
+ class Magentodesarrollo_Ceca_Model_Paymentmethod extends Mage_Payment_Model_Method_Abstract
8
+ {
9
+
10
+ /**
11
+ * unique internal payment method identifier
12
+ *
13
+ * @var string [a-z0-9_]
14
+ */
15
+ protected $_code = 'ceca';
16
+
17
+ /**
18
+ * Is this payment method a gateway (online auth/charge) ?
19
+ */
20
+ protected $_isGateway = true;
21
+
22
+ /**
23
+ * Can authorize online?
24
+ */
25
+ protected $_canAuthorize = true;
26
+
27
+ /**
28
+ * Can capture funds online?
29
+ */
30
+ protected $_canCapture = true;
31
+
32
+ /**
33
+ * Can capture partial amounts online?
34
+ */
35
+ protected $_canCapturePartial = false;
36
+
37
+ /**
38
+ * Can refund online?
39
+ */
40
+ protected $_canRefund = true;//no funciona bien en true
41
+ protected $_canRefundInvoicePartial = false;
42
+ /**
43
+ * Can void transactions online?
44
+ */
45
+ protected $_canVoid = true;
46
+
47
+ /**
48
+ * Can use this payment method in administration panel?
49
+ */
50
+ protected $_canUseInternal = true;
51
+
52
+ /**
53
+ * Can show this payment method as an option on checkout payment page?
54
+ */
55
+ protected $_canUseCheckout = true;
56
+
57
+ /**
58
+ * Is this payment method suitable for multi-shipping checkout?
59
+ */
60
+ protected $_canUseForMultishipping = true;
61
+
62
+ /**
63
+ * Can save credit card information for future processing?
64
+ */
65
+ protected $_canSaveCc = false;
66
+
67
+ protected $_isInitializeNeeded = false;
68
+
69
+ public function authorize(Varien_Object $payment, $amount)
70
+ {
71
+ //Mage::log('Authorizing!');
72
+ }
73
+
74
+ public function capture(Varien_Object $payment, $amount)
75
+ {
76
+ //Mage::log('** Capturing **');
77
+ }
78
+
79
+ public function assignData($data)
80
+ {
81
+ //Mage::log('Assigning Data');
82
+ }
83
+
84
+ public function refund(Varien_Object $payment, $amount)
85
+ {
86
+ //preparacion del array
87
+ $orderId=$payment->getOrder()->getIncrementId();
88
+ $invoice = $payment->getOrder()->getInvoiceCollection()
89
+ ->addAttributeToSort('created_at', 'DSC')
90
+ ->setPage(1, 1)
91
+ ->getFirstItem();
92
+
93
+ $transId=$invoice->getTransactionId();
94
+ $url = (Mage::getStoreConfig('payment/ceca/produccion')?'https://pgw.ceca.es/cgi-bin/tpvanular':'http://tpv.ceca.es:8000/cgi-bin/tpvanular');
95
+ $clave=Mage::getStoreConfig('payment/ceca/clave_encriptacion');
96
+ $merchant=Mage::getStoreConfig('payment/ceca/merchant_id');
97
+ $acquirer=Mage::getStoreConfig('payment/ceca/acquirer_bin');
98
+ $terminal=Mage::getStoreConfig('payment/ceca/terminal_id');
99
+ $precio=intval(100*$amount);
100
+ Mage::log($amount);
101
+ $mensaje = $clave . $merchant . $acquirer . $terminal . $orderId . $precio."9782".$transId."SHA1";
102
+ $firma =sha1($mensaje);
103
+
104
+ $fields = array(
105
+ "MerchantID" => $merchant,
106
+ "AcquirerBIN" =>$acquirer,
107
+ "TerminalID" => $terminal,
108
+ "Firma" => $firma,
109
+ "Num_operacion" => $orderId,
110
+ "Importe" => $precio,
111
+ "TipoMoneda" => "978",
112
+ "Exponente" => "2",
113
+ "Referencia" => $transId,
114
+ "Cifrado" => "SHA1"
115
+ );
116
+ $fields_string="";
117
+ foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
118
+ rtrim($fields_string, '&');
119
+ //open connection
120
+ $ch = curl_init();
121
+ //set the url, number of POST vars, POST data
122
+ curl_setopt($ch,CURLOPT_URL, $url);
123
+ curl_setopt($ch,CURLOPT_POST, count($fields));
124
+ curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
125
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
126
+ //execute post
127
+ $result = curl_exec($ch);
128
+ Mage::log($result,null,'serversidevalidation.log');
129
+ $resok = preg_replace("/<.*?>/", "", $result);
130
+ $resok = preg_match("/400/", $resok);
131
+ if(!$resok){
132
+ $resko = preg_replace("/[\n|\r]/", "", $result);
133
+ $resko = preg_replace("/<SCRIPT.*<\/SCRIPT>/", "", $resko);
134
+ $resko = preg_match("/<BODY.*<\/BODY>/", $resko, $res);
135
+ Mage::throwException($res[0]);
136
+ }
137
+ $curlinfo = curl_getinfo($ch);
138
+ $curlinfo =$curlinfo['http_code'];
139
+ //close connection
140
+ curl_close($ch);
141
+ //comprobación de conexión correcta
142
+ if($curlinfo!=200){
143
+ Mage::throwException("Fallo de conexión");
144
+ }
145
+
146
+ return $this;
147
+ }
148
+
149
+ //donde va cuando pulsas place order
150
+ public function getOrderPlaceRedirectUrl() {
151
+ return Mage::getUrl('ceca/payment/redirect');
152
+ }
153
+ /*public function getCheckoutRedirectUrl()
154
+ {
155
+ return Mage::getUrl('checkout/onepage/success');
156
+ }//esto se lanza antes del checkoutrevision*/
157
+
158
+
159
+ public function getCheckoutFormFields($order){
160
+ $clave=Mage::getStoreConfig('payment/ceca/clave_encriptacion');
161
+ $merchant=Mage::getStoreConfig('payment/ceca/merchant_id');
162
+ $acquirer=Mage::getStoreConfig('payment/ceca/acquirer_bin');
163
+ $terminal=Mage::getStoreConfig('payment/ceca/terminal_id');
164
+ $urlOk=Mage::getUrl('checkout/onepage/success');
165
+ $urlKo=Mage::getUrl('ceca/payment/fail');//Mage::getUrl('checkout/onepage/failure');
166
+ $precio=intval(100*$order->getGrandTotal());
167
+ $orderId=$order->getIncrementId();
168
+
169
+ $mensaje = $clave . $merchant . $acquirer . $terminal . $orderId . $precio."9782SHA1".$urlOk.$urlKo;
170
+ $firma =sha1($mensaje);
171
+
172
+ $Arr = array(
173
+ "MerchantID" => $merchant,
174
+ "AcquirerBIN" =>$acquirer,
175
+ "TerminalID" => $terminal,
176
+ "URL_OK" => $urlOk,
177
+ "URL_NOK" => $urlKo,
178
+ "Firma" => $firma,
179
+ "Cifrado" => "SHA1",
180
+ "Num_operacion" => $orderId,
181
+ "Importe" => $precio,
182
+ "TipoMoneda" => "978",
183
+ "Exponente" => "2",
184
+ "Pago_soportado" => "SSL",
185
+ "Idioma" => "1"
186
+ );
187
+ return $Arr;
188
+ }
189
+
190
+ }
app/code/community/Magentodesarrollo/Ceca/controllers/PaymentController.php ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * TPV Ceca
5
+ */
6
+ class Magentodesarrollo_Ceca_PaymentController extends Mage_Core_Controller_Front_Action {
7
+
8
+ public function redirectAction() {
9
+
10
+ $ordernumber = Mage::getSingleton('checkout/session')->getLastRealOrderId();
11
+ //si no acabas de comprar este if te saca al carrito
12
+ if(isset($ordernumber))
13
+ {
14
+ $order = Mage::getModel('sales/order')->loadByIncrementId($ordernumber);
15
+ //comprueba si esta pagada
16
+ if (!$this->_isOrderAlreadyPaid($order)) {
17
+ //coge el html del formulario que hara el redirect automaticamente
18
+ echo ($this->pintarhtml($order));
19
+ } else {
20
+ $this->_redirect('checkout/cart');
21
+ }
22
+ } else {$this->_redirect('checkout/cart');}
23
+ }
24
+ /**
25
+ *
26
+ */
27
+ protected function _isOrderAlreadyPaid(Mage_Sales_Model_Order $order = null) {
28
+ $order = !isset($order) ? $this->_getOrder($errorMessage) : $order;
29
+
30
+ if ($order) {
31
+ $payment = $order->getPayment();
32
+ return $payment->getLastTransId() ? true : false;
33
+ }
34
+ return false;
35
+ }
36
+
37
+ /**
38
+ * coger formulario
39
+ */
40
+ public function pintarhtml($order){
41
+ $cecatpv = Mage::getModel('ceca/paymentmethod');
42
+ $url = (Mage::getStoreConfig('payment/ceca/produccion')?'https://pgw.ceca.es/cgi-bin/tpv':'http://tpv.ceca.es:8000/cgi-bin/tpv');
43
+ $form = new Varien_Data_Form();
44
+ $form->setAction($url)
45
+ ->setId('ceca_standard_checkout')
46
+ ->setName('ceca_standard_checkout')
47
+ ->setMethod('POST')
48
+ ->setUseContainer(true);
49
+
50
+ foreach ($cecatpv->getCheckoutFormFields($order) as $field => $value) {
51
+ $form->addField($field, 'hidden', array('name' => $field, 'value' => $value));
52
+ }
53
+ $html = '<html>';
54
+ $html .= '<head>';
55
+ $html .= '</head>';
56
+ $html .= '<body>';
57
+ $html.= '<div class="ceca-container">';
58
+ $html.= '<p class="redirecting-text">' . 'You will be redirected to the ServiRed website in a few seconds.' . '</p>';
59
+ $html.= $form->toHtml();
60
+ $html.='</div>';
61
+ $html.= '<script type="text/javascript">document.getElementById("ceca_standard_checkout").submit();</script>';
62
+ $html.= '</body></html>';
63
+ return $html;
64
+ }
65
+
66
+ public function responseAction() {
67
+ //Mage::log($_POST);
68
+ // Recogemos datos de respuesta
69
+ $clave = Mage::getStoreConfig('payment/ceca/clave_encriptacion');
70
+ $total = $_POST["Importe"];
71
+ $orderId = $_POST["Num_operacion"];
72
+ $moneda = $_POST["TipoMoneda"];
73
+ $firma_remota = $_POST["Firma"];
74
+ $exponente = $_POST["Exponente"];
75
+ $transid = $_POST["Referencia"];
76
+ $merchant = $_POST["MerchantID"];
77
+ $acquirer = $_POST["AcquirerBIN"];
78
+ $terminal = $_POST["TerminalID"];
79
+ $numaut = $_POST["Num_aut"];
80
+ //$ = $_POST[""];
81
+ //$ = $_POST[""];
82
+ //$ = $_POST[""];
83
+ //$ = $_POST[""];
84
+ $mensaje = $clave . $merchant . $acquirer . $terminal . $orderId . $total . $moneda . $exponente . $transid;
85
+ $firma =sha1($mensaje);
86
+
87
+ if(($firma==$firma_remota)&&($numaut==101000)){
88
+
89
+ //Grava la orden
90
+ $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
91
+ $payment = $order->getPayment();
92
+ $payment->setTransactionId($transid);
93
+ $payment->Capture(NULL);
94
+ $order->save();
95
+
96
+ //manda correo
97
+ $invoice = $payment->getCreatedInvoice();
98
+ if ($invoice && Mage::getStoreConfig('payment/ceca/enviafactura')){
99
+ $invoice->sendEmail(true);
100
+ }
101
+
102
+
103
+ }//firma no coincide
104
+ else{
105
+ Mage::log("Posible estafa de pago por firma erronea.");
106
+ }
107
+
108
+
109
+ }
110
+
111
+ public function failAction() {
112
+ $orderid = Mage::getSingleton('checkout/session')->getLastOrderId();
113
+ $order = Mage::getModel('sales/order')->load($orderid);
114
+ if($order->getStatus()=='pending'){
115
+ $state = 'new';
116
+ $status = 'canceled';
117
+ $comment = 'Ceca ha actualizado el estado del pedido con el valor "'.$status.'"';
118
+ $isCustomerNotified = true;
119
+ $order->setState($state, $status, $comment, $isCustomerNotified);
120
+ $order->registerCancellation("")->save();
121
+ $order->save();
122
+ }
123
+ $this->_redirect('checkout/onepage/failure');
124
+ }
125
+ /*
126
+ public function testAction(){
127
+
128
+ }*/
129
+
130
+ }
app/code/community/Magentodesarrollo/Ceca/etc/config.xml ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Magentodesarrollo_Ceca>
5
+ <version>0.1.0</version>
6
+ </Magentodesarrollo_Ceca>
7
+ </modules>
8
+ <frontend>
9
+ <routers>
10
+ <ceca>
11
+ <use>standard</use>
12
+ <args>
13
+ <module>Magentodesarrollo_Ceca</module>
14
+ <frontName>ceca</frontName>
15
+ </args>
16
+ </ceca>
17
+ </routers>
18
+ </frontend>
19
+ <global>
20
+ <models>
21
+ <ceca>
22
+ <class>Magentodesarrollo_Ceca_Model</class>
23
+ </ceca>
24
+ </models>
25
+ </global>
26
+ <default>
27
+ <payment>
28
+ <ceca>
29
+ <active>1</active>
30
+ <!-- model to handle logic for this payment method -->
31
+ <model>ceca/paymentmethod</model>
32
+ <!-- order status for new orders paid by this payment method -->
33
+ <order_status>pending</order_status>
34
+ <!-- default title for payment checkout page and order view page -->
35
+ <title>TPV Ceca</title>
36
+ <allowspecific>0</allowspecific>
37
+ <payment_action>authorize</payment_action><!--payment_action>authorize_capture</payment_action-->
38
+ </ceca>
39
+ </payment>
40
+ </default>
41
+ </config>
app/code/community/Magentodesarrollo/Ceca/etc/system.xml ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <payment>
5
+ <groups>
6
+ <ceca translate="label" module="paygate">
7
+ <label>Pago TPV - Ceca</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>0</show_in_store>
12
+ <fields>
13
+ <active translate="label">
14
+ <label>Enabled</label>
15
+ <frontend_type>select</frontend_type>
16
+ <source_model>adminhtml/system_config_source_yesno</source_model>
17
+ <sort_order>1</sort_order>
18
+ <show_in_default>1</show_in_default>
19
+ <show_in_website>1</show_in_website>
20
+ <show_in_store>1</show_in_store>
21
+ </active>
22
+ <merchant_id translate="label">
23
+ <label>Merchant ID</label>
24
+ <frontend_type>text</frontend_type>
25
+ <sort_order>5</sort_order>
26
+ <show_in_default>1</show_in_default>
27
+ <show_in_website>1</show_in_website>
28
+ <show_in_store>1</show_in_store>
29
+ </merchant_id>
30
+ <acquirer_bin translate="label">
31
+ <label>Acquirer BIN</label>
32
+ <frontend_type>text</frontend_type>
33
+ <sort_order>10</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
+ </acquirer_bin>
38
+ <terminal_id translate="label">
39
+ <label>Terminal ID</label>
40
+ <frontend_type>text</frontend_type>
41
+ <sort_order>15</sort_order>
42
+ <show_in_default>1</show_in_default>
43
+ <show_in_website>1</show_in_website>
44
+ <show_in_store>1</show_in_store>
45
+ </terminal_id>
46
+ <clave_encriptacion translate="label">
47
+ <label>Clave de encriptacion</label>
48
+ <frontend_type>text</frontend_type>
49
+ <sort_order>20</sort_order>
50
+ <show_in_default>1</show_in_default>
51
+ <show_in_website>1</show_in_website>
52
+ <show_in_store>1</show_in_store>
53
+ </clave_encriptacion>
54
+ <produccion translate="label">
55
+ <label>¿Entorno real?</label>
56
+ <frontend_type>select</frontend_type>
57
+ <source_model>adminhtml/system_config_source_yesno</source_model>
58
+ <sort_order>25</sort_order>
59
+ <show_in_default>1</show_in_default>
60
+ <show_in_website>1</show_in_website>
61
+ <show_in_store>1</show_in_store>
62
+ </produccion>
63
+ <enviafactura translate="label">
64
+ <label>¿Enviar factura?</label>
65
+ <frontend_type>select</frontend_type>
66
+ <source_model>adminhtml/system_config_source_yesno</source_model>
67
+ <sort_order>30</sort_order>
68
+ <show_in_default>1</show_in_default>
69
+ <show_in_website>1</show_in_website>
70
+ <show_in_store>1</show_in_store>
71
+ </enviafactura>
72
+ </fields>
73
+ </ceca>
74
+ </groups>
75
+ </payment>
76
+ </sections>
77
+ </config>
app/etc/modules/Magentodesarrollo_Ceca.xml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <modules>
3
+ <Magentodesarrollo_Ceca>
4
+ <active>true</active>
5
+ <codePool>community</codePool>
6
+ <depends>
7
+ <Mage_Payment/>
8
+ </depends>
9
+ </Magentodesarrollo_Ceca>
10
+ </modules>
11
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Tpv_Ceca</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license>GPL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Pasarela bancaria de Ceca</summary>
10
+ <description>Modulo para redirigir una compra a la pasarela bancaria de ceca.</description>
11
+ <notes>testing</notes>
12
+ <authors><author><name>Magento Desarrollo</name><user>magentobk1</user><email>magentodesarrollo@brokerfashion.com</email></author></authors>
13
+ <date>2015-07-03</date>
14
+ <time>15:04:11</time>
15
+ <contents><target name="magecommunity"><dir name="Magentodesarrollo"><dir name="Ceca"><dir name="Helper"><file name="Data.php" hash="9f56090ba09c144d5330d1a3bc88f880"/></dir><dir name="Model"><file name="Paymentmethod.php" hash="e1600e8831b5133c9aab95f1bfeb78e5"/></dir><dir name="controllers"><file name="PaymentController.php" hash="dcbc5a2b282f26fbd39464d776ff48a9"/></dir><dir name="etc"><file name="config.xml" hash="b7041c2c6353902925ecd83c47322917"/><file name="system.xml" hash="82f2a7bfea20c990e9d1ed724eed6fbb"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Magentodesarrollo_Ceca.xml" hash="427d8c952d6408e5ef49721855a57175"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.4.36</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>