From 861ab3a55fcbf7db4932af4e3fde23bdf4a4a21f Mon Sep 17 00:00:00 2001 From: juanjomb Date: Thu, 28 Jan 2021 12:27:51 +0100 Subject: [PATCH 1/2] Add extra data in paylands --- .gitignore | 1 + composer.json | 2 +- .../Exception/InvalidValueException.php | 30 ++++ .../Services/ExtraDataBuilder.php | 60 ++++++++ .../ExtraDataBuilderAwareInterface.php | 10 ++ .../Services/PaylandsApiAdapter.php | 10 +- .../Tests/Services/ExtraDataBuilderTest.php | 82 +++++++++++ .../PaylandsBundle/Util/Address.php | 79 ++++++++++ .../PaylandsBundle/Util/CountryCode.php | 54 +++++++ .../Util/DocumentIdentificationIssuerType.php | 44 ++++++ .../Util/DocumentIdentificationType.php | 58 ++++++++ .../PaylandsBundle/Util/ExtraData.php | 53 +++++++ .../Util/Interfaces/ArrayableInterface.php | 12 ++ .../PaylandsBundle/Util/Phone.php | 35 +++++ .../PaylandsBundle/Util/Profile.php | 135 ++++++++++++++++++ 15 files changed, 662 insertions(+), 3 deletions(-) create mode 100644 src/PaymentSuite/PaylandsBundle/Exception/InvalidValueException.php create mode 100644 src/PaymentSuite/PaylandsBundle/Services/ExtraDataBuilder.php create mode 100644 src/PaymentSuite/PaylandsBundle/Services/Interfaces/ExtraDataBuilderAwareInterface.php create mode 100644 src/PaymentSuite/PaylandsBundle/Tests/Services/ExtraDataBuilderTest.php create mode 100644 src/PaymentSuite/PaylandsBundle/Util/Address.php create mode 100644 src/PaymentSuite/PaylandsBundle/Util/CountryCode.php create mode 100644 src/PaymentSuite/PaylandsBundle/Util/DocumentIdentificationIssuerType.php create mode 100644 src/PaymentSuite/PaylandsBundle/Util/DocumentIdentificationType.php create mode 100644 src/PaymentSuite/PaylandsBundle/Util/ExtraData.php create mode 100644 src/PaymentSuite/PaylandsBundle/Util/Interfaces/ArrayableInterface.php create mode 100644 src/PaymentSuite/PaylandsBundle/Util/Phone.php create mode 100644 src/PaymentSuite/PaylandsBundle/Util/Profile.php diff --git a/.gitignore b/.gitignore index a03e2f3..32876d8 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ composer.lock phpunit.xml **/Tests/app/cache/ **/var/cache/ +.idea diff --git a/composer.json b/composer.json index 1c6dd4d..866de28 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,7 @@ "twig/twig": "^2.11", "stripe/stripe-php": "3.4.0", "monolog/monolog": "^1.17", - "wearemarketing/paylands-php": "0.1.*", + "wearemarketing/paylands-php": "0.2.*", "endelwar/gestpayws": "^1.4", "symfony/expression-language": "^4.3", "symfony/templating": "^4.3", diff --git a/src/PaymentSuite/PaylandsBundle/Exception/InvalidValueException.php b/src/PaymentSuite/PaylandsBundle/Exception/InvalidValueException.php new file mode 100644 index 0000000..ccab5b4 --- /dev/null +++ b/src/PaymentSuite/PaylandsBundle/Exception/InvalidValueException.php @@ -0,0 +1,30 @@ + + */ + +namespace PaymentSuite\PaylandsBundle\Exception; + +use PaymentSuite\PaymentCoreBundle\Exception\PaymentException; + +/** + * Class InvalidValueException + * @author Juanjo Martínez + */ +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)); + } +} diff --git a/src/PaymentSuite/PaylandsBundle/Services/ExtraDataBuilder.php b/src/PaymentSuite/PaylandsBundle/Services/ExtraDataBuilder.php new file mode 100644 index 0000000..51f6efc --- /dev/null +++ b/src/PaymentSuite/PaylandsBundle/Services/ExtraDataBuilder.php @@ -0,0 +1,60 @@ + + */ +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 + ); + } +} diff --git a/src/PaymentSuite/PaylandsBundle/Services/Interfaces/ExtraDataBuilderAwareInterface.php b/src/PaymentSuite/PaylandsBundle/Services/Interfaces/ExtraDataBuilderAwareInterface.php new file mode 100644 index 0000000..f08b139 --- /dev/null +++ b/src/PaymentSuite/PaylandsBundle/Services/Interfaces/ExtraDataBuilderAwareInterface.php @@ -0,0 +1,10 @@ +paymentBridge instanceof ExtraDataBuilderAwareInterface + ? $this->paymentBridge->buildExtraData()->toArray() + : []; + $paymentOrder = $this->client->createPayment( $paymentMethod->getCustomerExternalId(), $this->paymentBridge->getAmount(), (string)$this->paymentBridge->getOrder(), - $this->currencyServiceResolver->getService() + $this->currencyServiceResolver->getService(), + $extraData ); $transaction = $this->client->directPayment( @@ -117,4 +123,4 @@ public function validateCard(PaylandsMethod $paymentMethod) $paymentMethod->getCustomerExternalId() )); } -} \ No newline at end of file +} diff --git a/src/PaymentSuite/PaylandsBundle/Tests/Services/ExtraDataBuilderTest.php b/src/PaymentSuite/PaylandsBundle/Tests/Services/ExtraDataBuilderTest.php new file mode 100644 index 0000000..fabab28 --- /dev/null +++ b/src/PaymentSuite/PaylandsBundle/Tests/Services/ExtraDataBuilderTest.php @@ -0,0 +1,82 @@ + + */ + +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 + */ +class ExtraDataBuilderTest extends TestCase +{ + public function testBuildWithProfile() + { + $builder = new ExtraDataBuilder(); + + $extraData = $builder->withProfile( + Profile::create( + 'John', + 'Doe', + 'John Doe', + 'invent@mail.com', + 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('invent@mail.com', $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'], + ]; + } +} diff --git a/src/PaymentSuite/PaylandsBundle/Util/Address.php b/src/PaymentSuite/PaylandsBundle/Util/Address.php new file mode 100644 index 0000000..bbfebe5 --- /dev/null +++ b/src/PaymentSuite/PaylandsBundle/Util/Address.php @@ -0,0 +1,79 @@ + + */ +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, + ]); + } +} diff --git a/src/PaymentSuite/PaylandsBundle/Util/CountryCode.php b/src/PaymentSuite/PaylandsBundle/Util/CountryCode.php new file mode 100644 index 0000000..f7dc89e --- /dev/null +++ b/src/PaymentSuite/PaylandsBundle/Util/CountryCode.php @@ -0,0 +1,54 @@ + + */ +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; + } +} diff --git a/src/PaymentSuite/PaylandsBundle/Util/DocumentIdentificationIssuerType.php b/src/PaymentSuite/PaylandsBundle/Util/DocumentIdentificationIssuerType.php new file mode 100644 index 0000000..0ce5701 --- /dev/null +++ b/src/PaymentSuite/PaylandsBundle/Util/DocumentIdentificationIssuerType.php @@ -0,0 +1,44 @@ + + */ +final class DocumentIdentificationIssuerType +{ + const OPTIONS = [ + 'STATE_GOVERNMENT', + 'FEDERAL_GOVERNMENT', + 'MONEY_TRANSMITTER', + 'PROFESSIONAL_ASSOCIATION', + ]; + + private $value; + + /** + * DocumentIdentificationIssuerType constructor. + * @param $value + */ + private function __construct($value) + { + $this->value = $value; + } + + public static function create(string $value): self + { + if(!in_array($value, self::OPTIONS)){ + throw new InvalidValueException(self::class, $value); + } + + return new self($value); + } + + public function __toString() + { + return $this->value; + } +} diff --git a/src/PaymentSuite/PaylandsBundle/Util/DocumentIdentificationType.php b/src/PaymentSuite/PaylandsBundle/Util/DocumentIdentificationType.php new file mode 100644 index 0000000..8ea9fc8 --- /dev/null +++ b/src/PaymentSuite/PaylandsBundle/Util/DocumentIdentificationType.php @@ -0,0 +1,58 @@ + + */ +final class DocumentIdentificationType +{ + const OPTIONS = [ + 'ALIEN_REGISTRATION_CARD', + 'ELECTOR_CREDENTIAL', + 'FISCAL_IDENTIFICATION_CODE', + 'ORIGIN_COUNTRY_IDENTIFICATION_CODE', + 'FOREIGN_IDENTIFICATION_DOCUMENT', + 'NATIONAL_IDENTITY_DOCUMENT', + 'OTHER_PHYSICAL_PERSON_DOCUMENTS', + 'DRIVER_LICENSE', + 'CONSULAR_REGISTRATION', + 'UNDER_AGE', + 'RESIDENCE_CARD', + 'TAX_IDENTIFICATION_NUMBER', + 'NON_DRIVER_LICENSE_PHOTO_ID', + 'VALID_PASSPORT', + 'DIPLOMAT_IDENTITY_CARD', + 'US_GOVERNMENT_ISSUER_ID', + 'UNIQUE_ID_ISSUED_BY_MT', + 'NATIONAL_IDENTITY_DOCUMENT' + ]; + + private $value; + + /** + * DocumentIdentificationIssuerType constructor. + * @param $value + */ + private function __construct($value) + { + $this->value = $value; + } + + public static function create(string $value): self + { + if(!in_array($value, self::OPTIONS)){ + throw new InvalidValueException(self::class, $value); + } + + return new self($value); + } + + public function __toString() + { + return $this->value; + } +} diff --git a/src/PaymentSuite/PaylandsBundle/Util/ExtraData.php b/src/PaymentSuite/PaylandsBundle/Util/ExtraData.php new file mode 100644 index 0000000..fc021c5 --- /dev/null +++ b/src/PaymentSuite/PaylandsBundle/Util/ExtraData.php @@ -0,0 +1,53 @@ + + */ +final class ExtraData implements ArrayableInterface +{ + private $profile; + + private $address; + + private $shippingAddress; + + private $billingAddress; + + private function __construct( + Profile $profile = null, + Address $address = null, + Address $shippingAddress = null, + Address $billingAddress = null + ) + { + $this->profile = $profile; + $this->address = $address; + $this->shippingAddress = $shippingAddress; + $this->billingAddress = $billingAddress; + } + + public static function create( + Profile $profile = null, + Address $address = null, + Address $shippingAddress = null, + Address $billingAddress = null + ): self + { + return new self($profile, $address, $shippingAddress, $billingAddress); + } + + public function toArray(): array + { + return array_filter([ + 'profile' => $this->profile ? $this->profile->toArray() : [], + 'address' => $this->address ? $this->address->toArray() : [], + 'shipping_address' => $this->shippingAddress ? $this->shippingAddress->toArray() : [], + 'billing_address' => $this->billingAddress ? $this->billingAddress->toArray() : [], + ]); + } +} diff --git a/src/PaymentSuite/PaylandsBundle/Util/Interfaces/ArrayableInterface.php b/src/PaymentSuite/PaylandsBundle/Util/Interfaces/ArrayableInterface.php new file mode 100644 index 0000000..b3d1ca0 --- /dev/null +++ b/src/PaymentSuite/PaylandsBundle/Util/Interfaces/ArrayableInterface.php @@ -0,0 +1,12 @@ + + */ +interface ArrayableInterface +{ + public function toArray(): array; +} diff --git a/src/PaymentSuite/PaylandsBundle/Util/Phone.php b/src/PaymentSuite/PaylandsBundle/Util/Phone.php new file mode 100644 index 0000000..80f18b1 --- /dev/null +++ b/src/PaymentSuite/PaylandsBundle/Util/Phone.php @@ -0,0 +1,35 @@ + + */ +final class Phone implements ArrayableInterface +{ + private $number; + + private $prefix; + + private function __construct(string $number, string $prefix = null) + { + $this->number = $number; + $this->prefix = $prefix; + } + + public static function create(string $number, string $prefix = null): self + { + return new self($number, $prefix); + } + + public function toArray(): array + { + return array_filter([ + 'number' => $this->number, + 'prefix' => $this->prefix, + ]); + } +} diff --git a/src/PaymentSuite/PaylandsBundle/Util/Profile.php b/src/PaymentSuite/PaylandsBundle/Util/Profile.php new file mode 100644 index 0000000..f3da3d4 --- /dev/null +++ b/src/PaymentSuite/PaylandsBundle/Util/Profile.php @@ -0,0 +1,135 @@ + + */ +final class Profile implements ArrayableInterface +{ + private $firstName; + + private $lastName; + + private $cardholderName; + + private $email; + + private $documentIdentificationIssuerType; + + private $documentIdentificationType; + + private $documentIdentificationNumber; + + private $birthdate; + + private $sourceOfFunds; + + private $occupation; + + private $socialSecurityNumber; + + private $phone; + + private $workPhone; + + private $homePhone; + + private $mobilePhone; + + private function __construct( + string $firstName, + string $lastName, + string $cardholderName = null, + string $email = null, + DocumentIdentificationIssuerType $documentIdentificationIssuerType = null, + DocumentIdentificationType $documentIdentificationType = null, + string $documentIdentificationNumber = null, + \DateTime $birthdate = null, + string $sourceOfFunds = null, + string $occupation = null, + string $socialSecurityNumber = null, + Phone $phone = null, + Phone $workPhone = null, + Phone $homePhone = null, + Phone $mobilePhone = null + ) + { + $this->firstName = $firstName; + $this->lastName = $lastName; + $this->cardholderName = $cardholderName; + $this->email = $email; + $this->documentIdentificationIssuerType = $documentIdentificationIssuerType; + $this->documentIdentificationType = $documentIdentificationType; + $this->documentIdentificationNumber = $documentIdentificationNumber; + $this->birthdate = $birthdate; + $this->sourceOfFunds = $sourceOfFunds; + $this->occupation = $occupation; + $this->socialSecurityNumber = $socialSecurityNumber; + $this->phone = $phone; + $this->workPhone = $workPhone; + $this->homePhone = $homePhone; + $this->mobilePhone = $mobilePhone; + } + + public static function create( + string $firstName, + string $lastName, + string $cardholderName = null, + string $email = null, + DocumentIdentificationIssuerType $documentIdentificationIssuerType = null, + DocumentIdentificationType $documentIdentificationType = null, + string $documentIdentificationNumber = null, + \DateTime $birthdate = null, + string $sourceOfFunds = null, + string $occupation = null, + string $socialSecurityNumber = null, + Phone $phone = null, + Phone $workPhone = null, + Phone $homePhone = null, + Phone $mobilePhone = null + ): self + { + + return new self( + $firstName, + $lastName, + $cardholderName, + $email, + $documentIdentificationIssuerType, + $documentIdentificationType, + $documentIdentificationNumber, $birthdate, + $sourceOfFunds, + $occupation, + $socialSecurityNumber, + $phone, + $workPhone, + $homePhone, + $mobilePhone + ); + } + + public function toArray(): array + { + return array_filter([ + 'first_name' => $this->firstName, + 'last_name' => $this->lastName, + 'cardholder_name' => $this->cardholderName, + 'email' => $this->email, + 'document_identification_issuer_type' => (string) $this->documentIdentificationIssuerType, + 'document_identification_type' => (string) $this->documentIdentificationType, + 'document_identification_number' => $this->documentIdentificationNumber, + 'birthdate' => $this->birthdate ? $this->birthdate->format('Y-m-d') : $this->birthdate, + 'source_of_funds' => $this->sourceOfFunds, + 'occupation' => $this->occupation, + 'social_security_number' => $this->socialSecurityNumber, + 'phone' => $this->phone ? $this->phone->toArray() : null, + 'work_phone' => $this->workPhone ? $this->workPhone->toArray() : null, + 'home_phone' => $this->homePhone ? $this->homePhone->toArray() : null, + 'mobile_phone' => $this->mobilePhone ? $this->mobilePhone->toArray() : null, + ]); + } +} From 417854dd8d9951d9b1376bba811ae0ec569ce638 Mon Sep 17 00:00:00 2001 From: juanjomb Date: Thu, 28 Jan 2021 15:41:37 +0100 Subject: [PATCH 2/2] Fix redsys psd2 builder test --- .../Services/Redsys3dSecureBuilderTest.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/PaymentSuite/RedsysBundle/Tests/Services/Redsys3dSecureBuilderTest.php b/src/PaymentSuite/RedsysBundle/Tests/Services/Redsys3dSecureBuilderTest.php index 83b05eb..a62b568 100644 --- a/src/PaymentSuite/RedsysBundle/Tests/Services/Redsys3dSecureBuilderTest.php +++ b/src/PaymentSuite/RedsysBundle/Tests/Services/Redsys3dSecureBuilderTest.php @@ -303,16 +303,16 @@ public function testAddLastPasswordChangeDateNullDate() * @param string|null $changeDate * @param string|null $expected */ - public function testLastPasswordChangeIndicator(?string $authDate, ?string $changeDate, ?string $expected) + public function testLastPasswordChangeIndicator(?\DateTime $authDate, ?\DateTime $changeDate, ?string $expected) { $builder = new Redsys3dSecureBuilder(); if (!is_null($authDate)) { - $builder->addAuthenticationDate(\DateTime::createFromFormat('Y-m-d', $authDate)); + $builder->addAuthenticationDate($authDate); } if (!is_null($changeDate)) { - $builder->addLastPasswordChangeDate(\DateTime::createFromFormat('Y-m-d', $changeDate)); + $builder->addLastPasswordChangeDate($changeDate); } $this->assertEquals($expected, $builder->get()['acctInfo']['chAccPwChangeInd'] ?? null); @@ -321,13 +321,13 @@ public function testLastPasswordChangeIndicator(?string $authDate, ?string $chan public function passwordChangeIndicatorProvider() { return [ - 'Changed after date' => ['2020-12-07', '2020-12-08', '02'], - 'Changed on authentication date' => ['2020-12-07', '2020-12-07', '02'], - 'Changed some days ago' => ['2020-12-07', '2020-12-01', '03'], - 'Changed one month ago' => ['2020-12-07', '2020-11-07', '04'], - 'Changed two months ago' => ['2020-12-07', '2020-09-07', '05'], - 'Without change date' => ['2020-12-07', null, null], - 'Without authentication date' => [null, '2020-12-07', '03'], + 'Changed after date' => [new \DateTime('- 1 day'), new \DateTime('today'), '02'], + 'Changed on authentication date' => [new \DateTime('today'), new \DateTime('today'), '02'], + 'Changed some days ago' => [new \DateTime('today'), new \DateTime('- 6 days'), '03'], + 'Changed one month ago' => [new \DateTime('today'), new \DateTime('- 1 month'), '04'], + 'Changed two months ago' => [new \DateTime('today'), new \DateTime('- 3 months'), '05'], + 'Without change date' => [new \DateTime('today'), null, null], + 'Without authentication date' => [null, new \DateTime('today'), '03'], ]; }