Skip to content

Commit

Permalink
Merge pull request #99 from pagseguro/desenvolvimento
Browse files Browse the repository at this point in the history
Add shipping address required option
  • Loading branch information
s2it-moscou authored Dec 18, 2017
2 parents 7c72d96 + c6a2215 commit 3c1fa99
Show file tree
Hide file tree
Showing 12 changed files with 216 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
3.4.0
- Adicionada possibilidade de *não* enviar o endereço de entrega nas requisições (*shipping* opcional).

3.3.2
- Correção no charset das requisições
- 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.
Expand Down
3 changes: 3 additions & 0 deletions public/DirectPayment/usingBoleto.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
'apto. 114'
);

// If your payment request don't need shipping information use:
// $boleto->setShipping()->setAddressRequired()->withParameters('FALSE');

try {
//Get the crendentials and register the boleto payment
$result = $boleto->register(
Expand Down
2 changes: 2 additions & 0 deletions source/Domains/Requests/Adapter/Shipping.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
namespace PagSeguro\Domains\Requests\Adapter;

use PagSeguro\Domains\Requests\Shipping\Address;
use PagSeguro\Domains\Requests\Shipping\AddressRequired;
use PagSeguro\Domains\Requests\Shipping\Type;
use PagSeguro\Domains\Requests\Shipping\Cost;

Expand All @@ -33,6 +34,7 @@ class Shipping
use Address;
use Cost;
use Type;
use AddressRequired;

private $shipping;

Expand Down
41 changes: 41 additions & 0 deletions source/Domains/Requests/Shipping/AddressRequired.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* 2007-2016 [PagSeguro Internet Ltda.]
*
* NOTICE OF LICENSE
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author PagSeguro Internet Ltda.
* @copyright 2007-2016 PagSeguro Internet Ltda.
* @license http://www.apache.org/licenses/LICENSE-2.0
*
*/

namespace PagSeguro\Domains\Requests\Shipping;

trait AddressRequired
{
private $addressRequired;

public function getAddressRequired()
{
return current($this->addressRequired);
}

public function setAddressRequired()
{
$this->addressRequired = new \PagSeguro\Resources\Factory\Shipping\AddressRequired($this->shipping);
return $this->addressRequired;
}
}
22 changes: 22 additions & 0 deletions source/Domains/Shipping.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class Shipping
* Shipping cost.
*/
private $cost;
/***
* Shipping address required.
*/
private $addressRequired;

/**
* @return Address
Expand Down Expand Up @@ -95,4 +99,22 @@ public function setType($type)
$this->type = $type;
return $this;
}

/**
* @return ShippingAddressRequired
*/
public function getAddressRequired()
{
return $this->addressRequired;
}

/**
* @param ShippingAddressRequired $addressRequired
* @return Shipping
*/
public function setAddressRequired($addressRequired)
{
$this->addressRequired = $addressRequired;
return $this;
}
}
54 changes: 54 additions & 0 deletions source/Domains/ShippingAddressRequired.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/**
* 2007-2016 [PagSeguro Internet Ltda.]
*
* NOTICE OF LICENSE
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author PagSeguro Internet Ltda.
* @copyright 2007-2016 PagSeguro Internet Ltda.
* @license http://www.apache.org/licenses/LICENSE-2.0
*
*/

namespace PagSeguro\Domains;

/**
* Class ShippingAddressRequired
* @package PagSeguro\Domains
*/
class ShippingAddressRequired
{

/**
* @var
*/
private $addressRequired;

/**
* @return string
*/
public function getAddressRequired()
{
return $this->addressRequired;
}

/**
* @param string $addressRequired
*/
public function setAddressRequired($addressRequired)
{
$this->addressRequired = $addressRequired;
}
}
5 changes: 5 additions & 0 deletions source/Enum/Properties/BackwardCompatibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,11 @@ class BackwardCompatibility
*/
const SHIPPING_ADDRESS_COUNTRY = "shipping.address.country";

/**
* Shipping address required
*/
const SHIPPING_ADDRESS_REQUIRED = "shipping.address.required";

/**
* Primary Key
*/
Expand Down
5 changes: 5 additions & 0 deletions source/Enum/Properties/Current.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,11 @@ class Current
*/
const SHIPPING_ADDRESS_COUNTRY = "shippingAddressCountry";

/**
* Shipping address required
*/
const SHIPPING_ADDRESS_REQUIRED = "shippingAddressRequired";

/**
* Redirect Url
*/
Expand Down
2 changes: 1 addition & 1 deletion source/Library.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Library
/**
*
*/
const VERSION = "3.3.2";
const VERSION = "3.4.0";
/**
* @var
*/
Expand Down
2 changes: 1 addition & 1 deletion source/Parsers/Response/Shipping.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
namespace PagSeguro\Parsers\Response;

use PagSeguro\Resources\Factory\Shipping\Address;
use PagSeguro\Resources\Factory\Shipping\AddressRequired;
use PagSeguro\Resources\Factory\Shipping\Cost;
use PagSeguro\Resources\Factory\Shipping\Type;

Expand Down Expand Up @@ -75,7 +76,6 @@ public function setShipping($shipping)

$shippingCost = new Cost($shippingClass);
$shippingCost->withParameters(current($shipping->cost));

$this->shipping = $shippingClass;
}
return $this;
Expand Down
16 changes: 16 additions & 0 deletions source/Parsers/Shipping.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public static function getData(Requests $request, $properties)
if (!is_null($request->getShipping()->getType())) {
$data = array_merge($data, self::type($request, $properties));
}
// address required
if (!is_null($request->getShipping()->getAddressRequired())) {
$data = array_merge($data, self::addressRequired($request, $properties));
}
// cost
if (!is_null($request->getShipping()->getCost())) {
$data = array_merge($data, self::cost($request, $properties));
Expand Down Expand Up @@ -84,6 +88,18 @@ private static function type($request, $properties)
return $data;
}

/**
* @param $request
* @param $properties
* @return string
*/
private static function addressRequired($request, $properties)
{
$data = [];
$data[$properties::SHIPPING_ADDRESS_REQUIRED] = $request->getShipping()->getAddressRequired()->getAddressRequired();
return $data;
}

/**
* @param $request
* @param $properties
Expand Down
63 changes: 63 additions & 0 deletions source/Resources/Factory/Shipping/AddressRequired.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* 2007-2016 [PagSeguro Internet Ltda.]
*
* NOTICE OF LICENSE
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author PagSeguro Internet Ltda.
* @copyright 2007-2016 PagSeguro Internet Ltda.
* @license http://www.apache.org/licenses/LICENSE-2.0
*
*/

namespace PagSeguro\Resources\Factory\Shipping;

use PagSeguro\Domains\ShippingAddressRequired;

/**
* Class Shipping
* @package PagSeguro\Resources\Factory\Request
*/
class AddressRequired
{

/**
* @var \PagSeguro\Domains\Shipping
*/
private $shipping;

/**
* Shipping constructor.
*/
public function __construct($shipping)
{
$this->shipping = $shipping;
}

public function instance(ShippingAddressRequired $addressRequired)
{
return $this->shipping->setAddressRequired($addressRequired);
}

public function withParameters($addressRequired)
{
$shipping = new ShippingAddressRequired();
$shipping->setAddressRequired($addressRequired);
$this->shipping->setAddressRequired(
$shipping
);
return $this->shipping;
}
}

0 comments on commit 3c1fa99

Please sign in to comment.