Eupago_MB - Version 1.1.3

Version Notes

[EN] - re-orders and trasactions is now avaiable
[PT] - novas funcionalidades : re-order e registo de transações

Download this release

Release Info

Developer Eupago
Extension Eupago_MB
Version 1.1.3
Comparing to
See all releases


Code changes from version 1.1.2 to 1.1.3

app/code/community/Eupago/Multibanco/Model/Multibanco.php CHANGED
@@ -36,8 +36,11 @@ class Eupago_Multibanco_Model_Multibanco extends Mage_Payment_Model_Method_Abstr
36
 
37
  public function order(Varien_Object $payment, $amount)
38
  {
39
-
40
- $result = $this->soapApiGeraRefMB($payment,$amount);
 
 
 
41
 
42
  if($result == false) {
43
  $errorMsg = $this->_getHelper()->__('Error Processing the request');
@@ -126,6 +129,16 @@ class Eupago_Multibanco_Model_Multibanco extends Mage_Payment_Model_Method_Abstr
126
  return 'https://seguro.eupago.pt/'.$version.'.wsdl';
127
  }
128
 
 
 
 
 
 
 
 
 
 
 
129
 
130
  // faz pedido à eupago via SOAP Para gerar Referencias Multibanco
131
  private function soapApiGeraRefMB(Varien_Object $payment, $amount){
@@ -176,29 +189,44 @@ class Eupago_Multibanco_Model_Multibanco extends Mage_Payment_Model_Method_Abstr
176
  return $result;
177
  }
178
 
 
 
179
 
180
- // public function assignData($data){
181
- // if (!($data instanceof Varien_Object)) {
182
- // $data = new Varien_Object($data);
183
- // }
184
- // $info = $this->getInfoInstance();
185
- // $info->setAdditionalInformation('multibanco_phone_number', $data->getMultibancoPhoneNumber());
186
-
187
- // return $this;
188
- // }
189
-
190
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
  public function validate(){
192
  parent::validate();
193
-
194
- $info = $this->getInfoInstance();
195
- // acrescentar as validações de valor caso existam
196
- // $no = $info->getAdditionalInformation('multibanco_phone_number');
197
 
198
- // if(empty($no) || !is_numeric($no) || strlen ($no) != 9){
199
- // $errorCode = 'invalid_data';
200
- // $errorMsg = $this->_getHelper()->__('O campo Número Multibanco parece ser inválido. Por favor verifique');
201
- // }
202
 
203
  // if(isset($errorMsg)){
204
  // Mage::throwException($errorMsg);
@@ -206,5 +234,5 @@ class Eupago_Multibanco_Model_Multibanco extends Mage_Payment_Model_Method_Abstr
206
 
207
  return $this;
208
  }
209
-
210
  }
36
 
37
  public function order(Varien_Object $payment, $amount)
38
  {
39
+ if(class_exists('SOAPClient')){
40
+ $result = $this->soapApiGeraRefMB($payment,$amount);
41
+ }else{
42
+ $result = $this->restApiGeraRefMB($payment,$amount);
43
+ }
44
 
45
  if($result == false) {
46
  $errorMsg = $this->_getHelper()->__('Error Processing the request');
129
  return 'https://seguro.eupago.pt/'.$version.'.wsdl';
130
  }
131
 
132
+ private function getRestUrl(){
133
+ $chave = $this->getConfigData('chave');
134
+ $demo = explode("-",$chave);
135
+
136
+ if($demo[0] == 'demo'){
137
+ return 'https://replica.eupago.pt/clientes/rest_api/multibanco/create';
138
+ }
139
+ return 'https://seguro.eupago.pt/clientes/rest_api/multibanco/create';
140
+ }
141
+
142
 
143
  // faz pedido à eupago via SOAP Para gerar Referencias Multibanco
144
  private function soapApiGeraRefMB(Varien_Object $payment, $amount){
189
  return $result;
190
  }
191
 
192
+ // faz pedido à eupago via REST Para gerar Referencias Multibanco
193
+ private function restApiGeraRefMB(Varien_Object $payment, $amount){
194
 
195
+ $per_dup = $this->getConfigData('per_dup');
196
+
197
+ $n_dias = $this->getConfigData('payment_deadline');
198
+
199
+ $order = $payment->getOrder();
200
+
201
+ $client = new Varien_Http_Client($this->getRestUrl());
202
+ $client->setMethod(Varien_Http_Client::POST);
203
+ $client->setParameterPost('chave', $this->getConfigData('chave'));
204
+ $client->setParameterPost('valor', $amount);
205
+ $client->setParameterPost('id', $order->getIncrementId());
206
+ if($per_dup != 1 || (is_numeric($n_dias) && $n_dias > 0)){
207
+ $data_inicio = date("Y-m-d");
208
+ $data_fim = (is_numeric($n_dias) && $n_dias > 0) ? date('Y-m-d', strtotime('+'.$n_dias.' day', strtotime($data_inicio))) : "2099-12-31";
209
+ $per_dup =($per_dup == true) ? 1 : 0;
210
+ $client->setParameterPost('data_inicio', $data_inicio);
211
+ $client->setParameterPost('data_fim', $data_fim);
212
+ $client->setParameterPost('per_dup', $per_dup);
213
+ }
214
+
215
+ $result = $client->request();
216
+ if ($result->isSuccessful()){
217
+ return json_decode($result->getBody());
218
+ }else{
219
+ Mage::throwException("Ocorreu um erro ao gerar a referência multibanco");
220
+ return false;
221
+ }
222
+
223
+ }
224
+
225
+
226
  public function validate(){
227
  parent::validate();
 
 
 
 
228
 
229
+ // acrescentar as validações de valor caso existam
 
 
 
230
 
231
  // if(isset($errorMsg)){
232
  // Mage::throwException($errorMsg);
234
 
235
  return $this;
236
  }
237
+
238
  }
app/code/community/Eupago/Multibanco/controllers/CallbackController.php CHANGED
@@ -47,21 +47,110 @@ class Eupago_Multibanco_CallbackController extends Mage_Core_Controller_Front_Ac
47
 
48
  // marca como paga ou gera fatura
49
  if($this->validaTransacao($callBack_params, $order)){
50
- //$this->marcaComoPaga($order, $callBack_params->valor); // -> para usar para marcar como paga sem gerar fatura
51
- $this->capture($order);
 
 
52
  }
53
  }
54
 
55
- private function marcaComoPaga($order,$valor_pago){
 
56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  $order->setData('state', "complete");
58
  $order->setStatus("processing");
59
  $order->sendOrderUpdateEmail();
60
  $history = $order->addStatusHistoryComment('Encomenda paga por MULTIBANCO.', false);
61
  $history->setIsCustomerNotified(true);
 
 
62
  $order->setTotalPaid($valor_pago);
63
  $order->save();
64
- echo "estado alterado para processing com sucesso";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  }
66
 
67
  private function validaTransacao($CallBack, $order){
47
 
48
  // marca como paga ou gera fatura
49
  if($this->validaTransacao($callBack_params, $order)){
50
+ if(class_exists('SOAPClient'))
51
+ $this->capture($order);
52
+ else
53
+ $this->marcaComoPaga($order, $callBack_params->valor, true); // -> para usar para marcar como paga sem gerar fatura
54
  }
55
  }
56
 
57
+ // CALLBACK ANTIGO FICARÁ DEPRECATED NA PROXIMA VERSÃO
58
+ public function autorizeAction(){
59
 
60
+ ///// dados vindos da api para comfirmar
61
+ $CallBack = $this->getRequest()->getParams();
62
+ $CallBack_valor = $CallBack['valor'];
63
+ $CallBack_referencia = $CallBack['referencia'];
64
+ $CallBack_chave_api = $CallBack['chave_api'];
65
+ $CallBack_orderId = $CallBack['identificador'];
66
+ $CallBack_autorizacao = $CallBack['autorizacao'];
67
+
68
+
69
+ ////// dados de encomenda
70
+ $OrderNumber = $CallBack_orderId; //$CallBack_orderId vaem da api Eupago[order-id]
71
+ $order = Mage::getModel('sales/order')->load($OrderNumber, 'increment_id');
72
+ $valor_encomenda = $order->grand_total; //retirado do valor total da encomenda
73
+
74
+ /////// dados do pagamento
75
+ $pagamento = $order->getPayment();
76
+
77
+ // se não existir dados de pagamento antigos chama o novo callback
78
+ if($pagamento->eupago_referencia == null || $pagamento->eupago_referencia == "" ){
79
+ $this->multibancoAction();
80
+ return;
81
+ }
82
+
83
+ /////// dados do pagamento antigos
84
+ $entidade = $pagamento->eupago_entidade;
85
+ $referencia = str_pad($pagamento->eupago_referencia, 9, "0", STR_PAD_LEFT);
86
+ $valor_gerado = $pagamento->eupago_montante;
87
+
88
+ /////// gera autorizacao
89
+ $chave_api = Mage::getStoreConfig('payment/multibanco/chave');
90
+ $autorizacao = md5(date('Y-m-d').$chave_api);
91
+
92
+ //////// Confere dados
93
+ $confere_montantes = (($valor_encomenda == $valor_gerado) == $CallBack_valor ? true : false);
94
+ $confere_autorizacao = ($autorizacao == $CallBack_autorizacao ? true : false);
95
+ $confere_referencia = ($referencia == $CallBack_referencia ? true : false);
96
+ $confere_chave_api = ($CallBack_chave_api == $chave_api ? true : false);
97
+
98
+
99
+ ////// se tudo ok, faz o update do estado da encomenda e envia um email ao cliente
100
+ if($confere_montantes && $confere_chave_api && $confere_referencia){ /*futuro upgrade -> $confere_autorizacao*/
101
+
102
+ $order->setData('state', "complete");
103
+ $order->setStatus("processing");
104
+ $order->sendOrderUpdateEmail();
105
+
106
+ //////// hack for generate invoice automatically
107
+ $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
108
+ if (!$invoice->getTotalQty()) {
109
+ Mage::throwException(Mage::helper('core')->__('Cannot create an invoice without products.'));
110
+ }
111
+ $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_OFFLINE);
112
+ $invoice->register();
113
+ $transactionSave = Mage::getModel('core/resource_transaction')
114
+ ->addObject($invoice)
115
+ ->addObject($invoice->getOrder());
116
+ $transactionSave->save();
117
+ ////////////////
118
+
119
+ $history = $order->addStatusHistoryComment('Order marked as complete automatically.', false);
120
+ $history->setIsCustomerNotified(true);
121
+ $order->save();
122
+
123
+ echo "alterado para pago..";
124
+ }else{
125
+ echo "os valores de pagamento não correspondem com os da encomenda";
126
+ }
127
+ }
128
+
129
+ private function marcaComoPaga($order,$valor_pago,$geraFatura = false){
130
  $order->setData('state', "complete");
131
  $order->setStatus("processing");
132
  $order->sendOrderUpdateEmail();
133
  $history = $order->addStatusHistoryComment('Encomenda paga por MULTIBANCO.', false);
134
  $history->setIsCustomerNotified(true);
135
+ if($geraFatura)
136
+ $this->geraFatura($order);
137
  $order->setTotalPaid($valor_pago);
138
  $order->save();
139
+ echo "estado alterado para processing com sucesso. e gerada fatura sem transação";
140
+ }
141
+
142
+ private function geraFatura($order){
143
+ //////// hack para gerar fatura sem transação automaticamente
144
+ $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
145
+ if (!$invoice->getTotalQty()) {
146
+ Mage::throwException(Mage::helper('core')->__('Cannot create an invoice without products.'));
147
+ }
148
+ $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_OFFLINE);
149
+ $invoice->register();
150
+ $transactionSave = Mage::getModel('core/resource_transaction')
151
+ ->addObject($invoice)
152
+ ->addObject($invoice->getOrder());
153
+ $transactionSave->save();
154
  }
155
 
156
  private function validaTransacao($CallBack, $order){
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Eupago_MB</name>
4
- <version>1.1.2</version>
5
  <stability>stable</stability>
6
  <license>GNU General Public License (GPL)</license>
7
  <channel>community</channel>
@@ -11,9 +11,9 @@
11
  <notes>[EN] - re-orders and trasactions is now avaiable&#xD;
12
  [PT] - novas funcionalidades : re-order e registo de transa&#xE7;&#xF5;es</notes>
13
  <authors><author><name>Eupago</name><user>eupago</user><email>suporte@eupago.pt</email></author></authors>
14
- <date>2016-12-02</date>
15
- <time>18:43:37</time>
16
- <contents><target name="magecommunity"><dir name="Eupago"><dir name="Multibanco"><dir name="Block"><dir name="Form"><file name="Multibanco.php" hash="a526f756cd407a159a5438efefa0d66f"/></dir><dir name="Info"><file name="Multibanco.php" hash="460f7315eecf5b43574eac9fd30844ac"/></dir><dir name="Onepage"><file name="Success.php" hash="9da0851f53a89abeb25602d3c94a2612"/></dir></dir><dir name="Model"><file name="Multibanco.php" hash="5f34211caaa4f2564d1213779de0e2bf"/><dir name="System"><dir name="Config"><file name="Template.php" hash="fd636ddfc0a57d9e904ceb913415398d"/></dir></dir></dir><dir name="controllers"><file name="CallbackController.php" hash="a4cd7c27de50d646c2778eefde1e2495"/></dir><dir name="etc"><file name="config.xml" hash="179d01bf0777fd0c2e4e49e86282abce"/><file name="system.xml" hash="f25b77b36ec9b9cddbbd4131b861bcd7"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Eupago_Multibanco.xml" hash="87ee673b7cd7ec1dbc44cf2a0ef0f0c3"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="eupago"><dir name="multibanco"><dir name="checkout"><file name="success.phtml" hash="65c0fbce628ecdb41855475826cbbc2b"/></dir><dir name="info"><file name="default.phtml" hash="a74d2e7e6bf4cc69995b6d513cd06859"/><file name="multibanco.phtml" hash="a502ada6767afe020486170e6243e086"/></dir></dir></dir></dir><dir name="layout"><file name="eupago_multibanco.xml" hash="e3fbf5f655164991b363b305e09b0953"/></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="eupago"><dir name="multibanco"><dir name="info"><file name="multibanco.phtml" hash="47d133c69fb6121b648037995c868740"/></dir></dir></dir></dir></dir></dir></dir></target><target name="mageskin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="images"><dir name="eupago"><dir name="multibanco"><file name="eupago_mb_p.png" hash="6db08f88f1f4770337db63105a4f0f08"/><file name="multibanco_icon.png" hash="87425d6e05c42ae6780b16ca8379d97a"/></dir></dir></dir></dir></dir></dir></target></contents>
17
  <compatible/>
18
  <dependencies><required><php><min>5.2.0</min><max>7.0.0</max></php></required></dependencies>
19
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Eupago_MB</name>
4
+ <version>1.1.3</version>
5
  <stability>stable</stability>
6
  <license>GNU General Public License (GPL)</license>
7
  <channel>community</channel>
11
  <notes>[EN] - re-orders and trasactions is now avaiable&#xD;
12
  [PT] - novas funcionalidades : re-order e registo de transa&#xE7;&#xF5;es</notes>
13
  <authors><author><name>Eupago</name><user>eupago</user><email>suporte@eupago.pt</email></author></authors>
14
+ <date>2016-12-05</date>
15
+ <time>17:34:15</time>
16
+ <contents><target name="magecommunity"><dir name="Eupago"><dir name="Multibanco"><dir name="Block"><dir name="Form"><file name="Multibanco.php" hash="a526f756cd407a159a5438efefa0d66f"/></dir><dir name="Info"><file name="Multibanco.php" hash="460f7315eecf5b43574eac9fd30844ac"/></dir><dir name="Onepage"><file name="Success.php" hash="9da0851f53a89abeb25602d3c94a2612"/></dir></dir><dir name="Model"><file name="Multibanco.php" hash="d9f2858be6fe35eeffd9eaa8f9a884f1"/><dir name="System"><dir name="Config"><file name="Template.php" hash="fd636ddfc0a57d9e904ceb913415398d"/></dir></dir></dir><dir name="controllers"><file name="CallbackController.php" hash="3fb7fad856b683a4ea0f2b3434edaac9"/></dir><dir name="etc"><file name="config.xml" hash="179d01bf0777fd0c2e4e49e86282abce"/><file name="system.xml" hash="f25b77b36ec9b9cddbbd4131b861bcd7"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Eupago_Multibanco.xml" hash="87ee673b7cd7ec1dbc44cf2a0ef0f0c3"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="eupago"><dir name="multibanco"><dir name="checkout"><file name="success.phtml" hash="65c0fbce628ecdb41855475826cbbc2b"/></dir><dir name="info"><file name="default.phtml" hash="a74d2e7e6bf4cc69995b6d513cd06859"/><file name="multibanco.phtml" hash="a502ada6767afe020486170e6243e086"/></dir></dir></dir></dir><dir name="layout"><file name="eupago_multibanco.xml" hash="e3fbf5f655164991b363b305e09b0953"/></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="eupago"><dir name="multibanco"><dir name="info"><file name="multibanco.phtml" hash="47d133c69fb6121b648037995c868740"/></dir></dir></dir></dir></dir></dir></dir></target><target name="mageskin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="images"><dir name="eupago"><dir name="multibanco"><file name="eupago_mb_p.png" hash="6db08f88f1f4770337db63105a4f0f08"/><file name="multibanco_icon.png" hash="87425d6e05c42ae6780b16ca8379d97a"/></dir></dir></dir></dir></dir></dir></target></contents>
17
  <compatible/>
18
  <dependencies><required><php><min>5.2.0</min><max>7.0.0</max></php></required></dependencies>
19
  </package>