From 5f9a7067904cbcfa0d1cb3d73bac94326ba19fbb Mon Sep 17 00:00:00 2001 From: sixer1182 Date: Tue, 5 Nov 2019 10:12:50 +0100 Subject: [PATCH 1/2] [feature] (PHPLIB-258) HDD: Allow excluding payment types from paypage. --- CHANGELOG.md | 6 +++ src/Resources/AbstractHeidelpayResource.php | 12 +++++- src/Resources/PaymentTypes/Paypage.php | 41 +++++++++++++++++++ test/integration/PaymentTypes/PaypageTest.php | 3 ++ .../Resources/PaymentTypes/PayPageTest.php | 14 ++++++- 5 files changed, 74 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28da3b5c..7bfc2a01 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [1.2.4.0][1.2.4.0] + +### Added +* It is now possible to exclude payment types from the Paypage. + ## [1.2.3.0][1.2.3.0] ### Added @@ -299,3 +304,4 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a [1.2.1.0]: https://github.com/heidelpay/heidelpayPHP/compare/1.2.0.0..1.2.1.0 [1.2.2.0]: https://github.com/heidelpay/heidelpayPHP/compare/1.2.1.0..1.2.2.0 [1.2.3.0]: https://github.com/heidelpay/heidelpayPHP/compare/1.2.2.0..1.2.3.0 +[1.2.4.0]: https://github.com/heidelpay/heidelpayPHP/compare/1.2.3.0..1.2.4.0 diff --git a/src/Resources/AbstractHeidelpayResource.php b/src/Resources/AbstractHeidelpayResource.php index 1a743056..ef969e89 100755 --- a/src/Resources/AbstractHeidelpayResource.php +++ b/src/Resources/AbstractHeidelpayResource.php @@ -53,6 +53,16 @@ abstract class AbstractHeidelpayResource implements HeidelpayParentInterface // + /** + * Returns the API name of the resource. + * + * @return string + */ + public static function getResourceName(): string + { + return ResourceNameService::getClassShortNameKebapCase(static::class); + } + /** * Returns the id of this resource. * @@ -360,7 +370,7 @@ public function getLinkedResources(): array */ protected function getResourcePath(): string { - return ResourceNameService::getClassShortNameKebapCase(static::class); + return self::getResourceName(); } /** diff --git a/src/Resources/PaymentTypes/Paypage.php b/src/Resources/PaymentTypes/Paypage.php index 7feb3234..bd2361bd 100644 --- a/src/Resources/PaymentTypes/Paypage.php +++ b/src/Resources/PaymentTypes/Paypage.php @@ -92,6 +92,9 @@ class Paypage extends BasePaymentType /** @var Payment|null $payment */ private $payment; + /** @var string[] $excludeTypes */ + protected $excludeTypes = []; + /** * Paypage constructor. * @@ -469,6 +472,44 @@ public function getPaymentId() return null; } + /** + * Returns an array of payment types not shown on the paypage. + * + * @return string[] + */ + public function getExcludeTypes(): array + { + return $this->excludeTypes; + } + + /** + * Sets array of payment types not shown on the paypage. + * + * @param string[] $excludeTypes + * + * @return Paypage + */ + public function setExcludeTypes(array $excludeTypes): Paypage + { + $this->excludeTypes = $excludeTypes; + return $this; + } + + /** + * Adds a payment type to the array of excluded payment types. + * + * @param string $excludeType The API name of the payment type resource that should not be shown on the paypage. + * It can be retrieved by calling the static function `getResourceName` on the payment + * type class e.g. Card::getResourceName(). + * + * @return Paypage + */ + public function addExcludeType(string $excludeType): Paypage + { + $this->excludeTypes[] = $excludeType; + return $this; + } + // // diff --git a/test/integration/PaymentTypes/PaypageTest.php b/test/integration/PaymentTypes/PaypageTest.php index 024988b1..0c743bcc 100644 --- a/test/integration/PaymentTypes/PaypageTest.php +++ b/test/integration/PaymentTypes/PaypageTest.php @@ -27,6 +27,7 @@ use heidelpayPHP\Exceptions\HeidelpayApiException; use heidelpayPHP\Resources\CustomerFactory; use heidelpayPHP\Resources\Payment; +use heidelpayPHP\Resources\PaymentTypes\Card; use heidelpayPHP\Resources\PaymentTypes\Paypage; use heidelpayPHP\test\BasePaymentTest; use PHPUnit\Framework\AssertionFailedError; @@ -133,9 +134,11 @@ public function maximumPaypageAuthorizeShouldBeCreatable() ->setHelpUrl('https://www.heidelpay.com/at/') ->setContactUrl('https://www.heidelpay.com/en/about-us/about-heidelpay/') ->setInvoiceId($invoiceId); + $paypage->addExcludeType(Card::getResourceName()); $this->assertEmpty($paypage->getId()); $paypage = $this->heidelpay->initPayPageAuthorize($paypage, $customer, $basket); $this->assertNotEmpty($paypage->getId()); + $this->assertArraySubset([Card::getResourceName()], $paypage->getExcludeTypes()); $payment = $paypage->getPayment(); $this->assertInstanceOf(Payment::class, $payment); $this->assertNotNull($payment->getId()); diff --git a/test/unit/Resources/PaymentTypes/PayPageTest.php b/test/unit/Resources/PaymentTypes/PayPageTest.php index b3746ed0..8bbcee0f 100644 --- a/test/unit/Resources/PaymentTypes/PayPageTest.php +++ b/test/unit/Resources/PaymentTypes/PayPageTest.php @@ -31,7 +31,10 @@ use heidelpayPHP\Resources\Customer; use heidelpayPHP\Resources\Metadata; use heidelpayPHP\Resources\Payment; +use heidelpayPHP\Resources\PaymentTypes\Card; +use heidelpayPHP\Resources\PaymentTypes\Giropay; use heidelpayPHP\Resources\PaymentTypes\Paypage; +use heidelpayPHP\Resources\PaymentTypes\SepaDirectDebit; use heidelpayPHP\Services\ResourceService; use heidelpayPHP\test\BasePaymentTest; use PHPUnit\Framework\Exception; @@ -79,6 +82,9 @@ public function getterAndSetterWorkAsExpected() $this->assertNull($paypage->getPrivacyPolicyUrl()); $this->assertNull($paypage->getTermsAndConditionUrl()); + // other + $this->assertCount(0, $paypage->getExcludeTypes()); + // ----------- SET test values ------------ $payment = (new Payment())->setId('my payment id'); $paypage @@ -97,7 +103,8 @@ public function getterAndSetterWorkAsExpected() ->setPrivacyPolicyUrl('my privacy policy url') ->setTermsAndConditionUrl('my tac url') ->setPayment($payment) - ->setRedirectUrl('https://redirect.url'); + ->setRedirectUrl('https://redirect.url') + ->addExcludeType(SepaDirectDebit::getResourceName()); // ----------- VERIFY test values ------------ $this->assertEquals(321.0, $paypage->getAmount()); @@ -123,6 +130,11 @@ public function getterAndSetterWorkAsExpected() $this->assertEquals('my imprint url', $paypage->getImprintUrl()); $this->assertEquals('my privacy policy url', $paypage->getPrivacyPolicyUrl()); $this->assertEquals('my tac url', $paypage->getTermsAndConditionUrl()); + + // other + $this->assertArraySubset([SepaDirectDebit::getResourceName()], $paypage->getExcludeTypes()); + $paypage->setExcludeTypes([Card::getResourceName(), Giropay::getResourceName()]); + $this->assertArraySubset([Card::getResourceName(), Giropay::getResourceName()], $paypage->getExcludeTypes()); } /** From 9cfc29858ba3ff0b20c8592284ecf72d38ed5a8f Mon Sep 17 00:00:00 2001 From: sixer1182 Date: Tue, 5 Nov 2019 10:22:01 +0100 Subject: [PATCH 2/2] [feature] (PHPLIB-258) HDD: Fix test. --- test/unit/Resources/PaymentTypes/PayPageTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/unit/Resources/PaymentTypes/PayPageTest.php b/test/unit/Resources/PaymentTypes/PayPageTest.php index 8bbcee0f..a10c1a94 100644 --- a/test/unit/Resources/PaymentTypes/PayPageTest.php +++ b/test/unit/Resources/PaymentTypes/PayPageTest.php @@ -366,7 +366,8 @@ public function exposeShouldSetBasicParams() 'privacyPolicyUrl' => 'my privacy policy url', 'termsAndConditionUrl' => 'my tac url', 'orderId' => 'my order id', - 'invoiceId' => 'my invoice id' + 'invoiceId' => 'my invoice id', + 'excludeTypes' => [] ]; $this->assertEquals($expected, $paypage->expose()); }