RicardoMartins_PagSeguro - Version 3.0.1

Version Notes

Versão estável.

Os bugs devem ser reportados na área de Issues no github do projeto em https://github.com/r-martins/PagSeguro-Magento-Transparente

Download this release

Release Info

Developer Ricardo Martins
Extension RicardoMartins_PagSeguro
Version 3.0.1
Comparing to
See all releases


Code changes from version 2.5.6 to 3.0.1

Files changed (22) hide show
  1. app/code/community/RicardoMartins/PagSeguro/Helper/Data.php +46 -14
  2. app/code/community/RicardoMartins/PagSeguro/Helper/Internal.php +4 -1
  3. app/code/community/RicardoMartins/PagSeguro/Helper/Params.php +33 -7
  4. app/code/community/RicardoMartins/PagSeguro/Model/Abstract.php +98 -22
  5. app/code/community/RicardoMartins/PagSeguro/Model/Observer.php +1 -1
  6. app/code/community/RicardoMartins/PagSeguro/Model/Payment/Cc.php +35 -14
  7. app/code/community/RicardoMartins/PagSeguro/Model/Source/Ccbrand.php +26 -0
  8. app/code/community/RicardoMartins/PagSeguro/controllers/AjaxController.php +15 -0
  9. app/code/community/RicardoMartins/PagSeguro/controllers/TestController.php +68 -8
  10. app/code/community/RicardoMartins/PagSeguro/data/ricardomartins_pagseguro_setup/data-install-3.0.0.php +18 -0
  11. app/code/community/RicardoMartins/PagSeguro/etc/config.xml +17 -6
  12. app/code/community/RicardoMartins/PagSeguro/etc/system.xml +37 -5
  13. app/design/adminhtml/base/default/template/ricardomartins_pagseguro/form/cc.phtml +105 -0
  14. app/design/adminhtml/base/default/template/ricardomartins_pagseguro/form/cc/dob.phtml +87 -0
  15. app/design/adminhtml/base/default/template/ricardomartins_pagseguro/form/directpayment.phtml +14 -11
  16. app/design/frontend/base/default/template/ricardomartins_pagseguro/form/cc.phtml +26 -5
  17. app/design/frontend/base/default/template/ricardomartins_pagseguro/form/cc/dob.phtml +3 -3
  18. app/design/frontend/base/default/template/ricardomartins_pagseguro/form/directpayment.phtml +11 -12
  19. js/pagseguro/card.js +2495 -0
  20. js/pagseguro/pagseguro.js +221 -150
  21. package.xml +5 -5
  22. skin/frontend/base/default/pagseguro/selo/brflag.png +0 -0
app/code/community/RicardoMartins/PagSeguro/Helper/Data.php CHANGED
@@ -11,18 +11,24 @@
11
*/
12
class RicardoMartins_PagSeguro_Helper_Data extends Mage_Core_Helper_Abstract
13
{
14
- const XML_PATH_PAYMENT_PAGSEGURO_EMAIL = 'payment/pagseguro/merchant_email';
15
- const XML_PATH_PAYMENT_PAGSEGURO_TOKEN = 'payment/pagseguro/token';
16
- const XML_PATH_PAYMENT_PAGSEGURO_DEBUG = 'payment/pagseguro/debug';
17
- const XML_PATH_PAUMENT_PAGSEGURO_SANDBOX = 'payment/pagseguro/sandbox';
18
- const XML_PATH_PAYMENT_PAGSEGURO_SANDBOX_EMAIL = 'payment/pagseguro/sandbox_merchant_email';
19
- const XML_PATH_PAYMENT_PAGSEGURO_SANDBOX_TOKEN = 'payment/pagseguro/sandbox_token';
20
- const XML_PATH_PAYMENT_PAGSEGURO_WS_URL = 'payment/pagseguro/ws_url';
21
- const XML_PATH_PAYMENT_PAGSEGURO_WS_URL_APP = 'payment/pagseguro/ws_url_app';
22
- const XML_PATH_PAYMENT_PAGSEGURO_JS_URL = 'payment/pagseguro/js_url';
23
- const XML_PATH_PAYMENT_PAGSEGURO_SANDBOX_WS_URL = 'payment/pagseguro/sandbox_ws_url';
24
- const XML_PATH_PAYMENT_PAGSEGURO_SANDBOX_WS_URL_APP = 'payment/pagseguro/sandbox_ws_url_app';
25
- const XML_PATH_PAYMENT_PAGSEGURO_SANDBOX_JS_URL = 'payment/pagseguro/sandbox_js_url';
26
const XML_PATH_PAYMENT_PAGSEGURO_KEY = 'payment/pagseguropro/key';
27
28
/**
@@ -187,7 +193,7 @@ class RicardoMartins_PagSeguro_Helper_Data extends Mage_Core_Helper_Abstract
187
*/
188
public function isCpfVisible()
189
{
190
- $customerCpfAttribute = Mage::getStoreConfig('payment/pagseguro/customer_cpf_attribute');
191
return empty($customerCpfAttribute);
192
}
193
@@ -243,7 +249,7 @@ class RicardoMartins_PagSeguro_Helper_Data extends Mage_Core_Helper_Abstract
243
public function checkTokenIntegrity()
244
{
245
$section = Mage::getSingleton('adminhtml/config')->getSection('payment');
246
- $frontendType = (string)$section->groups->pagseguro->fields->token->frontend_type;
247
248
if ('obscure' != $frontendType) {
249
$this->writeLog(
@@ -285,4 +291,30 @@ class RicardoMartins_PagSeguro_Helper_Data extends Mage_Core_Helper_Abstract
285
);
286
return $scriptBlock;
287
}
288
}
11
*/
12
class RicardoMartins_PagSeguro_Helper_Data extends Mage_Core_Helper_Abstract
13
{
14
+ const XML_PATH_PAYMENT_PAGSEGURO_EMAIL = 'payment/rm_pagseguro/merchant_email';
15
+ const XML_PATH_PAYMENT_PAGSEGURO_TOKEN = 'payment/rm_pagseguro/token';
16
+ const XML_PATH_PAYMENT_PAGSEGURO_DEBUG = 'payment/rm_pagseguro/debug';
17
+ const XML_PATH_PAUMENT_PAGSEGURO_SANDBOX = 'payment/rm_pagseguro/sandbox';
18
+ const XML_PATH_PAYMENT_PAGSEGURO_SANDBOX_EMAIL = 'payment/rm_pagseguro/sandbox_merchant_email';
19
+ const XML_PATH_PAYMENT_PAGSEGURO_SANDBOX_TOKEN = 'payment/rm_pagseguro/sandbox_token';
20
+ const XML_PATH_PAYMENT_PAGSEGURO_WS_URL = 'payment/rm_pagseguro/ws_url';
21
+ const XML_PATH_PAYMENT_PAGSEGURO_WS_URL_APP = 'payment/rm_pagseguro/ws_url_app';
22
+ const XML_PATH_PAYMENT_PAGSEGURO_JS_URL = 'payment/rm_pagseguro/js_url';
23
+ const XML_PATH_PAYMENT_PAGSEGURO_SANDBOX_WS_URL = 'payment/rm_pagseguro/sandbox_ws_url';
24
+ const XML_PATH_PAYMENT_PAGSEGURO_SANDBOX_WS_URL_APP = 'payment/rm_pagseguro/sandbox_ws_url_app';
25
+ const XML_PATH_PAYMENT_PAGSEGURO_SANDBOX_JS_URL = 'payment/rm_pagseguro/sandbox_js_url';
26
+ const XML_PATH_PAYMENT_PAGSEGURO_CC_ACTIVE = 'payment/rm_pagseguro_cc/active';
27
+ const XML_PATH_PAYMENT_PAGSEGURO_CC_FLAG = 'payment/rm_pagseguro_cc/flag';
28
+ const XML_PATH_PAYMENT_PAGSEGURO_CC_INFO_BRL = 'payment/rm_pagseguro_cc/info_brl';
29
+ const XML_PATH_PAYMENT_PAGSEGURO_CC_SHOW_TOTAL = 'payment/rm_pagseguro_cc/show_total';
30
+ const XML_PATH_PAYMENT_PAGSEGUROPRO_TEF_ACTIVE = 'payment/pagseguropro_tef/active';
31
+ const XML_PATH_PAYMENT_PAGSEGUROPRO_BOLETO_ACTIVE = 'payment/pagseguropro_boleto/active';
32
const XML_PATH_PAYMENT_PAGSEGURO_KEY = 'payment/pagseguropro/key';
33
34
/**
193
*/
194
public function isCpfVisible()
195
{
196
+ $customerCpfAttribute = Mage::getStoreConfig('payment/rm_pagseguro/customer_cpf_attribute');
197
return empty($customerCpfAttribute);
198
}
199
249
public function checkTokenIntegrity()
250
{
251
$section = Mage::getSingleton('adminhtml/config')->getSection('payment');
252
+ $frontendType = (string)$section->groups->rm_pagseguro->fields->token->frontend_type;
253
254
if ('obscure' != $frontendType) {
255
$this->writeLog(
291
);
292
return $scriptBlock;
293
}
294
+
295
+ /**
296
+ * Return serialized (json) string with module configuration
297
+ * return string
298
+ */
299
+ public function getConfigJs()
300
+ {
301
+ $config = array(
302
+ 'active_methods' => array(
303
+ 'cc' => (int)Mage::getStoreConfigFlag(self::XML_PATH_PAYMENT_PAGSEGURO_CC_ACTIVE),
304
+ 'boleto' => (int)Mage::getStoreConfigFlag(self::XML_PATH_PAYMENT_PAGSEGUROPRO_BOLETO_ACTIVE),
305
+ 'tef' => (int)Mage::getStoreConfigFlag(self::XML_PATH_PAYMENT_PAGSEGUROPRO_TEF_ACTIVE)
306
+ ),
307
+ 'flag' => Mage::getStoreConfig(self::XML_PATH_PAYMENT_PAGSEGURO_CC_FLAG),
308
+ 'debug' => $this->isDebugActive(),
309
+ 'PagSeguroSessionId' => $this->getSessionId(),
310
+ 'is_admin' => Mage::app()->getStore()->isAdmin(),
311
+ 'show_total' => Mage::getStoreConfigFlag(self::XML_PATH_PAYMENT_PAGSEGURO_CC_SHOW_TOTAL),
312
+ );
313
+ return json_encode($config);
314
+ }
315
+
316
+ public function isInfoBrlActive()
317
+ {
318
+ return Mage::getStoreConfigFlag(self::XML_PATH_PAYMENT_PAGSEGURO_CC_INFO_BRL);
319
+ }
320
}
app/code/community/RicardoMartins/PagSeguro/Helper/Internal.php CHANGED
@@ -32,7 +32,10 @@ class RicardoMartins_PagSeguro_Helper_Internal extends Mage_Core_Helper_Abstract
32
*/
33
public function getCreditCardApiCallParams(Mage_Sales_Model_Order $order, $payment)
34
{
35
$helper = Mage::helper('ricardomartins_pagseguro');
36
$pHelper = Mage::helper('ricardomartins_pagseguro/params'); //params helper - helper auxiliar de parametrização
37
$params = array(
38
'email' => $helper->getMerchantEmail(),
@@ -41,7 +44,7 @@ class RicardoMartins_PagSeguro_Helper_Internal extends Mage_Core_Helper_Abstract
41
'paymentMethod' => 'creditCard',
42
'receiverEmail' => $helper->getMerchantEmail(),
43
'currency' => 'BRL',
44
- 'creditCardToken' => $payment['additional_information']['credit_card_token'],
45
'reference' => $order->getIncrementId(),
46
'extraAmount' => $pHelper->getExtraAmount($order),
47
'notificationURL' => Mage::getUrl('ricardomartins_pagseguro/notification'),
32
*/
33
public function getCreditCardApiCallParams(Mage_Sales_Model_Order $order, $payment)
34
{
35
+ /** @var RicardoMartins_PagSeguro_Helper_Data $helper */
36
$helper = Mage::helper('ricardomartins_pagseguro');
37
+
38
+ /** @var RicardoMartins_PagSeguro_Helper_Params $pHelper */
39
$pHelper = Mage::helper('ricardomartins_pagseguro/params'); //params helper - helper auxiliar de parametrização
40
$params = array(
41
'email' => $helper->getMerchantEmail(),
44
'paymentMethod' => 'creditCard',
45
'receiverEmail' => $helper->getMerchantEmail(),
46
'currency' => 'BRL',
47
+ 'creditCardToken' => $pHelper->getPaymentHash('credit_card_token'),
48
'reference' => $order->getIncrementId(),
49
'extraAmount' => $pHelper->getExtraAmount($order),
50
'notificationURL' => Mage::getUrl('ricardomartins_pagseguro/notification'),
app/code/community/RicardoMartins/PagSeguro/Helper/Params.php CHANGED
@@ -45,7 +45,6 @@ class RicardoMartins_PagSeguro_Helper_Params extends Mage_Core_Helper_Abstract
45
46
$phone = $this->_extractPhone($order->getBillingAddress()->getTelephone());
47
48
-
49
$senderName = $this->removeDuplicatedSpaces(
50
sprintf('%s %s', $order->getCustomerFirstname(), $order->getCustomerLastname())
51
);
@@ -55,7 +54,7 @@ class RicardoMartins_PagSeguro_Helper_Params extends Mage_Core_Helper_Abstract
55
$return = array(
56
'senderName' => $senderName,
57
'senderEmail' => trim($order->getCustomerEmail()),
58
- 'senderHash' => $payment['additional_information']['sender_hash'],
59
'senderCPF' => $digits->filter($cpf),
60
'senderAreaCode'=> $phone['area'],
61
'senderPhone' => $phone['number'],
@@ -138,10 +137,10 @@ class RicardoMartins_PagSeguro_Helper_Params extends Mage_Core_Helper_Abstract
138
/** @var Mage_Sales_Model_Order_Address $address */
139
$address = ($type=='shipping' && !$order->getIsVirtual()) ?
140
$order->getShippingAddress() : $order->getBillingAddress();
141
- $addressStreetAttribute = Mage::getStoreConfig('payment/pagseguro/address_street_attribute');
142
- $addressNumberAttribute = Mage::getStoreConfig('payment/pagseguro/address_number_attribute');
143
- $addressComplementAttribute = Mage::getStoreConfig('payment/pagseguro/address_complement_attribute');
144
- $addressNeighborhoodAttribute = Mage::getStoreConfig('payment/pagseguro/address_neighborhood_attribute');
145
146
//gathering address data
147
$addressStreet = $this->_getAddressAttributeValue($address, $addressStreetAttribute);
@@ -415,7 +414,7 @@ class RicardoMartins_PagSeguro_Helper_Params extends Mage_Core_Helper_Abstract
415
*/
416
private function _getCustomerCpfValue(Mage_Sales_Model_Order $order, $payment)
417
{
418
- $customerCpfAttribute = Mage::getStoreConfig('payment/pagseguro/customer_cpf_attribute');
419
420
if (empty($customerCpfAttribute)) { //Asked with payment data
421
if (isset($payment['additional_information'][$payment->getMethod() . '_cpf'])) {
@@ -477,4 +476,31 @@ class RicardoMartins_PagSeguro_Helper_Params extends Mage_Core_Helper_Abstract
477
}
478
return (abs($extraAmount) == $totalAmount);
479
}
480
}
45
46
$phone = $this->_extractPhone($order->getBillingAddress()->getTelephone());
47
48
$senderName = $this->removeDuplicatedSpaces(
49
sprintf('%s %s', $order->getCustomerFirstname(), $order->getCustomerLastname())
50
);
54
$return = array(
55
'senderName' => $senderName,
56
'senderEmail' => trim($order->getCustomerEmail()),
57
+ 'senderHash' => $this->getPaymentHash('sender_hash'),
58
'senderCPF' => $digits->filter($cpf),
59
'senderAreaCode'=> $phone['area'],
60
'senderPhone' => $phone['number'],
137
/** @var Mage_Sales_Model_Order_Address $address */
138
$address = ($type=='shipping' && !$order->getIsVirtual()) ?
139
$order->getShippingAddress() : $order->getBillingAddress();
140
+ $addressStreetAttribute = Mage::getStoreConfig('payment/rm_pagseguro/address_street_attribute');
141
+ $addressNumberAttribute = Mage::getStoreConfig('payment/rm_pagseguro/address_number_attribute');
142
+ $addressComplementAttribute = Mage::getStoreConfig('payment/rm_pagseguro/address_complement_attribute');
143
+ $addressNeighborhoodAttribute = Mage::getStoreConfig('payment/rm_pagseguro/address_neighborhood_attribute');
144
145
//gathering address data
146
$addressStreet = $this->_getAddressAttributeValue($address, $addressStreetAttribute);
414
*/
415
private function _getCustomerCpfValue(Mage_Sales_Model_Order $order, $payment)
416
{
417
+ $customerCpfAttribute = Mage::getStoreConfig('payment/rm_pagseguro/customer_cpf_attribute');
418
419
if (empty($customerCpfAttribute)) { //Asked with payment data
420
if (isset($payment['additional_information'][$payment->getMethod() . '_cpf'])) {
476
}
477
return (abs($extraAmount) == $totalAmount);
478
}
479
+
480
+ /**
481
+ * Get payment hashes (sender_hash & credit_card_token) from session
482
+ * @param string $param sender_hash or credit_card_token
483
+ *
484
+ * @return bool|string
485
+ */
486
+ public function getPaymentHash($param=null)
487
+ {
488
+ $isAdmin = Mage::app()->getStore()->isAdmin();
489
+ $session = ($isAdmin)?'core/cookie':'checkout/session';
490
+ $registry = Mage::getSingleton($session);
491
+
492
+ $registry = ($isAdmin)?$registry->get('PsPayment'):$registry->getData('PsPayment');
493
+
494
+ $registry = unserialize($registry);
495
+
496
+ if (is_null($param)) {
497
+ return $registry;
498
+ }
499
+
500
+ if (isset($registry[$param])) {
501
+ return $registry[$param];
502
+ }
503
+
504
+ return false;
505
+ }
506
}
app/code/community/RicardoMartins/PagSeguro/Model/Abstract.php CHANGED
@@ -11,6 +11,7 @@
11
*/
12
class RicardoMartins_PagSeguro_Model_Abstract extends Mage_Payment_Model_Method_Abstract
13
{
14
/**
15
* Processes notification XML data. XML is sent right after order is sent to PagSeguro, and on order updates.
16
* @see https://pagseguro.uol.com.br/v2/guia-de-integracao/api-de-notificacoes.html#v2-item-servico-de-notificacoes
@@ -18,6 +19,13 @@ class RicardoMartins_PagSeguro_Model_Abstract extends Mage_Payment_Model_Method_
18
*/
19
public function proccessNotificatonResult(SimpleXMLElement $resultXML)
20
{
21
if (isset($resultXML->error)) {
22
$errMsg = Mage::helper('ricardomartins_pagseguro')->__((string)$resultXML->error->message);
23
Mage::throwException(
@@ -32,22 +40,24 @@ class RicardoMartins_PagSeguro_Model_Abstract extends Mage_Payment_Model_Method_
32
/** @var Mage_Sales_Model_Order $order */
33
$order = Mage::getModel('sales/order')->loadByIncrementId((string)$resultXML->reference);
34
$payment = $order->getPayment();
35
$this->_code = $payment->getMethod();
36
$processedState = $this->processStatus((int)$resultXML->status);
37
$message = $processedState->getMessage();
38
39
if ((int)$resultXML->status == 6) { //valor devolvido (gera credit memo e tenta cancelar o pedido)
40
if ($order->canUnhold()) {
41
$order->unhold();
42
}
43
if ($order->canCancel()) {
44
$order->cancel();
45
$order->save();
46
} else {
47
$payment->registerRefundNotification(floatval($resultXML->grossAmount));
48
$order->addStatusHistoryComment(
49
- 'Devolvido: o valor foi devolvido ao comprador, mas o
50
- pedido encontra-se em um estado que não pode ser cancelado.'
51
)->save();
52
}
53
}
@@ -67,28 +77,38 @@ class RicardoMartins_PagSeguro_Model_Abstract extends Mage_Payment_Model_Method_
67
}
68
69
if ($processedState->getStateChanged()) {
70
- $order->setState(
71
- $processedState->getState(),
72
- true,
73
- $message,
74
- $processedState->getIsCustomerNotified()
75
- )->save();
76
} else {
77
$order->addStatusHistoryComment($message);
78
}
79
80
if ((int)$resultXML->status == 3) { //Quando o pedido foi dado como Pago
81
- //cria fatura e envia email (se configurado)
82
- // $payment->registerCaptureNotification(floatval($resultXML->grossAmount));
83
if(!$order->hasInvoices()){
84
$invoice = $order->prepareInvoice();
85
$invoice->register()->pay();
86
$msg = sprintf('Pagamento capturado. Identificador da Transação: %s', (string)$resultXML->code);
87
$invoice->addComment($msg);
88
$invoice->sendEmail(
89
- Mage::getStoreConfigFlag('payment/pagseguro/send_invoice_email'),
90
'Pagamento recebido com sucesso.'
91
);
92
Mage::getModel('core/resource_transaction')
93
->addObject($invoice)
94
->addObject($invoice->getOrder())
@@ -132,7 +152,7 @@ class RicardoMartins_PagSeguro_Model_Abstract extends Mage_Payment_Model_Method_
132
133
$client->request();
134
$resposta = $client->getLastResponse()->getBody();
135
-
136
$helper->writeLog(sprintf('Retorno do Pagseguro para notificationCode %s: %s', $notificationCode, $resposta));
137
138
libxml_use_internal_errors(true);
@@ -155,6 +175,7 @@ class RicardoMartins_PagSeguro_Model_Abstract extends Mage_Payment_Model_Method_
155
$return = new Varien_Object();
156
$return->setStateChanged(true);
157
$return->setIsTransactionPending(true); //payment is pending?
158
switch($statusCode)
159
{
160
case '1':
@@ -204,7 +225,8 @@ class RicardoMartins_PagSeguro_Model_Abstract extends Mage_Payment_Model_Method_
204
);
205
break;
206
case '6':
207
- $return->setState(Mage_Sales_Model_Order::STATE_CLOSED);
208
$return->setIsCustomerNotified(false);
209
$return->setIsTransactionPending(false);
210
$return->setMessage('Devolvida: o valor da transação foi devolvido para o comprador.');
@@ -226,10 +248,11 @@ class RicardoMartins_PagSeguro_Model_Abstract extends Mage_Payment_Model_Method_
226
* Call PagSeguro API to place an order (/transactions)
227
* @param $params
228
* @param $payment
229
*
230
* @return SimpleXMLElement
231
*/
232
- public function callApi($params, $payment)
233
{
234
$helper = Mage::helper('ricardomartins_pagseguro');
235
$useApp = $helper->getLicenseType() == 'app';
@@ -238,11 +261,11 @@ class RicardoMartins_PagSeguro_Model_Abstract extends Mage_Payment_Model_Method_
238
}
239
$params = $this->_convertEncoding($params);
240
$paramsString = $this->_convertToCURLString($params);
241
-
242
- $helper->writeLog('Parametros sendo enviados para API (/transactions): '. var_export($params, true));
243
-
244
$ch = curl_init();
245
- curl_setopt($ch, CURLOPT_URL, $helper->getWsUrl('transactions', $useApp));
246
curl_setopt($ch, CURLOPT_POST, count($params));
247
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
248
curl_setopt($ch, CURLOPT_POSTFIELDS, $paramsString);
@@ -263,10 +286,11 @@ class RicardoMartins_PagSeguro_Model_Abstract extends Mage_Payment_Model_Method_
263
}
264
curl_close($ch);
265
266
- $helper->writeLog('Retorno PagSeguro (/transactions): ' . var_export($response, true));
267
268
libxml_use_internal_errors(true);
269
$xml = simplexml_load_string(trim($response));
270
if (false === $xml) {
271
switch($response){
272
case 'Unauthorized':
@@ -287,10 +311,60 @@ class RicardoMartins_PagSeguro_Model_Abstract extends Mage_Payment_Model_Method_
287
'Houve uma falha ao processar seu pedido/pagamento. Por favor entre em contato conosco.'
288
);
289
}
290
-
291
return $xml;
292
}
293
294
/**
295
* Convert array values to utf-8
296
* @param array $params
@@ -304,7 +378,7 @@ class RicardoMartins_PagSeguro_Model_Abstract extends Mage_Payment_Model_Method_
304
}
305
return $params;
306
}
307
-
308
/**
309
* Convert API params (already ISO-8859-1) to url format (curl string)
310
* @param array $params
@@ -317,7 +391,9 @@ class RicardoMartins_PagSeguro_Model_Abstract extends Mage_Payment_Model_Method_
317
foreach ($params as $k => $v) {
318
$fieldsString .= $k.'='.urlencode($v).'&';
319
}
320
-
321
return rtrim($fieldsString, '&');
322
}
323
}
11
*/
12
class RicardoMartins_PagSeguro_Model_Abstract extends Mage_Payment_Model_Method_Abstract
13
{
14
+
15
/**
16
* Processes notification XML data. XML is sent right after order is sent to PagSeguro, and on order updates.
17
* @see https://pagseguro.uol.com.br/v2/guia-de-integracao/api-de-notificacoes.html#v2-item-servico-de-notificacoes
19
*/
20
public function proccessNotificatonResult(SimpleXMLElement $resultXML)
21
{
22
+ // prevent this event from firing twice
23
+ if(Mage::registry('sales_order_invoice_save_after_event_triggered'))
24
+ {
25
+ return $this; // this method has already been executed once in this request
26
+ }
27
+ Mage::register('sales_order_invoice_save_after_event_triggered', true);
28
+
29
if (isset($resultXML->error)) {
30
$errMsg = Mage::helper('ricardomartins_pagseguro')->__((string)$resultXML->error->message);
31
Mage::throwException(
40
/** @var Mage_Sales_Model_Order $order */
41
$order = Mage::getModel('sales/order')->loadByIncrementId((string)$resultXML->reference);
42
$payment = $order->getPayment();
43
+
44
$this->_code = $payment->getMethod();
45
$processedState = $this->processStatus((int)$resultXML->status);
46
+
47
$message = $processedState->getMessage();
48
49
if ((int)$resultXML->status == 6) { //valor devolvido (gera credit memo e tenta cancelar o pedido)
50
if ($order->canUnhold()) {
51
$order->unhold();
52
}
53
+
54
if ($order->canCancel()) {
55
$order->cancel();
56
$order->save();
57
} else {
58
$payment->registerRefundNotification(floatval($resultXML->grossAmount));
59
$order->addStatusHistoryComment(
60
+ 'Devolvido: o valor foi devolvido ao comprador.'
61
)->save();
62
}
63
}
77
}
78
79
if ($processedState->getStateChanged()) {
80
+ // somente para o status 6 que edita o status do pedido - Weber
81
+ if ((int)$resultXML->status != 6) {
82
+ $order->setState(
83
+ $processedState->getState(),
84
+ true,
85
+ $message,
86
+ $processedState->getIsCustomerNotified()
87
+ )->save();
88
+ }
89
+
90
} else {
91
$order->addStatusHistoryComment($message);
92
}
93
94
if ((int)$resultXML->status == 3) { //Quando o pedido foi dado como Pago
95
+ // cria fatura e envia email (se configurado)
96
+ // $payment->registerCaptureNotification(floatval($resultXML->grossAmount));
97
if(!$order->hasInvoices()){
98
$invoice = $order->prepareInvoice();
99
$invoice->register()->pay();
100
$msg = sprintf('Pagamento capturado. Identificador da Transação: %s', (string)$resultXML->code);
101
$invoice->addComment($msg);
102
$invoice->sendEmail(
103
+ Mage::getStoreConfigFlag('payment/rm_pagseguro/send_invoice_email'),
104
'Pagamento recebido com sucesso.'
105
);
106
+
107
+ // salva o transaction id na invoice
108
+ if (isset($resultXML->code)) {
109
+ $invoice->setTransactionId((string)$resultXML->code)->save();
110
+ }
111
+
112
Mage::getModel('core/resource_transaction')
113
->addObject($invoice)
114
->addObject($invoice->getOrder())
152
153
$client->request();
154
$resposta = $client->getLastResponse()->getBody();
155
+
156
$helper->writeLog(sprintf('Retorno do Pagseguro para notificationCode %s: %s', $notificationCode, $resposta));
157
158
libxml_use_internal_errors(true);
175
$return = new Varien_Object();
176
$return->setStateChanged(true);
177
$return->setIsTransactionPending(true); //payment is pending?
178
+
179
switch($statusCode)
180
{
181
case '1':
225
);
226
break;
227
case '6':
228
+ //$return->setState(Mage_Sales_Model_Order::STATE_CLOSED);
229
+ $return->setData('state', Mage_Sales_Model_Order::STATE_CLOSED);
230
$return->setIsCustomerNotified(false);
231
$return->setIsTransactionPending(false);
232
$return->setMessage('Devolvida: o valor da transação foi devolvido para o comprador.');
248
* Call PagSeguro API to place an order (/transactions)
249
* @param $params
250
* @param $payment
251
+ * @param $type
252
*
253
* @return SimpleXMLElement
254
*/
255
+ public function callApi($params, $payment, $type='transactions')
256
{
257
$helper = Mage::helper('ricardomartins_pagseguro');
258
$useApp = $helper->getLicenseType() == 'app';
261
}
262
$params = $this->_convertEncoding($params);
263
$paramsString = $this->_convertToCURLString($params);
264
+
265
+ $helper->writeLog('Parametros sendo enviados para API (/'.$type.'): '. var_export($params, true));
266
+
267
$ch = curl_init();
268
+ curl_setopt($ch, CURLOPT_URL, $helper->getWsUrl($type, $useApp));
269
curl_setopt($ch, CURLOPT_POST, count($params));
270
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
271
curl_setopt($ch, CURLOPT_POSTFIELDS, $paramsString);
286
}
287
curl_close($ch);
288
289
+ $helper->writeLog('Retorno PagSeguro (/'.$type.'): ' . var_export($response, true));
290
291
libxml_use_internal_errors(true);
292
$xml = simplexml_load_string(trim($response));
293
+
294
if (false === $xml) {
295
switch($response){
296
case 'Unauthorized':
311
'Houve uma falha ao processar seu pedido/pagamento. Por favor entre em contato conosco.'
312
);
313
}
314
+
315
return $xml;
316
}
317
318
+ /**
319
+ * Check if order total is zero making method unavailable
320
+ * @param Mage_Sales_Model_Quote $quote
321
+ *
322
+ * @return mixed
323
+ */
324
+ public function isAvailable($quote = null)
325
+ {
326
+ return parent::isAvailable($quote) && !empty($quote)
327
+ && Mage::app()->getStore()->roundPrice($quote->getGrandTotal()) > 0;
328
+ }
329
+
330
+
331
+ /**
332
+ * Order payment
333
+ *
334
+ * @param Varien_Object $payment
335
+ * @param float $amount
336
+ *
337
+ * @return RicardoMartins_PagSeguro_Model_Payment_Abstract
338
+ */
339
+ public function refund(Varien_Object $payment, $amount)
340
+ {
341
+ //will grab data to be send via POST to API inside $params
342
+ $rmHelper = Mage::helper('ricardomartins_pagseguro');
343
+
344
+ // recupera a informação adicional do PagSeguro
345
+ $info = $this->getInfoInstance();
346
+ $transactionId = $info->getAdditionalInformation('transaction_id');
347
+
348
+ $params = array(
349
+ 'transactionCode' => $transactionId,
350
+ 'refundValue' => number_format($amount, 2, '.', ''),
351
+ );
352
+
353
+ if ($rmHelper->getLicenseType() != 'app') {
354
+ $params['token'] = $rmHelper->getToken();
355
+ $params['email'] = $rmHelper->getMerchantEmail();
356
+ }
357
+
358
+ // call API - refund
359
+ $returnXml = $this->callApi($params, $payment, 'transactions/refunds');
360
+
361
+ if ($returnXml === null) {
362
+ $errorMsg = $this->_getHelper()->__('Erro ao solicitar o reembolso.\n');
363
+ Mage::throwException($errorMsg);
364
+ }
365
+ return $this;
366
+ }
367
+
368
/**
369
* Convert array values to utf-8
370
* @param array $params
378
}
379
return $params;
380
}
381
+
382
/**
383
* Convert API params (already ISO-8859-1) to url format (curl string)
384
* @param array $params
391
foreach ($params as $k => $v) {
392
$fieldsString .= $k.'='.urlencode($v).'&';
393
}
394
return rtrim($fieldsString, '&');
395
}
396
}
397
+
398
+
399
+
app/code/community/RicardoMartins/PagSeguro/Model/Observer.php CHANGED
@@ -20,7 +20,7 @@ class RicardoMartins_PagSeguro_Model_Observer
20
$directpayment = Mage::app()->getLayout()
21
->createBlock('ricardomartins_pagseguro/form_directpayment')
22
->toHtml();
23
- $observer->getTransport()->setHtml($output . $directpayment);
24
}
25
return $this;
26
}
20
$directpayment = Mage::app()->getLayout()
21
->createBlock('ricardomartins_pagseguro/form_directpayment')
22
->toHtml();
23
+ $observer->getTransport()->setHtml($directpayment . $output);
24
}
25
return $this;
26
}
app/code/community/RicardoMartins/PagSeguro/Model/Payment/Cc.php CHANGED
@@ -11,13 +11,14 @@
11
*/
12
class RicardoMartins_PagSeguro_Model_Payment_Cc extends RicardoMartins_PagSeguro_Model_Abstract
13
{
14
- protected $_code = 'pagseguro_cc';
15
protected $_formBlockType = 'ricardomartins_pagseguro/form_cc';
16
protected $_infoBlockType = 'ricardomartins_pagseguro/form_info_cc';
17
protected $_isGateway = true;
18
protected $_canAuthorize = true;
19
protected $_canCapture = true;
20
- protected $_canRefund = false;
21
protected $_canVoid = true;
22
protected $_canUseInternal = false;
23
protected $_canUseCheckout = true;
@@ -63,10 +64,14 @@ class RicardoMartins_PagSeguro_Model_Payment_Cc extends RicardoMartins_PagSeguro
63
}
64
65
$info = $this->getInfoInstance();
66
- $info->setAdditionalInformation('sender_hash', $data->getSenderHash())
67
- ->setAdditionalInformation('credit_card_token', $data->getCreditCardToken())
68
->setAdditionalInformation('credit_card_owner', $data->getPsCcOwner())
69
- ->setCcType($data->getPsCardType())
70
->setCcLast4(substr($data->getPsCcNumber(), -4));
71
72
//cpf
@@ -111,26 +116,41 @@ class RicardoMartins_PagSeguro_Model_Payment_Cc extends RicardoMartins_PagSeguro
111
public function validate()
112
{
113
parent::validate();
114
- $info = $this->getInfoInstance();
115
116
- $senderHash = $info->getAdditionalInformation('sender_hash');
117
- $creditCardToken = $info->getAdditionalInformation('credit_card_token');
118
119
- if (empty($creditCardToken) || empty($senderHash)) {
120
Mage::helper('ricardomartins_pagseguro')
121
->writeLog(
122
- 'Falha ao obter o token do cartao ou sender_hash.
123
- Veja se os dados "sender_hash" e "credit_card_token" foram enviados no formulário.
124
- Um problema de JavaScript pode ter ocorrido.
125
- Se esta for apenas uma atualização de blocos via ajax nao se preocupe.'
126
);
127
Mage::throwException(
128
- 'Falha ao processar pagamento junto ao PagSeguro. Por favor, entre em contato com nossa equipe.'
129
);
130
}
131
return $this;
132
}
133
134
/**
135
* Order payment
136
*
@@ -175,6 +195,7 @@ class RicardoMartins_PagSeguro_Model_Payment_Cc extends RicardoMartins_PagSeguro
175
}
176
}
177
$payment->setAdditionalInformation($additional);
178
}
179
return $this;
180
}
11
*/
12
class RicardoMartins_PagSeguro_Model_Payment_Cc extends RicardoMartins_PagSeguro_Model_Abstract
13
{
14
+ protected $_code = 'rm_pagseguro_cc';
15
protected $_formBlockType = 'ricardomartins_pagseguro/form_cc';
16
protected $_infoBlockType = 'ricardomartins_pagseguro/form_info_cc';
17
protected $_isGateway = true;
18
protected $_canAuthorize = true;
19
protected $_canCapture = true;
20
+ protected $_canRefund = true;
21
+ protected $_canRefundInvoicePartial = false;
22
protected $_canVoid = true;
23
protected $_canUseInternal = false;
24
protected $_canUseCheckout = true;
64
}
65
66
$info = $this->getInfoInstance();
67
+
68
+ /** @var RicardoMartins_PagSeguro_Helper_Params $pHelper */
69
+ $pHelper = Mage::helper('ricardomartins_pagseguro/params');
70
+
71
+ $info->setAdditionalInformation('sender_hash', $pHelper->getPaymentHash('sender_hash'))
72
+ ->setAdditionalInformation('credit_card_token', $pHelper->getPaymentHash('credit_card_token'))
73
->setAdditionalInformation('credit_card_owner', $data->getPsCcOwner())
74
+ ->setCcType($pHelper->getPaymentHash('cc_type'))
75
->setCcLast4(substr($data->getPsCcNumber(), -4));
76
77
//cpf
116
public function validate()
117
{
118
parent::validate();
119
+ $missingInfo = $this->getInfoInstance();
120
+
121
+ /** @var RicardoMartins_PagSeguro_Helper_Params $pHelper */
122
+ $pHelper = Mage::helper('ricardomartins_pagseguro/params');
123
+
124
+ $shippingMethod = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getShippingMethod();
125
126
+ // verifica se não há método de envio selecionado antes de exibir o erro de falha no cartão de crédito - Weber
127
+ if (empty($shippingMethod)) {
128
+ return false;
129
+ }
130
+
131
+ $senderHash = $pHelper->getPaymentHash('sender_hash');
132
+ $creditCardToken = $pHelper->getPaymentHash('credit_card_token');
133
134
+ if (!$creditCardToken || !$senderHash) {
135
+ $missingInfo = sprintf('Token do cartão: %s', var_export($creditCardToken, true));
136
+ $missingInfo .= sprintf('/ Sender_hash: %s', var_export($senderHash, true));
137
Mage::helper('ricardomartins_pagseguro')
138
->writeLog(
139
+ "Falha ao obter o token do cartao ou sender_hash.
140
+ Ative o modo debug e observe o console de erros do seu navegador.
141
+ $missingInfo"
142
);
143
Mage::throwException(
144
+ 'Falha ao processar seu pagamento. Por favor, entre em contato com nossa equipe.'
145
);
146
}
147
return $this;
148
}
149
150
+
151
+ // public function processBeforeRefund($invoice, $payment){} //before refund
152
+ // public function processCreditmemo($creditmemo, $payment){} //after refund
153
+
154
/**
155
* Order payment
156
*
195
}
196
}
197
$payment->setAdditionalInformation($additional);
198
+
199
}
200
return $this;
201
}
app/code/community/RicardoMartins/PagSeguro/Model/Source/Ccbrand.php ADDED
@@ -0,0 +1,26 @@
1
+ <?php
2
+ /**
3
+ * PagSeguro Transparente Magento
4
+ *
5
+ * @category RicardoMartins
6
+ * @package RicardoMartins_PagSeguro
7
+ * @author Ricardo Martins
8
+ * @copyright Copyright (c) 2015 Ricardo Martins (http://r-martins.github.io/PagSeguro-Magento-Transparente/)
9
+ * @license https://opensource.org/licenses/MIT MIT License
10
+ */
11
+ class RicardoMartins_PagSeguro_Model_Source_Ccbrand
12
+ {
13
+ /**
14
+ * @return array
15
+ */
16
+ public function toOptionArray()
17
+ {
18
+ $options = array();
19
+ $options[] = array('value'=>'42x20','label'=>'42x20 px');
20
+ $options[] = array('value'=>'68x30','label'=>'68x30 px');
21
+ $options[] = array('value'=>'','label'=>'Exibir apenas texto');
22
+
23
+
24
+ return $options;
25
+ }
26
+ }
app/code/community/RicardoMartins/PagSeguro/controllers/AjaxController.php CHANGED
@@ -35,4 +35,19 @@ class RicardoMartins_PagSeguro_AjaxController extends Mage_Core_Controller_Front
35
$this->getResponse()->setHeader('Content-type', 'application/json', true);
36
$this->getResponse()->setBody(json_encode(array('session_id' => $sessionId)));
37
}
38
}
35
$this->getResponse()->setHeader('Content-type', 'application/json', true);
36
$this->getResponse()->setBody(json_encode(array('session_id' => $sessionId)));
37
}
38
+
39
+ public function updatePaymentHashesAction()
40
+ {
41
+ $paymentPost = $this->getRequest()->getPost('payment');
42
+ $isAdmin = isset($paymentPost['is_admin']) && $paymentPost['is_admin']=="true";
43
+ $session = 'checkout/session';
44
+ if ($isAdmin) {
45
+ $session = 'core/cookie';
46
+ Mage::getSingleton($session)->set('PsPayment', serialize($paymentPost));
47
+ } else {
48
+ Mage::getSingleton($session)->setData('PsPayment', serialize($paymentPost));
49
+ }
50
+
51
+ $this->getResponse()->setHttpResponseCode(200);
52
+ }
53
}
app/code/community/RicardoMartins/PagSeguro/controllers/TestController.php CHANGED
@@ -7,7 +7,7 @@
7
* @category RicardoMartins
8
* @package RicardoMartins_PagSeguro
9
* @author Ricardo Martins
10
- * @copyright Copyright (c) 2015 Ricardo Martins (http://r-martins.github.io/PagSeguro-Magento-Transparente/)
11
* @license https://opensource.org/licenses/MIT MIT License
12
*/
13
class RicardoMartins_PagSeguro_TestController extends Mage_Core_Controller_Front_Action
@@ -19,19 +19,28 @@ class RicardoMartins_PagSeguro_TestController extends Mage_Core_Controller_Front
19
public function getConfigAction()
20
{
21
$info = array();
22
$info['RicardoMartins_PagSeguro']['version'] = (string)Mage::getConfig()
23
->getModuleConfig('RicardoMartins_PagSeguro')->version;
24
- $info['RicardoMartins_PagSeguro']['debug'] = Mage::getStoreConfigFlag('payment/pagseguro/debug');
25
- $info['RicardoMartins_PagSeguro']['sandbox'] = Mage::getStoreConfigFlag('payment/pagseguro/sandbox');
26
27
if (Mage::getConfig()->getModuleConfig('RicardoMartins_PagSeguroPro')) {
28
$info['RicardoMartins_PagSeguroPro']['version'] = (string)Mage::getConfig()
29
->getModuleConfig('RicardoMartins_PagSeguroPro')->version;
30
- $info['RicardoMartins_PagSeguroPro']['key_type'] =
31
- (string)Mage::getStoreConfig('payment/pagseguropro/key_type');
32
}
33
34
- $helper = Mage::helper('ricardomartins_pagseguro');
35
$info['session_id'] = $helper->getSessionId();
36
37
$modules = array_keys((array)Mage::getConfig()->getNode('modules')->children());
@@ -41,8 +50,59 @@ class RicardoMartins_PagSeguro_TestController extends Mage_Core_Controller_Front
41
$info['pagseguro_modules'][] = $module;
42
}
43
}
44
-
45
$this->getResponse()->setHeader('Content-type', 'application/json');
46
- $this->getResponse()->setBody(json_encode($info));
47
}
48
}
7
* @category RicardoMartins
8
* @package RicardoMartins_PagSeguro
9
* @author Ricardo Martins
10
+ * @copyright Copyright (c) 2017 Ricardo Martins (http://r-martins.github.io/PagSeguro-Magento-Transparente/)
11
* @license https://opensource.org/licenses/MIT MIT License
12
*/
13
class RicardoMartins_PagSeguro_TestController extends Mage_Core_Controller_Front_Action
19
public function getConfigAction()
20
{
21
$info = array();
22
+ $helper = Mage::helper('ricardomartins_pagseguro');
23
+ $pretty = ($this->getRequest()->getParam('pretty', true) && version_compare(PHP_VERSION, '5.4', '>='))?128:0;
24
+
25
$info['RicardoMartins_PagSeguro']['version'] = (string)Mage::getConfig()
26
->getModuleConfig('RicardoMartins_PagSeguro')->version;
27
+ $info['RicardoMartins_PagSeguro']['debug'] = Mage::getStoreConfigFlag('payment/rm_pagseguro/debug');
28
+ $info['RicardoMartins_PagSeguro']['sandbox'] = Mage::getStoreConfigFlag('payment/rm_pagseguro/sandbox');
29
+ $info['configJs'] = json_decode($helper->getConfigJs());
30
31
if (Mage::getConfig()->getModuleConfig('RicardoMartins_PagSeguroPro')) {
32
$info['RicardoMartins_PagSeguroPro']['version'] = (string)Mage::getConfig()
33
->getModuleConfig('RicardoMartins_PagSeguroPro')->version;
34
+
35
+ $keyType = $helper->getLicenseType();
36
+ $info['RicardoMartins_PagSeguroPro']['key_type'] = ($keyType)==''?'assinatura':$keyType;
37
+ $info['RicardoMartins_PagSeguroPro']['key_validation'] = $this->_validateKey($keyType);
38
+
39
}
40
41
+ $info['compilation'] = $this->_getCompilerState();
42
+
43
+ $info['token_consistency'] = $this->_getTokenConsistency();
44
$info['session_id'] = $helper->getSessionId();
45
46
$modules = array_keys((array)Mage::getConfig()->getNode('modules')->children());
50
$info['pagseguro_modules'][] = $module;
51
}
52
}
53
$this->getResponse()->setHeader('Content-type', 'application/json');
54
+ $this->getResponse()->setBody(json_encode($info, $pretty));
55
+
56
+ }
57
+
58
+ /**
59
+ * Validates your PRO key. Only for tests purposes.
60
+ * @return mixed|string
61
+ */
62
+ private function _validateKey()
63
+ {
64
+ $key = Mage::getStoreConfig('payment/pagseguropro/key');
65
+ if (empty($key)) {
66
+ return 'KEY IS EMPTY';
67
+ }
68
+ $url = 'http://ws.ricardomartins.net.br/pspro/v6/auth/' . $key;
69
+
70
+ $ch = curl_init();
71
+ curl_setopt($ch, CURLOPT_URL, $url);
72
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
73
+ curl_setopt($ch, CURLOPT_TIMEOUT, 45);
74
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
75
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
76
+ libxml_use_internal_errors(true);
77
+
78
+ return curl_exec($ch);
79
+ }
80
+
81
+ /**
82
+ * Get compilation config details
83
+ * @return array
84
+ */
85
+ private function _getCompilerState()
86
+ {
87
+ $compiler = Mage::getModel('compiler/process');
88
+ $compilerConfig = MAGENTO_ROOT . '/includes/config.php';
89
+
90
+ if (file_exists($compilerConfig) && !(defined('COMPILER_INCLUDE_PATH') || defined('COMPILER_COLLECT_PATH'))) {
91
+ include $compilerConfig;
92
+ }
93
+ $status = defined('COMPILER_INCLUDE_PATH') ? 'Enabled' : 'Disabled';
94
+ $state = $compiler->getCollectedFilesCount() > 0 ? 'Compiled' : 'Not Compiled';
95
+ return array(
96
+ 'status' => $status,
97
+ 'state' => $state,
98
+ 'files_count' => $compiler->getCollectedFilesCount(),
99
+ 'scopes_count' => $compiler->getCompiledFilesCount()
100
+ );
101
+ }
102
+
103
+ private function _getTokenConsistency()
104
+ {
105
+ $token = Mage::helper('ricardomartins_pagseguro')->getToken();
106
+ return (strlen($token)!=32)?'Wrong size':'Good';
107
}
108
}
app/code/community/RicardoMartins/PagSeguro/data/ricardomartins_pagseguro_setup/data-install-3.0.0.php ADDED
@@ -0,0 +1,18 @@
1
+ <?php
2
+ /**
3
+ * Migra configurações antigas(se houver) pro padrão novo, evitando conflitos com outros módulos PagSeguro
4
+ */
5
+
6
+ /* @var $installer Mage_Core_Model_Resource_Setup */
7
+ $installer = $this;
8
+
9
+ $token = Mage::getStoreConfig('payment/pagseguro/token');
10
+ $decryptedToken = Mage::helper('core')->decrypt($token);
11
+
12
+ if ($token != false && strlen($decryptedToken) == 32 ) {
13
+ $sql = "UPDATE {$this->getTable('core/config_data')}
14
+ SET path = REPLACE(path, 'payment/pagseguro/', 'payment/rm_pagseguro/')
15
+ WHERE path LIKE 'payment/pagseguro/%'";
16
+
17
+ $installer->getConnection()->query($sql);
18
+ }
app/code/community/RicardoMartins/PagSeguro/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
<config>
3
<modules>
4
<RicardoMartins_PagSeguro>
5
- <version>2.5.6</version>
6
</RicardoMartins_PagSeguro>
7
</modules>
8
<global>
@@ -21,6 +21,14 @@
21
<class>RicardoMartins_PagSeguro_Helper</class>
22
</ricardomartins_pagseguro>
23
</helpers>
24
</global>
25
<frontend>
26
<routers>
@@ -63,18 +71,21 @@
63
</adminhtml>
64
<default>
65
<payment>
66
- <pagseguro_cc>
67
<active>0</active>
68
<title>Cartão de Crédito - via PagSeguro UOL</title>
69
<order_status>pending</order_status>
70
<payment_action>order</payment_action>
71
<model>ricardomartins_pagseguro/payment_cc</model>
72
<allowspecific>0</allowspecific>
73
<send_neworder_email>0</send_neworder_email>
74
<!--<specificcountry>BR</specificcountry>-->
75
<group_restriction>0</group_restriction>
76
- </pagseguro_cc>
77
- <pagseguro>
78
<customer_cpf_attribute>taxvat</customer_cpf_attribute>
79
<address_street_attribute>street_1</address_street_attribute>
80
<address_number_attribute>street_2</address_number_attribute>
@@ -87,13 +98,13 @@
87
<sandbox_ws_url_app>https://ws.ricardomartins.net.br/pspro/v6/wspagseguro/sandbox/v2/</sandbox_ws_url_app>
88
<!--<sandbox_ws_url_app>http://ws.local.com.br/pspro/v6/wspagseguro/sandbox/v2/</sandbox_ws_url_app>-->
89
<sandbox_js_url>https://stc.sandbox.pagseguro.uol.com.br/pagseguro/api/v2/checkout/pagseguro.directpayment.js</sandbox_js_url>
90
- </pagseguro>
91
</payment>
92
</default>
93
<phpunit>
94
<suite>
95
<modules>
96
- <RicardoMartins_PagSeguro />
97
</modules>
98
</suite>
99
</phpunit>
2
<config>
3
<modules>
4
<RicardoMartins_PagSeguro>
5
+ <version>3.0.0</version>
6
</RicardoMartins_PagSeguro>
7
</modules>
8
<global>
21
<class>RicardoMartins_PagSeguro_Helper</class>
22
</ricardomartins_pagseguro>
23
</helpers>
24
+ <resources>
25
+ <ricardomartins_pagseguro_setup>
26
+ <setup>
27
+ <module>RicardoMartins_PagSeguro</module>
28
+ <class>Mage_Core_Model_Resource_Setup</class>
29
+ </setup>
30
+ </ricardomartins_pagseguro_setup>
31
+ </resources>
32
</global>
33
<frontend>
34
<routers>
71
</adminhtml>
72
<default>
73
<payment>
74
+ <rm_pagseguro_cc>
75
<active>0</active>
76
<title>Cartão de Crédito - via PagSeguro UOL</title>
77
<order_status>pending</order_status>
78
+ <flag>42x20</flag>
79
<payment_action>order</payment_action>
80
<model>ricardomartins_pagseguro/payment_cc</model>
81
<allowspecific>0</allowspecific>
82
<send_neworder_email>0</send_neworder_email>
83
<!--<specificcountry>BR</specificcountry>-->
84
<group_restriction>0</group_restriction>
85
+ <info_brl>1</info_brl>
86
+ <total_installments>0</total_installments>
87
+ </rm_pagseguro_cc>
88
+ <rm_pagseguro>
89
<customer_cpf_attribute>taxvat</customer_cpf_attribute>
90
<address_street_attribute>street_1</address_street_attribute>
91
<address_number_attribute>street_2</address_number_attribute>
98
<sandbox_ws_url_app>https://ws.ricardomartins.net.br/pspro/v6/wspagseguro/sandbox/v2/</sandbox_ws_url_app>
99
<!--<sandbox_ws_url_app>http://ws.local.com.br/pspro/v6/wspagseguro/sandbox/v2/</sandbox_ws_url_app>-->
100
<sandbox_js_url>https://stc.sandbox.pagseguro.uol.com.br/pagseguro/api/v2/checkout/pagseguro.directpayment.js</sandbox_js_url>
101
+ </rm_pagseguro>
102
</payment>
103
</default>
104
<phpunit>
105
<suite>
106
<modules>
107
+ <RicardoMartins_PagSeguro/>
108
</modules>
109
</suite>
110
</phpunit>
app/code/community/RicardoMartins/PagSeguro/etc/system.xml CHANGED
@@ -29,8 +29,8 @@
29
<sections>
30
<payment>
31
<groups>
32
- <pagseguro module="ricardomartins_pagseguro">
33
- <comment><![CDATA[Precisa de ajuda? - <a href="http://r-martins.github.io/PagSeguro-Magento-Transparente" target="_blank">Site oficial do módulo</a> | <a href="https://pagsegurotransparente.zendesk.com/hc/pt-br" target="_blank">Central de Ajuda</a></href><br/> Lembre-se de <a href="//r-martins.github.io/PagSeguro-Magento-Transparente/pro/app.html#contratar" target="_blank"><strong>autorizar sua conta</strong></a> com a aplicação do módulo para liberar o checkout transparente junto ao PagSeguro. Ao fazer isso você também receberá o módulo PRO gratuitamente no e-mail informado, com suporte a boleto e TEF.<br/>Se preferir não utilizar a aplicação, <a href="//pagseguro.uol.com.br/receba-pagamentos.jhtml#checkout-transparent" target="_blank">solicite ao PagSeguro</a> a liberação da sua conta manualmente. E se desejar receber o módulo PRO com suporte a boleto e tef sem autorizar a aplicação, <a href="//r-martins.github.io/PagSeguro-Magento-Transparente/pro/" target="_blank">faça uma assinatura</a>.]]></comment>
34
<label>PagSeguro - Ricardo Martins</label>
35
<frontend_type>text</frontend_type>
36
<sort_order>110</sort_order>
@@ -47,6 +47,7 @@
47
<show_in_website>1</show_in_website>
48
<show_in_store>0</show_in_store>
49
<comment>E-mail da loja (conta vendedor)</comment>
50
</merchant_email>
51
<token translate="label">
52
<label>Token</label>
@@ -57,6 +58,7 @@
57
<show_in_website>1</show_in_website>
58
<show_in_store>0</show_in_store>
59
<comment>O token é obtido no seu painel do PagSeguro. Ao salvar esta página, ele será criptografado, aparentando ter um tamanho menor.</comment>
60
</token>
61
<sandbox translate="label">
62
<label>Ambiente de testes?</label>
@@ -202,8 +204,8 @@
202
<comment><![CDATA[Caso sua loja utilize um atributo personalizado para o campo 'Bairro' de entrega, selecione aqui.]]></comment>
203
</address_neighborhood_attribute>
204
</fields>
205
- </pagseguro>
206
- <pagseguro_cc module="ricardomartins_pagseguro">
207
<label>PagSeguro - Cartão de Crédito - Ricardo Martins</label>
208
<frontend_type>text</frontend_type>
209
<sort_order>111</sort_order>
@@ -240,6 +242,26 @@
240
<show_in_website>1</show_in_website>
241
<show_in_store>0</show_in_store>
242
</order_status>
243
<owner_dob_attribute>
244
<label>Data de Nascimento</label>
245
<frontend_type>select</frontend_type>
@@ -281,8 +303,18 @@
281
<group_restriction>1</group_restriction>
282
</depends>
283
</customer_groups>
284
</fields>
285
- </pagseguro_cc>
286
</groups>
287
</payment>
288
</sections>
29
<sections>
30
<payment>
31
<groups>
32
+ <rm_pagseguro module="ricardomartins_pagseguro">
33
+ <comment><![CDATA[Precisa de ajuda? - <a href="//r-martins.github.io/PagSeguro-Magento-Transparente" target="_blank">Site oficial do módulo</a> | <a href="//pagsegurotransparente.zendesk.com/hc/pt-br" target="_blank">Central de Ajuda</a>.<br/> Quer pagar menos taxas? <a href="//r-martins.github.io/PagSeguro-Magento-Transparente/pro/app.html" target="_blank"><strong>Autorize sua conta</strong></a> no modelo de aplicação e receba o módulo PRO gratuitamente no e-mail informado, com suporte a boleto e TEF.<br/>Se você tem taxas menores ainda, e desejar receber o módulo PRO com suporte a boleto e tef sem autorizar a aplicação, <a href="//r-martins.github.io/PagSeguro-Magento-Transparente/pro/" target="_blank">faça uma assinatura</a>.]]></comment>
34
<label>PagSeguro - Ricardo Martins</label>
35
<frontend_type>text</frontend_type>
36
<sort_order>110</sort_order>
47
<show_in_website>1</show_in_website>
48
<show_in_store>0</show_in_store>
49
<comment>E-mail da loja (conta vendedor)</comment>
50
+ <tooltip>E-mail da sua conta PagSeguro. Você deve ter uma Conta Vendedor ou Conta Empresarial.</tooltip>
51
</merchant_email>
52
<token translate="label">
53
<label>Token</label>
58
<show_in_website>1</show_in_website>
59
<show_in_store>0</show_in_store>
60
<comment>O token é obtido no seu painel do PagSeguro. Ao salvar esta página, ele será criptografado, aparentando ter um tamanho menor.</comment>
61
+ <tooltip>No caso de suspeita de token inválido ou de ter instalado outro módulo PagSeguro anteriormente, redigite o token e salve as configurações.</tooltip>
62
</token>
63
<sandbox translate="label">
64
<label>Ambiente de testes?</label>
204
<comment><![CDATA[Caso sua loja utilize um atributo personalizado para o campo 'Bairro' de entrega, selecione aqui.]]></comment>
205
</address_neighborhood_attribute>
206
</fields>
207
+ </rm_pagseguro>
208
+ <rm_pagseguro_cc module="ricardomartins_pagseguro">
209
<label>PagSeguro - Cartão de Crédito - Ricardo Martins</label>
210
<frontend_type>text</frontend_type>
211
<sort_order>111</sort_order>
242
<show_in_website>1</show_in_website>
243
<show_in_store>0</show_in_store>
244
</order_status>
245
+ <flag>
246
+ <label>Tamanho da bandeira do cartão</label>
247
+ <frontend_type>select</frontend_type>
248
+ <source_model>ricardomartins_pagseguro/source_ccbrand</source_model>
249
+ <sort_order>25</sort_order>
250
+ <show_in_default>1</show_in_default>
251
+ <show_in_website>1</show_in_website>
252
+ <show_in_store>1</show_in_store>
253
+ <tooltip><![CDATA[Exemplos: <br/><img src="//stc.pagseguro.uol.com.br/public/img/payment-methods-flags/42x20/visa.png" title="42x20"/><img src="//stc.pagseguro.uol.com.br/public/img/payment-methods-flags/68x30/visa.png" title="68x30"/>]]></tooltip>
254
+ </flag>
255
+ <info_brl>
256
+ <label>Exibir aviso que a transação é feita no Brasil.</label>
257
+ <frontend_type>select</frontend_type>
258
+ <source_model>adminhtml/system_config_source_yesno</source_model>
259
+ <sort_order>26</sort_order>
260
+ <show_in_default>1</show_in_default>
261
+ <show_in_website>1</show_in_website>
262
+ <show_in_store>1</show_in_store>
263
+ <comment><![CDATA[Esta informação DEVE conter em seu checkout por determinação da Visa.]]></comment>
264
+ </info_brl>
265
<owner_dob_attribute>
266
<label>Data de Nascimento</label>
267
<frontend_type>select</frontend_type>
303
<group_restriction>1</group_restriction>
304
</depends>
305
</customer_groups>
306
+ <show_total>
307
+ <label>Exibit valor total no seletor de parcelas</label>
308
+ <frontend_type>select</frontend_type>
309
+ <sort_order>70</sort_order>
310
+ <source_model>adminhtml/system_config_source_yesno</source_model>
311
+ <show_in_default>1</show_in_default>
312
+ <show_in_website>1</show_in_website>
313
+ <show_in_store>1</show_in_store>
314
+ <comment><![CDATA[Quando habilitado, o valor total do pedido é exibido junto com as informações de parcelamento.]]></comment>
315
+ </show_total>
316
</fields>
317
+ </rm_pagseguro_cc>
318
</groups>
319
</payment>
320
</sections>
app/design/adminhtml/base/default/template/ricardomartins_pagseguro/form/cc.phtml ADDED
@@ -0,0 +1,105 @@
1
+ <?php
2
+ /** @var RicardoMartins_PagSeguro_Block_Form_Cc $this */
3
+ $_code=$this->getMethodCode();
4
+ $_singleton = (Mage::app()->getStore()->isAdmin())?'adminhtml/session_quote':'checkout/session';
5
+ $_grandTotal = Mage::getSingleton($_singleton)->getQuote()->getGrandTotal();
6
+ $_grandTotal = (!$_grandTotal)?'null':$_grandTotal;
7
+ $_installments = Mage::getSingleton('checkout/session')->getQuote()->getPayment()->getAdditionalInformation('installment_quantity');
8
+ $_installments = (!$_installments)?'null':$_installments;
9
+
10
+ ?>
11
+ <ul class="form-list" id="payment_form_<?php echo $_code ?>" style="display:none;">
12
+ <?php /*
13
+ <li>
14
+ <div class="input-box">
15
+ <label for="<?php echo $_code ?>_cc_owner" class="required"><em>*</em><?php echo $this->__('Name on Card') ?></label>
16
+ <input type="text" title="<?php echo $this->__('Name on Card') ?>" class="input-text required-entry" id="<?php echo $_code ?>_cc_owner" name="payment[cc_owner]" value="<?php echo $this->escapeHtml($this->getInfoData('cc_owner')) ?>" />
17
+ </div>
18
+ </li>
19
+ */ ?>
20
+ <li>
21
+ <label for="<?php echo $_code ?>_cc_owner" class="required"><em>*</em><?php echo $this->__('Credit Card Owner\'s Name') ?></label>
22
+ <div class="input-box">
23
+ <input type="text" id="<?php echo $_code ?>_cc_owner" name="payment[ps_cc_owner]" title="<?php echo $this->__('Credit Card Owner\'s Name') ?>" class="input-text required-entry" value=""/>
24
+ </div>
25
+ </li>
26
+ <?php if($this->isDobVisible()):?>
27
+ <li id="<?php echo $_code ?>_cc_dob_div">
28
+ <?php $_dob = $this->getLayout()->createBlock('ricardomartins_pagseguro/form_cc_dob') ?>
29
+ <?php echo $_dob->toHtml() ?>
30
+ </li>
31
+ <?php endif ?>
32
+ <?php if(Mage::helper('ricardomartins_pagseguro')->isCpfVisible()):?>
33
+ <li id="<?php echo $_code ?>_cpf_div">
34
+ <label for="<?php echo $_code ?>_cpf" class="required"><em>*</em><?php echo $this->__('Credit Card Owner\'s CPF') ?></label>
35
+ <div class="input-box">
36
+ <input type="text" id="<?php echo $_code ?>_cpf" name="payment[<?php echo $_code?>_cpf]" title="<?php echo $this->__('Credit Card Owner\'s CPF') ?>" class="input-text required-entry validate-digits" value="" maxlength="11"/>
37
+ </div>
38
+ </li>
39
+ <?php endif ?>
40
+ <li>
41
+ <label for="<?php echo $_code ?>_cc_number" class="required"><em>*</em><?php echo $this->__('Credit Card Number') ?></label>
42
+ <div class="input-box">
43
+ <input type="text" id="<?php echo $_code ?>_cc_number" name="payment[ps_cc_number]" title="<?php echo $this->__('Credit Card Number') ?>" class="input-text validate-cc-number validate-cc-type required-entry" value="" maxlength="16"/>
44
+ <?php #nao remover os campos abaixo ?>
45
+ <span id="card-brand" style="text-transform: capitalize; display: block;"></span>
46
+ <span id="card-msg" style="color: red;clear:left; display: block;"></span>
47
+ </div>
48
+ </li>
49
+ <li id="<?php echo $_code ?>_cc_type_exp_div">
50
+ <label for="<?php echo $_code ?>_expiration" class="required"><em>*</em><?php echo $this->__('Expiration Date') ?></label>
51
+ <div class="input-box">
52
+ <div class="v-fix">
53
+ <select id="<?php echo $_code ?>_expiration" name="payment[ps_cc_exp_month]" class="month validate-cc-exp required-entry">
54
+ <?php $_ccExpMonth = $this->getInfoData('ps_cc_exp_month') ?>
55
+ <?php foreach ($this->getCcMonths() as $k=>$v): ?>
56
+ <option value="<?php echo $k?$k:'' ?>"<?php if($k==$_ccExpMonth): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
57
+ <?php endforeach ?>
58
+ </select>
59
+ </div>
60
+ <div class="v-fix">
61
+ <?php $_ccExpYear = $this->getInfoData('ps_cc_exp_year') ?>
62
+ <select id="<?php echo $_code ?>_expiration_yr" name="payment[ps_cc_exp_year]" class="year required-entry">
63
+ <?php foreach ($this->getCcYears() as $k=>$v): ?>
64
+ <option value="<?php echo $k?$k:'' ?>"<?php if($k==$_ccExpYear): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
65
+ <?php endforeach ?>
66
+ </select>
67
+ </div>
68
+ </div>
69
+ </li>
70
+ <li id="<?php echo $_code ?>_cc_type_cvv_div">
71
+ <label for="<?php echo $_code ?>_cc_cid" class="required"><em>*</em><?php echo $this->__('Card Verification Number') ?></label>
72
+ <div class="input-box">
73
+ <div class="v-fix">
74
+ <input type="text" title="<?php echo $this->__('Card Verification Number') ?>" class="input-text cvv required-entry validate-cc-cvn" id="<?php echo $_code ?>_cc_cid" name="payment[ps_cc_cid]" value="" maxlength="4"/>
75
+ </div>
76
+ <a href="#" class="cvv-what-is-this"><?php echo $this->__('What is this?') ?></a>
77
+ </div>
78
+ </li>
79
+ <li id="<?php echo $_code ?>_cc_installments_div">
80
+ <label for="<?php echo $_code ?>_cc_installments"><?php echo $this->__('Installments') ?></label>
81
+ <div class="input-box">
82
+ <div class="v-fix">
83
+ <select name="payment[ps_cc_installments]" id="<?php echo $_code ?>_cc_installments" class="required">
84
+ <option value="">Informe os dados do cartão para calcular</option>
85
+ </select>
86
+ </div>
87
+ </div>
88
+ </li>
89
+ <?php echo $this->getChildHtml() ?>
90
+ </ul>
91
+ <script type="text/javascript">
92
+ //<![CDATA[
93
+ if(typeof RMPagSeguroObj != "undefined"){
94
+ if(RMPagSeguroObj.config.debug){
95
+ console.info('Adicionando observer para campos de cartão...');
96
+ }
97
+ if(typeof RMPagSeguroObj.brand != "undefined"){
98
+ RMPagSeguroObj.updateBrand();
99
+ RMPagSeguroObj.getInstallments(<?php echo $_grandTotal . ',' . $_installments;?>);
100
+ }
101
+ }else{
102
+ console.error('RMPagSeguroObj não foi definido.');
103
+ }
104
+ //]]
105
+ </script>
app/design/adminhtml/base/default/template/ricardomartins_pagseguro/form/cc/dob.phtml ADDED
@@ -0,0 +1,87 @@
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package base_default
23
+ * @copyright Copyright (c) 2013 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+
27
+ /**
28
+ USAGE:
29
+
30
+ Simple:
31
+
32
+ <?php echo $this->getLayout()->createBlock('customer/widget_dob')
33
+ ->setDate($this->getCustomer()->getDob())
34
+ ->toHtml() ?>
35
+
36
+ For checkout/onepage/billing.phtml:
37
+
38
+ <?php echo $this->getLayout()->createBlock('customer/widget_dob')
39
+ ->setDate($this->getCustomer()->getDob())
40
+ ->setFieldIdFormat('billing:%s')
41
+ ->setFieldNameFormat('billing[%s]')
42
+ ->toHtml() ?>
43
+
44
+ NOTE: Regarding styles - if we leave it this way, we'll move it to boxes.css
45
+ Alternatively we could calculate widths automatically using block input parameters.
46
+ */
47
+
48
+ /**
49
+ * @see Mage_Customer_Block_Widget_Dob
50
+ */
51
+ ?>
52
+ <label for="<?php echo $this->getFieldId('month')?>" class="required"><em>*</em><?php echo $this->__('Date of Birth') ?></label>
53
+ <div class="input-box customer-dob ps-cc-owner-dob">
54
+ <?php
55
+ $this->setDateInput('d',
56
+ '<div class="dob-day">
57
+ <input type="text" id="' . $this->getFieldId('day') . '" name="' . $this->getFieldName('day') . '" value="' . $this->getDay() . '" title="' . $this->__('Day') . '" class="input-text validate-custom" ' . $this->getFieldParams() . ' maxlength="2" />
58
+ <label for="' . $this->getFieldId('day') . '">' . $this->__('DD') . '</label>
59
+ </div>'
60
+ );
61
+
62
+ $this->setDateInput('m',
63
+ '<div class="dob-month">
64
+ <input type="text" id="' . $this->getFieldId('month') . '" name="' . $this->getFieldName('month') . '" value="' . $this->getMonth() . '" title="' . $this->__('Month') . '" class="input-text validate-custom" ' . $this->getFieldParams() . ' maxlength="2"/>
65
+ <label for="' . $this->getFieldId('month') . '">' . $this->__('MM') . '</label>
66
+ </div>'
67
+ );
68
+
69
+ $this->setDateInput('y',
70
+ '<div class="dob-year">
71
+ <input type="text" id="' . $this->getFieldId('year') . '" name="' . $this->getFieldName('year') . '" value="' . $this->getYear() . '" title="' . $this->__('Year') . '" class="input-text validate-custom" ' . $this->getFieldParams() . ' maxlength="4"/>
72
+ <label for="' . $this->getFieldId('year') . '">' . $this->__('YYYY') . '</label>
73
+ </div>'
74
+ );
75
+ ?>
76
+ <?php echo $this->getSortedDateInputs() ?>
77
+ <div class="dob-full" style="display:none;">
78
+ <input type="hidden" id="<?php echo $this->getFieldId('dob')?>" name="<?php echo $this->getFieldName('dob')?>" />
79
+ </div>
80
+
81
+ <div class="validation-advice" style="display:none;"></div>
82
+ </div>
83
+ <script type="text/javascript">
84
+ //<![CDATA[
85
+ var ps_cc_owner_dob = new Varien.DOB('.ps-cc-owner-dob', 'true', '<?php echo $this->getDateFormat() ?>');
86
+ //]]>
87
+ </script>
app/design/adminhtml/base/default/template/ricardomartins_pagseguro/form/directpayment.phtml CHANGED
@@ -1,19 +1,22 @@
1
<?php
2
$_helper = Mage::helper('ricardomartins_pagseguro');
3
?>
4
- <input type="hidden" name="payment[sender_hash]" id="admin_sender_hash"/>
5
<script type="text/javascript">
6
//<![CDATA[
7
- PagSeguroDirectPayment.setSessionId('<?php echo $_helper->getSessionId();?>');
8
- var iid = setInterval(function()
9
- {
10
- if(typeof PagSeguroDirectPayment != "undefined" && PagSeguroDirectPayment.ready){
11
- console.log('PagSeguro ready');
12
-
13
- clearInterval(iid);
14
- RMPagSeguro.updateSenderHash();
15
}
16
- }, 4000);
17
- document.getElementById('edit_form').appendChild(document.getElementById('admin_sender_hash'));
18
//]]>
19
</script>
1
<?php
2
$_helper = Mage::helper('ricardomartins_pagseguro');
3
?>
4
<script type="text/javascript">
5
//<![CDATA[
6
+ var preparePagSeguro = function(){
7
+ if(typeof RMPagSeguroObj != "undefined"){
8
+ <?php if ($_helper->isDebugActive()): ?>
9
+ console.info('PagSeguro was already started.');
10
+ <?php endif; ?>
11
+ return;
12
}
13
+ <?php if ($_helper->isDebugActive()): ?>
14
+ console.info('PagSeguro is initiating. Wait for ready message.');
15
+ <?php endif; ?>
16
+ RMPagSeguroObj = new RMPagSeguro(<?php echo $_helper->getConfigJs()?>);
17
+ console.info('PagSeguro ready');
18
+ }
19
+ preparePagSeguro();
20
+
21
//]]>
22
</script>
app/design/frontend/base/default/template/ricardomartins_pagseguro/form/cc.phtml CHANGED
@@ -1,6 +1,11 @@
1
<?php
2
/** @var RicardoMartins_PagSeguro_Block_Form_Cc $this */
3
$_code=$this->getMethodCode();
4
?>
5
<ul class="form-list" id="payment_form_<?php echo $_code ?>" style="display:none;">
6
<?php /*
@@ -38,8 +43,6 @@ $_code=$this->getMethodCode();
38
<?php #nao remover os campos abaixo ?>
39
<span id="card-brand" style="text-transform: capitalize; display: block;"></span>
40
<span id="card-msg" style="color: red;clear:left; display: block;"></span>
41
- <input type="hidden" name="payment[ps_card_type]"/>
42
- <input type="hidden" name="payment[credit_card_token]"/>
43
</div>
44
</li>
45
<li id="<?php echo $_code ?>_cc_type_exp_div">
@@ -87,11 +90,29 @@ $_code=$this->getMethodCode();
87
<?php /* O selo do PagSeguro deve ser exibido obrigatoriamente. Você pode escolher outra imagem disponivel na pasta 'selo' */ ?>
88
<div class="selo-pagseguro"><img src="<?php echo $this->getSkinUrl('pagseguro/selo/selo04_200x60.gif');?>" alt="Pagamento processado pelo PagSeguro"/></div>
89
</li>
90
</ul>
91
<script type="text/javascript">
92
//<![CDATA[
93
- if ('undefined' !== typeof RMPagSeguro) {
94
- RMPagSeguro.getInstallments();
95
}
96
//]]
97
- </script>
1
<?php
2
/** @var RicardoMartins_PagSeguro_Block_Form_Cc $this */
3
$_code=$this->getMethodCode();
4
+ $_grandTotal = Mage::helper('checkout/cart')->getQuote()->getGrandTotal();
5
+ $_grandTotal = (!$_grandTotal)?'null':$_grandTotal;
6
+ $_installments = Mage::getSingleton('checkout/session')->getQuote()->getPayment()->getAdditionalInformation('installment_quantity');
7
+ $_installments = (!$_installments)?'null':$_installments;
8
+
9
?>
10
<ul class="form-list" id="payment_form_<?php echo $_code ?>" style="display:none;">
11
<?php /*
43
<?php #nao remover os campos abaixo ?>
44
<span id="card-brand" style="text-transform: capitalize; display: block;"></span>
45
<span id="card-msg" style="color: red;clear:left; display: block;"></span>
46
</div>
47
</li>
48
<li id="<?php echo $_code ?>_cc_type_exp_div">
90
<?php /* O selo do PagSeguro deve ser exibido obrigatoriamente. Você pode escolher outra imagem disponivel na pasta 'selo' */ ?>
91
<div class="selo-pagseguro"><img src="<?php echo $this->getSkinUrl('pagseguro/selo/selo04_200x60.gif');?>" alt="Pagamento processado pelo PagSeguro"/></div>
92
</li>
93
+ <?php if ($this->helper('ricardomartins_pagseguro')->isInfoBrlActive()): ?>
94
+ <li>
95
+ <p class="info-brl">
96
+ <img src="<?php echo $this->getSkinUrl('pagseguro/selo/brflag.png'); ?>" alt="Bandeira do Brasil" style="float: left">
97
+ Esta compra está sendo feita no <strong>Brasil</strong>.
98
+ </p>
99
+ </li>
100
+ <?php endif;?>
101
</ul>
102
<script type="text/javascript">
103
//<![CDATA[
104
+ // if ('undefined' !== typeof RMPagSeguro) {
105
+ // RMPagSeguro.getInstallments();
106
+ // }
107
+ if(typeof RMPagSeguroObj != "undefined"){
108
+ if(RMPagSeguroObj.config.debug){
109
+ console.info('Adicionando observer para campos de cartão...');
110
}
111
+ RMPagSeguroObj.addCardFieldsObserver(RMPagSeguroObj);
112
+ if(typeof RMPagSeguroObj.brand != "undefined"){
113
+ RMPagSeguroObj.updateBrand();
114
+ RMPagSeguroObj.getInstallments(<?php echo $_grandTotal . ',' . $_installments;?>);
115
+ }
116
+ }
117
//]]
118
+ </script>
app/design/frontend/base/default/template/ricardomartins_pagseguro/form/cc/dob.phtml CHANGED
@@ -54,21 +54,21 @@ NOTE: Regarding styles - if we leave it this way, we'll move it to boxes.css
54
<?php
55
$this->setDateInput('d',
56
'<div class="dob-day">
57
- <input type="text" id="' . $this->getFieldId('day') . '" name="' . $this->getFieldName('day') . '" value="' . $this->getDay() . '" title="' . $this->__('Day') . '" class="input-text validate-custom" ' . $this->getFieldParams() . ' />
58
<label for="' . $this->getFieldId('day') . '">' . $this->__('DD') . '</label>
59
</div>'
60
);
61
62
$this->setDateInput('m',
63
'<div class="dob-month">
64
- <input type="text" id="' . $this->getFieldId('month') . '" name="' . $this->getFieldName('month') . '" value="' . $this->getMonth() . '" title="' . $this->__('Month') . '" class="input-text validate-custom" ' . $this->getFieldParams() . ' />
65
<label for="' . $this->getFieldId('month') . '">' . $this->__('MM') . '</label>
66
</div>'
67
);
68
69
$this->setDateInput('y',
70
'<div class="dob-year">
71
- <input type="text" id="' . $this->getFieldId('year') . '" name="' . $this->getFieldName('year') . '" value="' . $this->getYear() . '" title="' . $this->__('Year') . '" class="input-text validate-custom" ' . $this->getFieldParams() . ' />
72
<label for="' . $this->getFieldId('year') . '">' . $this->__('YYYY') . '</label>
73
</div>'
74
);
54
<?php
55
$this->setDateInput('d',
56
'<div class="dob-day">
57
+ <input type="text" id="' . $this->getFieldId('day') . '" name="' . $this->getFieldName('day') . '" value="' . $this->getDay() . '" title="' . $this->__('Day') . '" class="input-text validate-custom" ' . $this->getFieldParams() . ' maxlength="2" />
58
<label for="' . $this->getFieldId('day') . '">' . $this->__('DD') . '</label>
59
</div>'
60
);
61
62
$this->setDateInput('m',
63
'<div class="dob-month">
64
+ <input type="text" id="' . $this->getFieldId('month') . '" name="' . $this->getFieldName('month') . '" value="' . $this->getMonth() . '" title="' . $this->__('Month') . '" class="input-text validate-custom" ' . $this->getFieldParams() . ' maxlength="2"/>
65
<label for="' . $this->getFieldId('month') . '">' . $this->__('MM') . '</label>
66
</div>'
67
);
68
69
$this->setDateInput('y',
70
'<div class="dob-year">
71
+ <input type="text" id="' . $this->getFieldId('year') . '" name="' . $this->getFieldName('year') . '" value="' . $this->getYear() . '" title="' . $this->__('Year') . '" class="input-text validate-custom" ' . $this->getFieldParams() . ' maxlength="4"/>
72
<label for="' . $this->getFieldId('year') . '">' . $this->__('YYYY') . '</label>
73
</div>'
74
);
app/design/frontend/base/default/template/ricardomartins_pagseguro/form/directpayment.phtml CHANGED
@@ -1,22 +1,21 @@
1
<?php
2
$_helper = Mage::helper('ricardomartins_pagseguro');
3
?>
4
- <input type="hidden" name="payment[sender_hash]"/>
5
<script type="text/javascript">
6
//<![CDATA[
7
var preparePagSeguro = function(){
8
- var iid = setInterval(function()
9
- {
10
- if(typeof PagSeguroDirectPayment != "undefined" && PagSeguroDirectPayment.ready){
11
- console.log('PagSeguro ready');
12
13
- clearInterval(iid);
14
- RMPagSeguro.updateSenderHash();
15
- RMPagSeguro.addBrandObserver();
16
- RMPagSeguro.addCardFieldsObserver();
17
- RMPagSeguro.removeUnavailableBanks();
18
- }
19
- }, 4000);
20
}
21
preparePagSeguro();
22
1
<?php
2
$_helper = Mage::helper('ricardomartins_pagseguro');
3
?>
4
<script type="text/javascript">
5
//<![CDATA[
6
var preparePagSeguro = function(){
7
+ if(typeof RMPagSeguroObj != "undefined"){
8
+ <?php if ($_helper->isDebugActive()): ?>
9
+ console.info('PagSeguro was already started.');
10
+ <?php endif; ?>
11
+ return;
12
+ }
13
+ <?php if ($_helper->isDebugActive()): ?>
14
+ console.info('PagSeguro is initiating. Wait for ready message.');
15
+ <?php endif; ?>
16
+ RMPagSeguroObj = new RMPagSeguro(<?php echo $_helper->getConfigJs()?>);
17
+ console.info('PagSeguro ready');
18
19
}
20
preparePagSeguro();
21
js/pagseguro/card.js ADDED
@@ -0,0 +1,2495 @@