diff --git a/CHANGELOG.md b/CHANGELOG.md index cbc713cc..847060ec 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,9 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a ## [1.2.8.0][1.2.8.0] ### Add -* Add curl error string to debug log. -* Add environment variable to enable/disable verbose curl output. +* Curl error string to debug log. +* Environment variable to enable/disable verbose curl output. * Method to get the initial transaction from a payment. +* Parameter `css` to `Paypage` to enable custom styling. Special thanks to github user [bleenders](https://github.com/bleenders). ### Change * Mask auth header in debug log. diff --git a/src/Resources/PaymentTypes/Paypage.php b/src/Resources/PaymentTypes/Paypage.php index c7004b99..1de955c4 100644 --- a/src/Resources/PaymentTypes/Paypage.php +++ b/src/Resources/PaymentTypes/Paypage.php @@ -99,8 +99,8 @@ class Paypage extends BasePaymentType /** @var bool $card3ds */ protected $card3ds; - /** @var array $css */ - protected $css = []; + /** @var array|null $css */ + protected $css; /** * Paypage constructor. @@ -548,14 +548,13 @@ public function getCss(): ?array } /** - * @param array $styles + * @param array|null $styles + * * @return Paypage */ public function setCss($styles): Paypage { - foreach ($styles as $element => $css) { - $this->css[$element] = $css; - } + $this->css = empty($styles) ? null : $styles; return $this; } diff --git a/test/integration/PaymentTypes/PaypageTest.php b/test/integration/PaymentTypes/PaypageTest.php index ef19dba4..6c40aca1 100644 --- a/test/integration/PaymentTypes/PaypageTest.php +++ b/test/integration/PaymentTypes/PaypageTest.php @@ -145,4 +145,17 @@ public function maximumPaypageAuthorizeShouldBeCreatable(): void $this->assertNotNull($payment->getId()); $this->assertNotEmpty($paypage->getRedirectUrl()); } + + /** + * Validate paypage css can be set empty array. + * + * @test + */ + public function cssShouldAllowForEmptyArray(): void + { + $paypage = new Paypage(100.0, 'EUR', self::RETURN_URL); + $this->assertEmpty($paypage->getId()); + $paypage = $this->heidelpay->initPayPageAuthorize($paypage->setCss([])); + $this->assertNotEmpty($paypage->getId()); + } } diff --git a/test/unit/Resources/PaymentTypes/PayPageTest.php b/test/unit/Resources/PaymentTypes/PayPageTest.php index b8308d1e..79647a12 100644 --- a/test/unit/Resources/PaymentTypes/PayPageTest.php +++ b/test/unit/Resources/PaymentTypes/PayPageTest.php @@ -70,6 +70,7 @@ public function getterAndSetterWorkAsExpected(): void $this->assertNull($paypage->getShopDescription()); $this->assertNull($paypage->getShopName()); $this->assertNull($paypage->getTagline()); + $this->assertNull($paypage->getCss()); // link urls $this->assertNull($paypage->getContactUrl()); @@ -102,7 +103,13 @@ public function getterAndSetterWorkAsExpected(): void ->setPayment($payment) ->setRedirectUrl('https://redirect.url') ->addExcludeType(SepaDirectDebit::getResourceName()) - ->setCard3ds(true); + ->setCard3ds(true) + ->setCss([ + 'shopDescription' => 'color: purple', + 'header' => 'background-color: red', + 'helpUrl' => 'color: blue', + 'contactUrl' => 'color: green', + ]); // ----------- VERIFY test values ------------ $this->assertEquals(321.0, $paypage->getAmount()); @@ -121,6 +128,12 @@ public function getterAndSetterWorkAsExpected(): void $this->assertEquals('my shop description', $paypage->getShopDescription()); $this->assertEquals('my shop name', $paypage->getShopName()); $this->assertEquals('my shops tag line', $paypage->getTagline()); + $this->assertEquals([ + 'shopDescription' => 'color: purple', + 'header' => 'background-color: red', + 'helpUrl' => 'color: blue', + 'contactUrl' => 'color: green', + ], $paypage->getCss()); // link urls $this->assertEquals('my contact url', $paypage->getContactUrl()); @@ -167,6 +180,7 @@ public function responseHandlingShouldWorkProperly(): void $this->assertNull($paypage->getShopDescription()); $this->assertNull($paypage->getShopName()); $this->assertNull($paypage->getTagline()); + $this->assertNull($paypage->getCss()); $this->assertNull($paypage->getContactUrl()); $this->assertNull($paypage->getHelpUrl()); @@ -191,6 +205,7 @@ public function responseHandlingShouldWorkProperly(): void $response->imprintUrl = 'imprint url'; $response->privacyPolicyUrl = 'privacy policy url'; $response->termsAndConditionUrl = 'tac url'; + $response->css = ['my'=> 'styles']; $paypage->handleResponse($response); // then @@ -207,6 +222,7 @@ public function responseHandlingShouldWorkProperly(): void $this->assertEquals('shop description', $paypage->getShopDescription()); $this->assertEquals('shop name', $paypage->getShopName()); $this->assertEquals('tagline', $paypage->getTagline()); + $this->assertEquals(['my' => 'styles'], $paypage->getCss()); $this->assertEquals('contact url', $paypage->getContactUrl()); $this->assertEquals('help url', $paypage->getHelpUrl()); @@ -330,7 +346,8 @@ public function exposeShouldSetBasicParams(): void ->setRedirectUrl('https://redirect.url') ->setOrderId('my order id') ->setInvoiceId('my invoice id') - ->setEffectiveInterestRate(4.99); + ->setEffectiveInterestRate(4.99) + ->setCss(['my' => 'style']); // then $expected = [ @@ -356,7 +373,8 @@ public function exposeShouldSetBasicParams(): void 'orderId' => 'my order id', 'invoiceId' => 'my invoice id', 'excludeTypes' => [], - 'additionalAttributes' => ['effectiveInterestRate' => 4.99] + 'additionalAttributes' => ['effectiveInterestRate' => 4.99], + 'css' => ['my' => 'style'] ]; $this->assertEquals($expected, $paypage->expose()); }