Skip to content
This repository has been archived by the owner on Mar 29, 2022. It is now read-only.

Commit

Permalink
Merge pull request #128 from heidelpay/develop
Browse files Browse the repository at this point in the history
release 1.2.4.0
  • Loading branch information
Simon Gabriel authored Nov 5, 2019
2 parents 05ba1ca + 82b4488 commit 156cd52
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
12 changes: 11 additions & 1 deletion src/Resources/AbstractHeidelpayResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ abstract class AbstractHeidelpayResource implements HeidelpayParentInterface

//<editor-fold desc="Getters/Setters">

/**
* 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.
*
Expand Down Expand Up @@ -360,7 +370,7 @@ public function getLinkedResources(): array
*/
protected function getResourcePath(): string
{
return ResourceNameService::getClassShortNameKebapCase(static::class);
return self::getResourceName();
}

/**
Expand Down
41 changes: 41 additions & 0 deletions src/Resources/PaymentTypes/Paypage.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ class Paypage extends BasePaymentType
/** @var Payment|null $payment */
private $payment;

/** @var string[] $excludeTypes */
protected $excludeTypes = [];

/**
* Paypage constructor.
*
Expand Down Expand Up @@ -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;
}

//</editor-fold>

//<editor-fold desc="Overridable methods">
Expand Down
3 changes: 3 additions & 0 deletions test/integration/PaymentTypes/PaypageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
17 changes: 15 additions & 2 deletions test/unit/Resources/PaymentTypes/PayPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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());
Expand All @@ -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());
}

/**
Expand Down Expand Up @@ -354,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());
}
Expand Down

0 comments on commit 156cd52

Please sign in to comment.