-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from PaymentSuite/feature/extra-data
Add extra data in paylands
- Loading branch information
Showing
16 changed files
with
672 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ composer.lock | |
phpunit.xml | ||
**/Tests/app/cache/ | ||
**/var/cache/ | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/PaymentSuite/PaylandsBundle/Exception/InvalidValueException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the PaymentSuite package. | ||
* | ||
* Copyright (c) 2013-2016 Marc Morera | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* Feel free to edit as you please, and have fun. | ||
* | ||
* @author Marc Morera <[email protected]> | ||
*/ | ||
|
||
namespace PaymentSuite\PaylandsBundle\Exception; | ||
|
||
use PaymentSuite\PaymentCoreBundle\Exception\PaymentException; | ||
|
||
/** | ||
* Class InvalidValueException | ||
* @author Juanjo Martínez <[email protected]> | ||
*/ | ||
class InvalidValueException extends \InvalidArgumentException | ||
{ | ||
public static function create(string $class, string $value): self | ||
{ | ||
return new self(sprintf('%s is not a valid value for %s', $value, $class)); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/PaymentSuite/PaylandsBundle/Services/ExtraDataBuilder.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
|
||
namespace PaymentSuite\PaylandsBundle\Services; | ||
|
||
use PaymentSuite\PaylandsBundle\Util\Address; | ||
use PaymentSuite\PaylandsBundle\Util\ExtraData; | ||
use PaymentSuite\PaylandsBundle\Util\Profile; | ||
|
||
/** | ||
* @author Juanjo Martínez <[email protected]> | ||
*/ | ||
final class ExtraDataBuilder | ||
{ | ||
private $profile; | ||
|
||
private $address; | ||
|
||
private $shippingAddress; | ||
|
||
private $billingAddress; | ||
|
||
public function withProfile(Profile $profile): self | ||
{ | ||
$this->profile = $profile; | ||
|
||
return $this; | ||
} | ||
|
||
public function withAddress(Address $address): self | ||
{ | ||
$this->address = $address; | ||
|
||
return $this; | ||
} | ||
|
||
public function withShippingAddress(Address $address): self | ||
{ | ||
$this->shippingAddress = $address; | ||
|
||
return $this; | ||
} | ||
|
||
public function withBillingAddress(Address $address): self | ||
{ | ||
$this->billingAddress = $address; | ||
|
||
return $this; | ||
} | ||
|
||
public function build(): ExtraData | ||
{ | ||
return ExtraData::create( | ||
$this->profile, | ||
$this->address, | ||
$this->shippingAddress, | ||
$this->billingAddress | ||
); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/PaymentSuite/PaylandsBundle/Services/Interfaces/ExtraDataBuilderAwareInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace PaymentSuite\PaylandsBundle\Services\Interfaces; | ||
|
||
use PaymentSuite\PaylandsBundle\Util\ExtraData; | ||
|
||
interface ExtraDataBuilderAwareInterface | ||
{ | ||
public function buildExtraData(): ExtraData; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
src/PaymentSuite/PaylandsBundle/Tests/Services/ExtraDataBuilderTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the PaymentSuite package. | ||
* | ||
* Copyright (c) 2013-2016 Marc Morera | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* Feel free to edit as you please, and have fun. | ||
* | ||
* @author Marc Morera <[email protected]> | ||
*/ | ||
|
||
namespace PaymentSuite\PaylandsBundle\Tests\Services; | ||
|
||
use PaymentSuite\PaylandsBundle\Services\ExtraDataBuilder; | ||
use PaymentSuite\PaylandsBundle\Util\Address; | ||
use PaymentSuite\PaylandsBundle\Util\CountryCode; | ||
use PaymentSuite\PaylandsBundle\Util\DocumentIdentificationIssuerType; | ||
use PaymentSuite\PaylandsBundle\Util\DocumentIdentificationType; | ||
use PaymentSuite\PaylandsBundle\Util\Profile; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Class PaylandsCurrencyServiceResolverTest. | ||
* | ||
* @author WAM Team <[email protected]> | ||
*/ | ||
class ExtraDataBuilderTest extends TestCase | ||
{ | ||
public function testBuildWithProfile() | ||
{ | ||
$builder = new ExtraDataBuilder(); | ||
|
||
$extraData = $builder->withProfile( | ||
Profile::create( | ||
'John', | ||
'Doe', | ||
'John Doe', | ||
'[email protected]', | ||
DocumentIdentificationIssuerType::create('STATE_GOVERNMENT'), | ||
DocumentIdentificationType::create('RESIDENCE_CARD') | ||
) | ||
)->build(); | ||
|
||
$this->assertCount(1, $extraData->toArray()); | ||
$this->assertEquals('John', $extraData->toArray()['profile']['first_name']); | ||
$this->assertEquals('Doe', $extraData->toArray()['profile']['last_name']); | ||
$this->assertEquals('John Doe', $extraData->toArray()['profile']['cardholder_name']); | ||
$this->assertEquals('[email protected]', $extraData->toArray()['profile']['email']); | ||
$this->assertEquals('STATE_GOVERNMENT', (string)$extraData->toArray()['profile']['document_identification_issuer_type']); | ||
$this->assertEquals('RESIDENCE_CARD', (string)$extraData->toArray()['profile']['document_identification_type']); | ||
} | ||
|
||
/** | ||
* @dataProvider getAddresses | ||
*/ | ||
public function testBuildWithAddress(string $builderMethod, string $extraDataIndex) | ||
{ | ||
$builder = new ExtraDataBuilder(); | ||
|
||
$extraData = $builder->$builderMethod(Address::create('Valencia', CountryCode::create('ESP'), 'Calle Invent', '46010', 'Valencia'))->build(); | ||
|
||
$this->assertCount(1, $extraData->toArray()); | ||
$this->assertEquals('Valencia', $extraData->toArray()[$extraDataIndex]['city']); | ||
$this->assertEquals('ESP', $extraData->toArray()[$extraDataIndex]['country']); | ||
$this->assertEquals('Calle Invent', $extraData->toArray()[$extraDataIndex]['address1']); | ||
$this->assertEquals('46010', $extraData->toArray()[$extraDataIndex]['zip_code']); | ||
$this->assertEquals('Valencia', $extraData->toArray()[$extraDataIndex]['state_code']); | ||
} | ||
|
||
public function getAddresses() | ||
{ | ||
return [ | ||
'Simple address' => ['withAddress', 'address'], | ||
'Shipping address' => ['withShippingAddress', 'shipping_address'], | ||
'Billing address' => ['withBillingAddress', 'billing_address'], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
|
||
namespace PaymentSuite\PaylandsBundle\Util; | ||
|
||
use PaymentSuite\PaylandsBundle\Util\Interfaces\ArrayableInterface; | ||
|
||
/** | ||
* @author Juanjo Martínez <[email protected]> | ||
*/ | ||
final class Address implements ArrayableInterface | ||
{ | ||
private $city; | ||
|
||
private $country; | ||
|
||
private $address1; | ||
|
||
private $address2; | ||
|
||
private $address3; | ||
|
||
private $zipCode; | ||
|
||
private $stateCode; | ||
|
||
public function __construct( | ||
string $city, | ||
CountryCode $country, | ||
string $address1, | ||
string $zipCode, | ||
string $stateCode, | ||
string $address2 = null, | ||
string $address3 = null | ||
) | ||
{ | ||
$this->city = $city; | ||
$this->country = $country; | ||
$this->address1 = $address1; | ||
$this->zipCode = $zipCode; | ||
$this->stateCode = $stateCode; | ||
$this->address2 = $address2; | ||
$this->address3 = $address3; | ||
} | ||
|
||
public static function create( | ||
string $city, | ||
CountryCode $country, | ||
string $address1, | ||
string $zipCode, | ||
string $stateCode, | ||
string $address2 = null, | ||
string $address3 = null | ||
): self | ||
{ | ||
return new self( | ||
$city, | ||
$country, | ||
$address1, | ||
$zipCode, | ||
$stateCode, | ||
$address2, | ||
$address3 | ||
); | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
return array_filter([ | ||
'city' => $this->city, | ||
'country' => (string) $this->country, | ||
'address1' => $this->address1, | ||
'zip_code' => $this->zipCode, | ||
'state_code' => $this->stateCode, | ||
'address2' => $this->address2, | ||
'address3' => $this->address3, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace PaymentSuite\PaylandsBundle\Util; | ||
|
||
use PaymentSuite\PaylandsBundle\Exception\InvalidValueException; | ||
|
||
/** | ||
* @author Juanjo Martínez <[email protected]> | ||
*/ | ||
final class CountryCode | ||
{ | ||
const COUNTRY_CODES = [ | ||
'ABW','AFG','AGO','AIA','ALA','ALB','AND','ARE','ARG','ARM','ASM','ATA','ATF','ATG','AUS','AUT','AZE','BDI', | ||
'BEL','BEN','BES','BFA','BGD','BGR','BHR','BHS','BIH','BLM','BLR','BLZ','BMU','BOL','BRA','BRB','BRN','BTN', | ||
'BVT','BWA','CAF','CAN','CCK','CHE','CHL','CHN','CIV','CMR','COD','COG','COK','COL','COM','CPV','CRI','CUB', | ||
'CUW','CXR','CYM','CYP','CZE','DEU','DJI','DMA','DNK','DOM','DZA','ECU','EGY','ERI','ESH','ESP','EST','ETH', | ||
'FIN','FJI','FLK','FRA','FRO','FSM','GAB','GBR','GEO','GGY','GHA','GIB','GIN','GLP','GMB','GNB','GNQ','GRC', | ||
'GRD','GRL','GTM','GUF','GUM','GUY','HKG','HMD','HND','HRV','HTI','HUN','IDN','IMN','IND','IOT','IRL','IRN', | ||
'IRQ','ISL','ISR','ITA','JAM','JEY','JOR','JPN','KAZ','KEN','KGZ','KHM','KIR','KNA','KOR','KWT','LAO','LBN', | ||
'LBR','LBY','LCA','LIE','LKA','LSO','LTU','LUX','LVA','MAC','MAF','MAR','MCO','MDA','MDG','MDV','MEX','MHL', | ||
'MKD','MLI','MLT','MMR','MNE','MNG','MNP','MOZ','MRT','MSR','MTQ','MUS','MWI','MYS','MYT','NAM','NCL','NER', | ||
'NFK','NGA','NIC','NIU','NLD','NOR','NPL','NRU','NZL','OMN','PAK','PAN','PCN','PER','PHL','PLW','PNG','POL', | ||
'PRI','PRK','PRT','PRY','PSE','PYF','QAT','REU','ROU','RUS','RWA','SAU','SDN','SEN','SGP','SGS','SHN','SJM', | ||
'SLB','SLE','SLV','SMR','SOM','SPM','SRB','SSD','STP','SUR','SVK','SVN','SWE','SWZ','SXM','SYC','SYR','TCA', | ||
'TCD','TGO','THA','TJK','TKL','TKM','TLS','TON','TTO','TUN','TUR','TUV','TWN','TZA','UGA','UKR','UMI','URY', | ||
'USA','UZB','VAT','VCT','VEN','VGB','VIR','VNM','VUT','WLF','WSM','YEM','ZAF','ZMB','ZWE' | ||
]; | ||
|
||
private $value; | ||
|
||
/** | ||
* CountryCode constructor. | ||
* @param $value | ||
*/ | ||
public function __construct(string $value) | ||
{ | ||
$this->value = $value; | ||
} | ||
|
||
public static function create(string $value): self | ||
{ | ||
if(!in_array($value, self::COUNTRY_CODES)) | ||
{ | ||
throw new InvalidValueException(self::class, $value); | ||
} | ||
|
||
return new self($value); | ||
} | ||
|
||
public function __toString() | ||
{ | ||
return $this->value; | ||
} | ||
} |
Oops, something went wrong.