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

Commit 6c86cef

Browse files
authored
Merge pull request #79 from gabriellucius/checkout-without-address
Checkout without address
2 parents f72d6bc + 856bc68 commit 6c86cef

File tree

69 files changed

+2769
-145
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+2769
-145
lines changed

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

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,21 +117,15 @@ private function payment($payment)
117117
$this->setItems($payment);
118118
$payment->setSender()->setName($this->order->getCustomerName());
119119
$payment->setSender()->setEmail($this->order->getCustomerEmail());
120+
$this->setSenderPhone($payment);
120121

121122
if ($this->order->getShippingAddress() !== false) {
122123
$orderAddress = new UOL_PagSeguro_Model_OrderAddress($this->order);
123124
$payment->setShipping()->setAddress()->instance($orderAddress->getShippingAddress());
124125
$payment->setShipping()->setType()->withParameters(SHIPPING_TYPE);
125-
$payment->setShipping()->setCost()->withParameters(number_format($this->order->getShippingAmount(), 2, '.',
126-
''));
127-
//set phone
128-
if ($this->order->getShippingAddress()->getTelephone()) {
129-
$phone = $this->helper->formatPhone($this->order->getShippingAddress()->getTelephone());
130-
$payment->setSender()->setPhone()->withParameters($phone['areaCode'], $phone['number']);
131-
}
132-
126+
$payment->setShipping()->setCost()->withParameters(number_format($this->order->getShippingAmount(), 2, '.', ''));
133127
}
134-
128+
135129
$payment->setExtraAmount($this->order->getBaseDiscountAmount() + $this->order->getTaxAmount());
136130
$payment->setNotificationUrl($this->getNotificationURL());
137131

@@ -143,7 +137,12 @@ private function payment($payment)
143137
*/
144138
private function setItems($payment)
145139
{
140+
$payment->setShipping()->setAddressRequired()->withParameters('false');
141+
146142
foreach ($this->order->getAllVisibleItems() as $product) {
143+
// check shipping necessity according with each product in the cart
144+
$this->setShippingIsRequired($payment, $product->getData()['product_type']);
145+
147146
$payment->addItems()->withParameters(
148147
$product->getId(),
149148
substr($product->getName(), 0, 254),
@@ -302,4 +301,56 @@ public function getOneStepCheckoutIsEnabled()
302301
{
303302
return (Mage::getStoreConfig("onestepcheckout/general/is_enabled") == 1) ? true : false;
304303
}
304+
305+
/**
306+
* Checks if the product type requires shipping and, if it is required, set
307+
* the 'addressRequired' pagseguro api parameter to true
308+
*
309+
* @param \PagSeguro\Domains\Requests\DirectPayment\Boleto
310+
* | \PagSeguro\Domains\Requests\DirectPayment\CreditCard
311+
* | \PagSeguro\Domains\Requests\DirectPayment\OnlineDebit
312+
* | \PagSeguro\Domains\Requests\Payment
313+
* $payment
314+
* @param string $productType
315+
* @return void
316+
*/
317+
private function setShippingIsRequired($payment, $productType)
318+
{
319+
if (! in_array($productType, $this->productTypesWithoutShipping())) {
320+
$payment->setShipping()->setAddressRequired()->withParameters('true');
321+
}
322+
}
323+
324+
/**
325+
* Return an array of magento product types that do not require shipping
326+
*
327+
* @return array
328+
*/
329+
private function productTypesWithoutShipping()
330+
{
331+
return array('virtual', 'downloadable');
332+
}
333+
334+
/**
335+
* Set sender phone with magento phone from billing address or, in second case, from shipping address
336+
*
337+
* @param \PagSeguro\Domains\Requests\DirectPayment\Boleto
338+
* | \PagSeguro\Domains\Requests\DirectPayment\CreditCard
339+
* | \PagSeguro\Domains\Requests\DirectPayment\OnlineDebit
340+
* | \PagSeguro\Domains\Requests\Payment
341+
* $payment
342+
* @return void
343+
*/
344+
private function setSenderPhone($payment)
345+
{
346+
$phone = null;
347+
if ($this->order->getBillingAddress() && $this->order->getBillingAddress()->getTelephone()) {
348+
$phone = $this->helper->formatPhone($this->order->getBillingAddress()->getTelephone());
349+
} else if ($this->order->getShippingAddress() && $this->order->getShippingAddress()->getTelephone()) {
350+
$phone = $this->helper->formatPhone($this->order->getShippingAddress()->getTelephone());
351+
}
352+
if ($phone) {
353+
$payment->setSender()->setPhone()->withParameters($phone['areaCode'], $phone['number']);
354+
}
355+
}
305356
}

lib/PagseguroPhpSdk/CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
### 4.0.0 (25/01/2018)
2+
3+
#### Funcionalidades
4+
- **pagamento recorrente (assinatura) transparente:** editar valor de cobrança de planos ja criados
5+
- **autorização**: encaminhar os dados do cliente e sugestão para cadastro ao criar uma autorização
6+
- **checkout transparente:** removida funcionalidade depreciada (cartão de crédito internacional)
7+
8+
3.4.1
9+
- Correção na requisição de Pagamento e Retentativa de Pagamento Recorrente
10+
11+
3.4.0
12+
- Adicionada possibilidade de *não* enviar o endereço de entrega nas requisições (*shipping* opcional).
13+
14+
3.3.2
15+
- Correção no charset das requisições
16+
- Correção do erro "Undefined class constant 'INSTALLMENT_NO_INTEREST_INSTALLMENT_QUANTITY'" ao configurar o número de parcelas no checkout transparente com cartão de crédito.
17+
118
3.3.0
219
- Removidas funcionalidades depreciadas
320
- Correções e melhorias gerais

lib/PagseguroPhpSdk/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ A biblioteca PagSeguro em PHP é um conjunto de classes de domínio que facilita
2525
Requisitos
2626
----------
2727

28-
- [PHP] 5.4.27+
28+
- [PHP] 5.4.27+ || 5.5+ || 5.6+
2929
- [SPL]
3030
- [cURL]
3131
- [SimpleXml]

lib/PagseguroPhpSdk/public/Authorization/Search/searchAuthorizationByCode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
\PagSeguro\Library::initialize();
66

7-
$code = '2ED002E234444A0D9469EF14F0D5A9C1';
7+
$code = 'FD3AF1B214EC40F0B0A6745D041BF50D';
88

99
try {
1010
$response = \PagSeguro\Services\Application\Search\Code::search(

lib/PagseguroPhpSdk/public/Authorization/Search/searchAuthorizationByNotification.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
\PagSeguro\Library::initialize();
66

7-
$code = '7DD98273EB72EB7238388469DF9008F43A14';
7+
$code = '7BD4A616E8C3E8C3F57BB440FFA9ABEAE6F2';
88

99
try {
1010
$response = \PagSeguro\Services\Application\Search\Notification::search(

lib/PagseguroPhpSdk/public/Authorization/createAuthorization.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
require_once "../../vendor/autoload.php";
44

5-
\PagSeguro\Library::initialize();
5+
try {
6+
\PagSeguro\Library::initialize();
7+
} catch (Exception $e) {
8+
die($e);
9+
}
610
\PagSeguro\Library::cmsVersion()->setName("Nome")->setRelease("1.0.0");
711
\PagSeguro\Library::moduleVersion()->setName("Nome")->setRelease("1.0.0");
812

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
require_once "../../vendor/autoload.php";
4+
5+
try {
6+
\PagSeguro\Library::initialize();
7+
} catch (Exception $e) {
8+
die($e);
9+
}
10+
\PagSeguro\Library::cmsVersion()->setName("Nome")->setRelease("1.0.0");
11+
\PagSeguro\Library::moduleVersion()->setName("Nome")->setRelease("1.0.0");
12+
13+
$authorization = new \PagSeguro\Domains\Requests\Authorization();
14+
15+
$authorization->setReference("AUTH_LIB_PHP_0001");
16+
$authorization->setRedirectUrl("http://www.lojamodelo.com.br");
17+
$authorization->setNotificationUrl("http://www.lojamodelo.com.br/nofitication");
18+
19+
$authorization->addPermission(\PagSeguro\Enum\Authorization\Permissions::CREATE_CHECKOUTS);
20+
$authorization->addPermission(\PagSeguro\Enum\Authorization\Permissions::SEARCH_TRANSACTIONS);
21+
$authorization->addPermission(\PagSeguro\Enum\Authorization\Permissions::RECEIVE_TRANSACTION_NOTIFICATIONS);
22+
$authorization->addPermission(\PagSeguro\Enum\Authorization\Permissions::MANAGE_PAYMENT_PRE_APPROVALS);
23+
$authorization->addPermission(\PagSeguro\Enum\Authorization\Permissions::DIRECT_PAYMENT);
24+
25+
$partner = new \PagSeguro\Domains\Authorization\Partner(
26+
'John Doe',
27+
new DateTime(),
28+
new \PagSeguro\Domains\Document('CPF', '00000000000'),
29+
new \PagSeguro\Domains\Phone('00', '000000000', \PagSeguro\Enum\Authorization\PhoneEnum::HOME)
30+
);
31+
32+
$person = new \PagSeguro\Domains\Authorization\Company(
33+
'John Doe',
34+
'http://www.example.com',
35+
new \PagSeguro\Domains\Document('CPF', '00000000000'),
36+
new \PagSeguro\Domains\Phone('00', '000000000', \PagSeguro\Enum\Authorization\PhoneEnum::BUSINESS),
37+
new \PagSeguro\Domains\Address('Rua Um',
38+
'1',
39+
'Sem complemento',
40+
'Bairro',
41+
'00000000',
42+
'Cidade',
43+
'UF',
44+
'BRA'),
45+
$partner);
46+
47+
/**
48+
* Com o método a seguir é possível especificar outros telefones
49+
*
50+
* Os tipos de telefone permitidos são HOME, MOBILE e BUSINESS.
51+
*/
52+
$person->addPhones(new \PagSeguro\Domains\Phone('00', '000000000', \PagSeguro\Enum\Authorization\PhoneEnum::HOME));
53+
$person->addPhones(new \PagSeguro\Domains\Phone('00', '000000000', \PagSeguro\Enum\Authorization\PhoneEnum::BUSINESS));
54+
55+
$account = new \PagSeguro\Domains\Authorization\Account('[email protected]', $person);
56+
57+
$authorization->setAccount($account);
58+
59+
try {
60+
$response = $authorization->register(
61+
\PagSeguro\Configuration\Configure::getApplicationCredentials()
62+
);
63+
echo "<h2>Criando requisi&ccedil;&atilde;o de authorização</h2>"
64+
. "<p>URL do pagamento: <strong>$response</strong></p>"
65+
. "<p><a title=\"URL de Autorização\" href=\"$response\" target=\_blank\">"
66+
. "Ir para URL de authorização.</a></p>";
67+
} catch (Exception $e) {
68+
die($e->getMessage());
69+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
require_once "../../vendor/autoload.php";
4+
5+
try {
6+
\PagSeguro\Library::initialize();
7+
} catch (Exception $e) {
8+
die($e);
9+
}
10+
\PagSeguro\Library::cmsVersion()->setName("Nome")->setRelease("1.0.0");
11+
\PagSeguro\Library::moduleVersion()->setName("Nome")->setRelease("1.0.0");
12+
13+
$authorization = new \PagSeguro\Domains\Requests\Authorization();
14+
15+
$authorization->setReference("AUTH_LIB_PHP_0001");
16+
$authorization->setRedirectUrl("http://www.lojamodelo.com.br");
17+
$authorization->setNotificationUrl("http://www.lojamodelo.com.br/nofitication");
18+
19+
$authorization->addPermission(\PagSeguro\Enum\Authorization\Permissions::CREATE_CHECKOUTS);
20+
$authorization->addPermission(\PagSeguro\Enum\Authorization\Permissions::SEARCH_TRANSACTIONS);
21+
$authorization->addPermission(\PagSeguro\Enum\Authorization\Permissions::RECEIVE_TRANSACTION_NOTIFICATIONS);
22+
$authorization->addPermission(\PagSeguro\Enum\Authorization\Permissions::MANAGE_PAYMENT_PRE_APPROVALS);
23+
$authorization->addPermission(\PagSeguro\Enum\Authorization\Permissions::DIRECT_PAYMENT);
24+
25+
$person = new \PagSeguro\Domains\Authorization\Personal(
26+
'John Doe',
27+
new DateTime('10-10-1990'),
28+
new \PagSeguro\Domains\Document('CPF', '00000000000'),
29+
new \PagSeguro\Domains\Phone('00', '000000000', \PagSeguro\Enum\Authorization\PhoneEnum::MOBILE),
30+
new \PagSeguro\Domains\Address('Rua Um',
31+
'1',
32+
'Sem complemento',
33+
'Bairro',
34+
'00000000',
35+
'Cidade',
36+
'UF',
37+
'BRA'));
38+
39+
/**
40+
* Com o método a seguir é possível especificar outros telefones
41+
*
42+
* Os tipos de telefone permitidos são HOME, MOBILE e BUSINESS.
43+
*/
44+
$person->addPhones(new \PagSeguro\Domains\Phone('00', '000000000', \PagSeguro\Enum\Authorization\PhoneEnum::BUSINESS));
45+
$person->addPhones(new \PagSeguro\Domains\Phone('00', '000000000', \PagSeguro\Enum\Authorization\PhoneEnum::BUSINESS));
46+
47+
$account = new \PagSeguro\Domains\Authorization\Account('[email protected]', $person);
48+
49+
$authorization->setAccount($account);
50+
51+
try {
52+
$response = $authorization->register(
53+
\PagSeguro\Configuration\Configure::getApplicationCredentials()
54+
);
55+
echo "<h2>Criando requisi&ccedil;&atilde;o de authorização</h2>"
56+
. "<p>URL do pagamento: <strong>$response</strong></p>"
57+
. "<p><a title=\"URL de Autorização\" href=\"$response\" target=\_blank\">"
58+
. "Ir para URL de authorização.</a></p>";
59+
} catch (Exception $e) {
60+
die($e->getMessage());
61+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
require_once "../../vendor/autoload.php";
4+
5+
try {
6+
\PagSeguro\Library::initialize();
7+
} catch (Exception $e) {
8+
die($e);
9+
}
10+
\PagSeguro\Library::cmsVersion()->setName("Nome")->setRelease("1.0.0");
11+
\PagSeguro\Library::moduleVersion()->setName("Nome")->setRelease("1.0.0");
12+
13+
$authorization = new \PagSeguro\Domains\Requests\Authorization();
14+
15+
$authorization->setReference("AUTH_LIB_PHP_0001");
16+
$authorization->setRedirectUrl("http://www.lojamodelo.com.br");
17+
$authorization->setNotificationUrl("http://www.lojamodelo.com.br/nofitication");
18+
19+
$authorization->addPermission(\PagSeguro\Enum\Authorization\Permissions::CREATE_CHECKOUTS);
20+
$authorization->addPermission(\PagSeguro\Enum\Authorization\Permissions::SEARCH_TRANSACTIONS);
21+
$authorization->addPermission(\PagSeguro\Enum\Authorization\Permissions::RECEIVE_TRANSACTION_NOTIFICATIONS);
22+
$authorization->addPermission(\PagSeguro\Enum\Authorization\Permissions::MANAGE_PAYMENT_PRE_APPROVALS);
23+
$authorization->addPermission(\PagSeguro\Enum\Authorization\Permissions::DIRECT_PAYMENT);
24+
25+
$person = new \PagSeguro\Domains\Authorization\Seller(
26+
'John Doe',
27+
new DateTime('10-10-1990'),
28+
new \PagSeguro\Domains\Document('CPF', '00000000000'),
29+
new \PagSeguro\Domains\Phone('00', '000000000', \PagSeguro\Enum\Authorization\PhoneEnum::MOBILE),
30+
new \PagSeguro\Domains\Address('Rua Um',
31+
'1',
32+
'Sem complemento',
33+
'Bairro',
34+
'00000000',
35+
'Cidade',
36+
'UF',
37+
'BRA'));
38+
39+
/**
40+
* Com o método a seguir é possível especificar outros telefones
41+
*
42+
* Os tipos de telefone permitidos são HOME, MOBILE e BUSINESS.
43+
*/
44+
$person->addPhones(new \PagSeguro\Domains\Phone('00', '000000000', \PagSeguro\Enum\Authorization\PhoneEnum::HOME));
45+
$person->addPhones(new \PagSeguro\Domains\Phone('00', '000000000', \PagSeguro\Enum\Authorization\PhoneEnum::BUSINESS));
46+
47+
$account = new \PagSeguro\Domains\Authorization\Account('[email protected]', $person);
48+
49+
$authorization->setAccount($account);
50+
51+
try {
52+
$response = $authorization->register(
53+
\PagSeguro\Configuration\Configure::getApplicationCredentials()
54+
);
55+
echo "<h2>Criando requisi&ccedil;&atilde;o de authorização</h2>"
56+
. "<p>URL do pagamento: <strong>$response</strong></p>"
57+
. "<p><a title=\"URL de Autorização\" href=\"$response\" target=\_blank\">"
58+
. "Ir para URL de authorização.</a></p>";
59+
} catch (Exception $e) {
60+
die($e->getMessage());
61+
}

lib/PagseguroPhpSdk/public/Configuration/dynamicConfiguration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
\PagSeguro\Configuration\Configure::setLog(true, '/logpath/logFilename.log');
4444

4545
/**
46-
* @todo To set the application credentials intead of the account credentials use:
46+
* @todo To set the application credentials instead of the account credentials use:
4747
* \PagSeguro\Configuration\Configure::setApplicationCredentials(
4848
* 'appId',
4949
* 'appKey'

0 commit comments

Comments
 (0)