From 713ef007e137b4b80955693f614773fd647ea3dc Mon Sep 17 00:00:00 2001 From: sixer1182 Date: Mon, 22 Feb 2021 16:02:48 +0100 Subject: [PATCH 1/2] Add integration tests for instalment cancel after shipment. --- CHANGELOG.md | 3 + .../PaymentTypes/InstallmentSecuredTest.php | 71 +++++++++++++++++-- 2 files changed, 70 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6798f765..cc669337 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a * Change debug logging of failed tests that depend on another one to work as expected. * Several minor changes. +### Added +* Extended testing for Instalment payment type. + ## [1.1.1.0] ### Changed diff --git a/test/integration/PaymentTypes/InstallmentSecuredTest.php b/test/integration/PaymentTypes/InstallmentSecuredTest.php index 72152aa3..15e43147 100644 --- a/test/integration/PaymentTypes/InstallmentSecuredTest.php +++ b/test/integration/PaymentTypes/InstallmentSecuredTest.php @@ -29,6 +29,7 @@ use UnzerSDK\Constants\ApiResponseCodes; use UnzerSDK\Exceptions\UnzerApiException; +use UnzerSDK\Resources\AbstractUnzerResource; use UnzerSDK\Resources\Customer; use UnzerSDK\Resources\CustomerFactory; use UnzerSDK\Resources\EmbeddedResources\Address; @@ -81,7 +82,7 @@ public function instalmentPlanShouldBeSelectable(): void * * @test */ - public function hddTypeShouldBeFechable(): InstallmentSecured + public function hddTypeShouldBeFetchable(): InstallmentSecured { // Mock a hdd Type $date = $this->getTodaysDateString(); @@ -130,17 +131,18 @@ public function hddTypeShouldBeFechable(): InstallmentSecured * Verify fetched hdd type can be authorized and charged * * @test - * @depends hddTypeShouldBeFechable + * @depends hddTypeShouldBeFetchable * - * @param InvoiceSecured $hddType fetched ins type. + * @param InstallmentSecured $hddType fetched ins type. * + * @return AbstractUnzerResource|Charge * @throws UnzerApiException */ public function hddTypeAuthorizeAndCharge(InstallmentSecured $hddType) { $customer = $this->getMaximumCustomer(); $basket = $this->createBasket(); - /** @var Authorization $auth */ + $auth = $hddType->authorize(119.00, 'EUR', 'https://unzer.com', $customer, null, null, $basket); $charge = $auth->getPayment()->charge(); $this->assertNotNull($auth); @@ -320,6 +322,67 @@ public function verifyPartlyCancelChargedInstallmentSecured(): void $this->assertTrue($payment->isCompleted()); } + /** + * Verify full cancel of charged HP after shipment. + * + * @test + * + * @depends verifyChargingAnInitializedInstallmentSecured + */ + public function verifyChargeAndFullCancelAnInitializedInstallmentSecuredAfterShipment(): void + { + $yesterday = $this->getYesterdaysTimestamp(); + $plans = $this->unzer->fetchInstallmentPlans(119.0, 'EUR', 4.99, $yesterday); + $this->assertGreaterThan(0, count($plans->getPlans())); + + /** @var InstalmentPlan $selectedPlan */ + $selectedPlan = $plans->getPlans()[0]; + $ins = new InstallmentSecured($selectedPlan, 'DE46940594210000012345', 'Manuel Weißmann', $yesterday, 'COBADEFFXXX', $yesterday, $this->getTomorrowsTimestamp()); + $this->unzer->createPaymentType($ins); + + $authorize = $ins->authorize(119.0, 'EUR', self::RETURN_URL, $this->getCustomer(), null, null, $basket = $this->createBasket()); + $payment = $authorize->getPayment(); + + $hddCharge = $payment->charge(); + $invoiceId = 'i' . self::generateRandomId(); + $ship = $this->unzer->ship($hddCharge->getPayment(), $invoiceId); + $this->assertNotNull($ship); + + $cancel = $payment->cancelAmount(); + $this->assertGreaterThan(0, count($cancel)); + } + + /** + * Verify full cancel of charged HP after shipment. + * + * @test + * + * @depends verifyChargingAnInitializedInstallmentSecured + */ + public function verifyPartlyCancelChargedInstallmentSecuredAfterShipment(): void + { + $yesterday = $this->getYesterdaysTimestamp(); + $plans = $this->unzer->fetchInstallmentPlans(119.0, 'EUR', 4.99, $yesterday); + $this->assertGreaterThan(0, count($plans->getPlans())); + + /** @var InstalmentPlan $selectedPlan */ + $selectedPlan = $plans->getPlans()[0]; + $ins = new InstallmentSecured($selectedPlan, 'DE89370400440532013000', 'Manuel Weißmann', $yesterday, 'COBADEFFXXX', $this->getTodaysDateString(), $this->getTomorrowsTimestamp()); + $this->unzer->createPaymentType($ins); + + $authorize = $ins->authorize(119.0, 'EUR', self::RETURN_URL, $this->getCustomer(), null, null, $basket = $this->createBasket()); + $payment = $authorize->getPayment(); + + $hddCharge = $payment->charge(); + $invoiceId = 'i' . self::generateRandomId(); + $ship = $this->unzer->ship($hddCharge->getPayment(), $invoiceId); + $this->assertNotNull($ship); + + $cancel = $payment->cancelAmount(59.5, null, null, 50.0, 9.5); + $this->assertCount(1, $cancel); + $this->assertTrue($payment->isCompleted()); + } + // // From 01e3b506ff147b9c8ade98aca6bc999395470223 Mon Sep 17 00:00:00 2001 From: sixer1182 Date: Mon, 22 Feb 2021 16:37:28 +0100 Subject: [PATCH 2/2] Add integration tests for instalment cancel after shipment. --- CHANGELOG.md | 3 +++ composer.json | 2 +- test/integration/PaymentTypes/InstallmentSecuredTest.php | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc669337..5ff6f731 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a ### Added * Extended testing for Instalment payment type. +### Changed +* Remove PhpUnit 8 support. + ## [1.1.1.0] ### Changed diff --git a/composer.json b/composer.json index c9927508..56c11db6 100755 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ "ext-json": "*" }, "require-dev": { - "phpunit/phpunit": ">6.5 <9.0", + "phpunit/phpunit": ">6.5 <8.0", "friendsofphp/php-cs-fixer": "^2.0" }, "suggest": { diff --git a/test/integration/PaymentTypes/InstallmentSecuredTest.php b/test/integration/PaymentTypes/InstallmentSecuredTest.php index 15e43147..c074cc3a 100644 --- a/test/integration/PaymentTypes/InstallmentSecuredTest.php +++ b/test/integration/PaymentTypes/InstallmentSecuredTest.php @@ -337,7 +337,7 @@ public function verifyChargeAndFullCancelAnInitializedInstallmentSecuredAfterShi /** @var InstalmentPlan $selectedPlan */ $selectedPlan = $plans->getPlans()[0]; - $ins = new InstallmentSecured($selectedPlan, 'DE46940594210000012345', 'Manuel Weißmann', $yesterday, 'COBADEFFXXX', $yesterday, $this->getTomorrowsTimestamp()); + $ins = new InstallmentSecured($selectedPlan, 'DE89370400440532013000', 'Manuel Weißmann', $yesterday, 'COBADEFFXXX', $this->getTodaysDateString(), $this->getTomorrowsTimestamp()); $this->unzer->createPaymentType($ins); $authorize = $ins->authorize(119.0, 'EUR', self::RETURN_URL, $this->getCustomer(), null, null, $basket = $this->createBasket());