Skip to content
This repository was archived by the owner on Apr 24, 2023. It is now read-only.

Commit 2688a26

Browse files
Merge pull request #43 from pagseguro/desenvolvimento
Desenvolvimento
2 parents 81bb6c4 + 3443c56 commit 2688a26

File tree

13 files changed

+349
-16
lines changed

13 files changed

+349
-16
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Para acessar e configurar o módulo acesse o menu PagSeguro -> Configurações.
6161
- **transações -> estorno**: esta pesquisa retornará todas as transações que estejam com status "paga", "disponível" e "em disputa", dentro da quantidade de dias definidos para a pesquisa. Desta forma você pode solicitar o estorno dos valores pagos para seus compradores.
6262
- **transações -> estorno -> dias**: número de dias que devem ser considerados para a pesquisa.
6363
- **requisitos**: exibe se os pré-requisitos básicos para o correto funcionamento do módulo estão sendo atendidos
64+
- **listar parcelamento**: Habilita a exibição de uma listagem de parcelas na tela de visualização do produto. (Irá exibir o maior parcelamento disponível para o produto na tela de exibição do mesmo)
6465

6566

6667
Dúvidas?
@@ -72,6 +73,9 @@ Caso tenha dúvidas ou precise de suporte, acesse nosso [fórum].
7273
Changelog
7374
---------
7475
---
76+
2.8.0
77+
- Possibilidade de exibir uma lista com o maior parcelamento disponível de acordo com o preço do produto visualizado;
78+
7579
2.7.0
7680
- Possibilidade de consultar e solicitar o cancelamento de transações;
7781
- Possibilidade de consultar e solicitar o estorno de transações;

UOL_PagSeguro-2.7.0.tgz

-343 KB
Binary file not shown.

UOL_PagSeguro-2.8.0.tgz

346 KB
Binary file not shown.

app/code/community/UOL/PagSeguro/Helper/Data.php

+31
Original file line numberDiff line numberDiff line change
@@ -629,4 +629,35 @@ public function getPaymentStatusToString(Integer $key)
629629
}
630630
return false;
631631
}
632+
633+
/**
634+
* Format string phone number
635+
* @param string $phone
636+
* @return array of area code and number
637+
*/
638+
public function formatPhone($phone)
639+
{
640+
$phone = preg_replace('/[^0-9]/', '', $phone);
641+
$ddd = '';
642+
643+
if (strlen($phone) > 9) {
644+
if (substr($phone, 0, 1) == 0) {
645+
$phone = substr($phone, 1);
646+
}
647+
648+
$ddd = substr($phone, 0, 2);
649+
$phone = substr($phone, 2);
650+
}
651+
652+
return array('areaCode' => $ddd, 'number' => $phone);
653+
}
654+
655+
/**
656+
* Request installments method
657+
* @return UOL_PagSeguro_Model_InstallmentsMethod
658+
*/
659+
public function installmentsModel()
660+
{
661+
return Mage::getSingleton('UOL_PagSeguro_Model_InstallmentsMethod');
662+
}
632663
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
<?php
2+
3+
/**
4+
************************************************************************
5+
Copyright [2015] [PagSeguro Internet Ltda.]
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
************************************************************************
19+
*/
20+
21+
use Mage_Payment_Model_Method_Abstract as MethodAbstract;
22+
23+
/**
24+
* PagSeguro installments model
25+
*/
26+
class UOL_PagSeguro_Model_InstallmentsMethod extends MethodAbstract
27+
{
28+
protected $_code = 'pagseguro';
29+
/**
30+
* Construct
31+
*/
32+
public function __construct()
33+
{
34+
$this->helper = Mage::helper('pagseguro');
35+
include_once(Mage::getBaseDir('lib') . '/PagSeguroLibrary/PagSeguroLibrary.php');
36+
include_once(Mage::getBaseDir('code') . '/community/UOL/PagSeguro/Model/Defines.php');
37+
}
38+
39+
/**
40+
* Check if installments show is enabled
41+
*/
42+
public function enabled()
43+
{
44+
return (Mage::getStoreConfig('payment/pagseguro/active') == 1 &&
45+
Mage::getStoreConfig('payment/pagseguro/installments') == 1) ?
46+
true :
47+
false;
48+
}
49+
50+
/**
51+
* Get the bigger installments list returned by the PagSeguro service
52+
* @param mixed $amount
53+
* @param string $brand
54+
* @return array | false
55+
*/
56+
public function create($amount, $brand = '')
57+
{
58+
$this->helper = Mage::helper('pagseguro');
59+
$this->setPagSeguroConfig();
60+
$credentials = $this->getCredentialsInformation();
61+
62+
try {
63+
$session = PagSeguroSessionService::getSession($credentials);
64+
$installments = PagSeguroInstallmentService::getInstallments(
65+
$credentials,
66+
$session,
67+
$amount,
68+
$brand
69+
);
70+
71+
$format = $this->output($installments, true);
72+
return $format['installments'];
73+
74+
} catch (Exception $exception) {
75+
Mage::log($exception->getMessage());
76+
return false;
77+
}
78+
}
79+
80+
/**
81+
* Get the bigger installments list in the installments
82+
* @param array $installments
83+
* @return array
84+
*/
85+
private function getMaxInstallment($installments)
86+
{
87+
$final = $current = array('brand' => '', 'start' => 0, 'final' => 0, 'quantity' => 0);
88+
89+
foreach ($installments as $key => $installment) {
90+
if ($current['brand'] !== $installment->getCardBrand()) {
91+
$current['brand'] = $installment->getCardBrand();
92+
$current['start'] = $key;
93+
}
94+
$current['quantity'] = $installment->getQuantity();
95+
$current['end'] = $key;
96+
if ($current['quantity'] > $final['quantity']) {
97+
$final = $current;
98+
}
99+
}
100+
101+
return array_slice(
102+
$installments,
103+
$final['start'],
104+
$final['end'] - $final['start'] + 1
105+
);
106+
}
107+
108+
/**
109+
* Set Config's to PagSeguro API
110+
*/
111+
private function setPagSeguroConfig()
112+
{
113+
$activeLog = $this->getConfigData('log');
114+
$charset = $this->getConfigData('charset');
115+
116+
//Module version
117+
PagSeguroLibrary::setModuleVersion('magento' . ':' . Mage::helper('pagseguro')->getVersion());
118+
119+
//CMS version
120+
PagSeguroLibrary::setCMSVersion('magento' . ':' . Mage::getVersion());
121+
122+
//Setup Charset
123+
if ($charset != null and !empty($charset)) {
124+
PagSeguroConfig::setApplicationCharset($charset);
125+
}
126+
127+
//Setup Log
128+
if ($activeLog == 1) {
129+
$logFile = $this->getConfigData('log_file');
130+
131+
if (self::checkFile(Mage::getBaseDir() . '/' . $logFile)) {
132+
PagSeguroConfig::activeLog(Mage::getBaseDir() . '/' . $logFile);
133+
} else {
134+
PagSeguroConfig::activeLog(); //Default Log
135+
}
136+
}
137+
}
138+
139+
/**
140+
* Get the access credential
141+
* @return PagSeguroAccountCredentials
142+
*/
143+
public function getCredentialsInformation()
144+
{
145+
$email = $this->getConfigData('email');
146+
$token = $this->getConfigData('token');
147+
$credentials = new PagSeguroAccountCredentials($email, $token);
148+
149+
return $credentials;
150+
}
151+
152+
/**
153+
* If file not exist, try create.
154+
* @param string $file
155+
* @return boolean $fileExist
156+
*/
157+
private static function checkFile($file)
158+
{
159+
try {
160+
$f = fopen($file, 'a');
161+
$fileExist = true;
162+
fclose($f);
163+
} catch (Exception $ex) {
164+
$fileExist = false;
165+
Mage::logException($ex);
166+
}
167+
168+
return $fileExist;
169+
}
170+
171+
/**
172+
* Return a formated output of installments
173+
*
174+
* @param array $installments
175+
* @param bool $maxInstallment
176+
* @return array
177+
*/
178+
private function output($installments, $maxInstallment)
179+
{
180+
return ($maxInstallment) ?
181+
$this->formatOutput($this->getMaxInstallment($installments)) :
182+
$this->formatOutput($installments);
183+
}
184+
185+
/**
186+
* Format the installment to the be show in the view
187+
* @param array $installments
188+
* @return array
189+
*/
190+
private function formatOutput($installments)
191+
{
192+
$response = $this->getOptions();
193+
foreach($installments as $installment) {
194+
$response['installments'][] = $this->formatInstallments($installment);
195+
}
196+
return $response;
197+
}
198+
/**
199+
* Format a installment for output
200+
*
201+
* @param $installment
202+
* @return array
203+
*/
204+
private function formatInstallments($installment)
205+
{
206+
return array(
207+
'quantity' => $installment->getQuantity(),
208+
'amount' => $installment->getInstallmentAmount(),
209+
'totalAmount' => PagSeguroHelper::decimalFormat($installment->getTotalAmount()),
210+
'text' => str_replace('.', ',', $this->getInstallmentText($installment))
211+
);
212+
}
213+
214+
/**
215+
* Mount the text message of the installment
216+
* @param object $installment
217+
* @return string
218+
*/
219+
private function getInstallmentText($installment)
220+
{
221+
return sprintf(
222+
"%s x de R$ %.2f %s juros",
223+
$installment->getQuantity(),
224+
$installment->getInstallmentAmount(),
225+
$this->getInterestFreeText($installment->getInterestFree()));
226+
}
227+
228+
/**
229+
* Get the string relative to if it is an interest free or not
230+
* @param string $insterestFree
231+
* @return string
232+
*/
233+
private function getInterestFreeText($insterestFree)
234+
{
235+
return ($insterestFree == 'true') ? 'sem' : 'com';
236+
}
237+
}

app/code/community/UOL/PagSeguro/Model/PaymentMethod.php

+2
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,11 @@ public function getCredentialsInformation()
312312
*/
313313
private function getSenderInformation()
314314
{
315+
$phone = Mage::helper('pagseguro')->formatPhone($this->order->getBillingAddress()->getTelephone());
315316
$PagSeguroSender = new PagSeguroSender();
316317
$PagSeguroSender->setEmail($this->order['customer_email']);
317318
$PagSeguroSender->setName($this->order['customer_firstname'] . ' ' . $this->order['customer_lastname']);
319+
$PagSeguroSender->setPhone($phone['areaCode'], $phone['number']);
318320

319321
return $PagSeguroSender;
320322
}

app/code/community/UOL/PagSeguro/etc/config.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ limitations under the License.
1919
<config>
2020
<modules>
2121
<UOL_PagSeguro>
22-
<version>2.7.0</version>
22+
<version>2.8.0</version>
2323
</UOL_PagSeguro>
2424
</modules>
2525
<global>

app/code/community/UOL/PagSeguro/etc/system.xml

+10
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,16 @@ limitations under the License.
287287
<discount_balance>1</discount_balance>
288288
</depends>
289289
</discount_balance_value>
290+
<installments translate="label">
291+
<label>LISTAR PARCELAMENTO</label>
292+
<tooltip>Habilita a exibição da listagem de parcelas na tela de visualização do produto. (Irá exibir o maior parcelamento disponível para o produto no pagamento com cartão de crédito)</tooltip>
293+
<frontend_type>select</frontend_type>
294+
<source_model>adminhtml/system_config_source_yesno</source_model>
295+
<sort_order>190</sort_order>
296+
<show_in_default>1</show_in_default>
297+
<show_in_website>1</show_in_website>
298+
<show_in_store>1</show_in_store>
299+
</installments>
290300
</fields>
291301
</pagseguro>
292302
</groups>

app/design/frontend/base/default/layout/uol/pagseguro.xml

+14
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,18 @@ limitations under the License.
5252
<block type="uol_pagseguro/payment" name="loading" template="uol/pagseguro/loading.phtml" />
5353
</reference>
5454
</checkout_onepage_index>
55+
56+
<catalog_product_view>
57+
<reference name="head">
58+
<action method="addItem">
59+
<type>skin_css</type>
60+
<script>uol/pagseguro/css/installments.css</script>
61+
<params><![CDATA[media="all"]]></params>
62+
</action>
63+
</reference>
64+
65+
<reference name="product.info.addtocart">
66+
<block type="core/template" name="pagseguro.installments.table" template="uol/pagseguro/installments.phtml" after="-"/>
67+
</reference>
68+
</catalog_product_view>
5569
</layout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
$helper = Mage::helper('pagseguro');
3+
4+
if ($helper->installmentsModel()->enabled()) {
5+
$productPrice = Mage::registry('current_product')->getFinalPrice();
6+
$installments = $helper->installmentsModel()->create($productPrice);
7+
8+
if ($installments) {
9+
$countInstallment = count($installments);
10+
$halfInstallment = ceil($countInstallment/2);
11+
12+
$totalAmount = str_replace('.', ',', $installments[$countInstallment-1]['totalAmount']);
13+
14+
echo "<table class=\"pagseguro-installments-table\"><caption>Ou pague em até {$installments[$countInstallment-1]['text']} (Total a prazo R\${$totalAmount})</caption><tbody>";
15+
16+
for($i = 0; $i < $halfInstallment; $i++) {
17+
echo "<tr><td>{$installments[$i]['text']}</td>";
18+
if (isset($installments[$i + $halfInstallment]['text'])) {
19+
echo "<td>{$installments[$i + $halfInstallment]['text']}</td>";
20+
}
21+
echo "</tr>";
22+
}
23+
echo "</tbody></table>";
24+
}
25+
}

0 commit comments

Comments
 (0)