From b1d747c7c08e5bc165eb9f76509467295bcbc62a Mon Sep 17 00:00:00 2001 From: sixer1182 Date: Tue, 15 Oct 2019 10:03:12 +0200 Subject: [PATCH 1/5] [change] (PHPLIB-245) SEPA: Allow recurring payment. --- CHANGELOG.md | 1 + README.md | 2 +- .../PaymentTypes/SepaDirectDebit.php | 2 ++ .../SepaDirectDebitGuaranteed.php | 2 ++ test/integration/RecurringPaymentTest.php | 36 +++++++++++++++++++ 5 files changed, 42 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 685d088a..3bfc1822 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a * Refactor deprecation notices. * Refactored and extended unit tests. * Test keypair can now be set via environment variables. +* Activate recurring payment for `SEPA Direct Debit (guaranteed)`. ## [1.2.2.0][1.2.2.0] diff --git a/README.md b/README.md index e017acdd..78d3d64e 100755 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Please refer to the following documentation for installation instructions and us * PayPal + Recurring * Prepayment * Przelewy24 -* SEPA direct debit (guaranteed) +* SEPA direct debit (guaranteed) + Recurring * SOFORT * EPS * FlexiPay direct (PIS) diff --git a/src/Resources/PaymentTypes/SepaDirectDebit.php b/src/Resources/PaymentTypes/SepaDirectDebit.php index c724599d..89fb00d4 100755 --- a/src/Resources/PaymentTypes/SepaDirectDebit.php +++ b/src/Resources/PaymentTypes/SepaDirectDebit.php @@ -26,11 +26,13 @@ use heidelpayPHP\Traits\CanDirectCharge; use heidelpayPHP\Traits\CanPayout; +use heidelpayPHP\Traits\CanRecur; class SepaDirectDebit extends BasePaymentType { use CanDirectCharge; use CanPayout; + use CanRecur; /** @var string $iban */ protected $iban; diff --git a/src/Resources/PaymentTypes/SepaDirectDebitGuaranteed.php b/src/Resources/PaymentTypes/SepaDirectDebitGuaranteed.php index 237381a9..70408cae 100755 --- a/src/Resources/PaymentTypes/SepaDirectDebitGuaranteed.php +++ b/src/Resources/PaymentTypes/SepaDirectDebitGuaranteed.php @@ -26,11 +26,13 @@ use heidelpayPHP\Traits\CanDirectChargeWithCustomer; use heidelpayPHP\Traits\CanPayoutWithCustomer; +use heidelpayPHP\Traits\CanRecur; class SepaDirectDebitGuaranteed extends BasePaymentType { use CanDirectChargeWithCustomer; use CanPayoutWithCustomer; + use CanRecur; /** @var string $iban */ protected $iban; diff --git a/test/integration/RecurringPaymentTest.php b/test/integration/RecurringPaymentTest.php index 334faec0..f849c132 100644 --- a/test/integration/RecurringPaymentTest.php +++ b/test/integration/RecurringPaymentTest.php @@ -27,6 +27,8 @@ use heidelpayPHP\Exceptions\HeidelpayApiException; use heidelpayPHP\Resources\PaymentTypes\Card; use heidelpayPHP\Resources\PaymentTypes\Paypal; +use heidelpayPHP\Resources\PaymentTypes\SepaDirectDebit; +use heidelpayPHP\Resources\PaymentTypes\SepaDirectDebitGuaranteed; use heidelpayPHP\test\BasePaymentTest; use PHPUnit\Framework\Exception; use RuntimeException; @@ -83,4 +85,38 @@ public function paypalShouldBeAbleToActivateRecurringPayments() $this->assertPending($recurring); $this->assertNotEmpty($recurring->getReturnUrl()); } + + /** + * Verify sepa direct debit can activate recurring payments. + * + * @test + * + * @throws RuntimeException + * @throws HeidelpayApiException + */ + public function sepaDirectDebitShouldBeAbleToActivateRecurringPayments() + { + /** @var SepaDirectDebit $dd */ + $dd = $this->heidelpay->createPaymentType(new SepaDirectDebit('DE89370400440532013000')); + $recurring = $dd->activateRecurring('https://dev.heidelpay.com'); + $this->assertPending($recurring); + $this->assertNotEmpty($recurring->getReturnUrl()); + } + + /** + * Verify sepa direct debit guaranteed can activate recurring payments. + * + * @test + * + * @throws RuntimeException + * @throws HeidelpayApiException + */ + public function sepaDirectDebitGuaranteedShouldBeAbleToActivateRecurringPayments() + { + /** @var SepaDirectDebitGuaranteed $ddg */ + $ddg = $this->heidelpay->createPaymentType(new SepaDirectDebitGuaranteed('DE89370400440532013000')); + $recurring = $ddg->activateRecurring('https://dev.heidelpay.com'); + $this->assertPending($recurring); + $this->assertNotEmpty($recurring->getReturnUrl()); + } } From cca964054eb46bcbce13bf7559500c1c3eb00a49 Mon Sep 17 00:00:00 2001 From: sixer1182 Date: Wed, 16 Oct 2019 09:07:52 +0200 Subject: [PATCH 2/5] [change] (PHPLIB-245) SEPA recurring: trial-and-error. --- test/integration/RecurringPaymentTest.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/integration/RecurringPaymentTest.php b/test/integration/RecurringPaymentTest.php index f849c132..0c5f4803 100644 --- a/test/integration/RecurringPaymentTest.php +++ b/test/integration/RecurringPaymentTest.php @@ -98,9 +98,12 @@ public function sepaDirectDebitShouldBeAbleToActivateRecurringPayments() { /** @var SepaDirectDebit $dd */ $dd = $this->heidelpay->createPaymentType(new SepaDirectDebit('DE89370400440532013000')); - $recurring = $dd->activateRecurring('https://dev.heidelpay.com'); - $this->assertPending($recurring); - $this->assertNotEmpty($recurring->getReturnUrl()); + $this->assertFalse($dd->isRecurring()); + $dd->charge(10.0, 'EUR', self::RETURN_URL); + $dd = $this->heidelpay->fetchPaymentType($dd->getId()); + $this->assertTrue($dd->isRecurring()); + // todo: catch error when AHC-2432 is done + $this->heidelpay->activateRecurringPayment($dd, self::RETURN_URL); } /** From c43fa0a4d5f8b3916d4cc43d98daa85727d70969 Mon Sep 17 00:00:00 2001 From: sixer1182 Date: Thu, 9 Jan 2020 17:33:32 +0100 Subject: [PATCH 3/5] [change] (PHPLIB-245) Enable recurring tests for SEPA Direct Debit. --- src/Constants/ApiResponseCodes.php | 2 ++ test/integration/RecurringPaymentTest.php | 11 +++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Constants/ApiResponseCodes.php b/src/Constants/ApiResponseCodes.php index eb05a4d7..76392b8c 100755 --- a/src/Constants/ApiResponseCodes.php +++ b/src/Constants/ApiResponseCodes.php @@ -69,6 +69,8 @@ class ApiResponseCodes const API_ERROR_CUSTOMER_CAN_NOT_BE_FOUND = 'API.500.100.100'; const API_ERROR_REQUEST_DATA_IS_INVALID = 'API.500.300.999'; const API_ERROR_RECURRING_PAYMENT_NOT_SUPPORTED = 'API.500.550.004'; + const API_ERROR_ACTIVATE_RECURRING_VIA_TRANSACTION = 'API.500.550.005'; + const API_ERROR_RECURRING_ALREADY_ACTIVE = 'API.500.550.006'; const API_ERROR_WEBHOOK_EVENT_ALREADY_REGISTERED = 'API.510.310.009'; const API_ERROR_WEBHOOK_CAN_NOT_BE_FOUND = 'API.510.310.008'; const API_ERROR_BASKET_ITEM_IMAGE_INVALID_URL = 'API.600.630.004'; diff --git a/test/integration/RecurringPaymentTest.php b/test/integration/RecurringPaymentTest.php index ea8e1e4d..5be3f1c2 100644 --- a/test/integration/RecurringPaymentTest.php +++ b/test/integration/RecurringPaymentTest.php @@ -133,7 +133,9 @@ public function sepaDirectDebitShouldBeAbleToActivateRecurringPayments() $dd->charge(10.0, 'EUR', self::RETURN_URL); $dd = $this->heidelpay->fetchPaymentType($dd->getId()); $this->assertTrue($dd->isRecurring()); - // todo: catch error when AHC-2432 is done + + $this->expectException(HeidelpayApiException::class); + $this->expectExceptionCode(ApiResponseCodes::API_ERROR_RECURRING_ALREADY_ACTIVE); $this->heidelpay->activateRecurringPayment($dd, self::RETURN_URL); } @@ -149,8 +151,9 @@ public function sepaDirectDebitGuaranteedShouldBeAbleToActivateRecurringPayments { /** @var SepaDirectDebitGuaranteed $ddg */ $ddg = $this->heidelpay->createPaymentType(new SepaDirectDebitGuaranteed('DE89370400440532013000')); - $recurring = $ddg->activateRecurring('https://dev.heidelpay.com'); - $this->assertPending($recurring); - $this->assertNotEmpty($recurring->getReturnUrl()); + + $this->expectException(HeidelpayApiException::class); + $this->expectExceptionCode(ApiResponseCodes::API_ERROR_ACTIVATE_RECURRING_VIA_TRANSACTION); + $ddg->activateRecurring('https://dev.heidelpay.com'); } } From 0078b56cfbf7193900db24b9118bc80441cc3080 Mon Sep 17 00:00:00 2001 From: sixer1182 Date: Thu, 9 Jan 2020 18:10:03 +0100 Subject: [PATCH 4/5] [change] (PHPLIB-245) Update CHANGELOG.md and README.md. --- CHANGELOG.md | 1 + README.md | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f662c8d7..0fea84f6 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a ### Added * Example for Payment Type `Przelewy24`. +* Enabled recurring payment for SEPA direct debit. ### Fixed * A bug which led to an error when trying to cancel the initial transaction of a charged invoice. diff --git a/README.md b/README.md index 5094b82e..f3b88f16 100755 --- a/README.md +++ b/README.md @@ -26,7 +26,8 @@ Please refer to the following documentation for installation instructions and us * PayPal + Recurring * Prepayment * Przelewy24 -* SEPA direct debit (guaranteed) + Recurring +* SEPA direct debit + Recurring +* SEPA direct debit guaranteed * SOFORT * EPS * FlexiPay® Direct (PIS) From b35a233aa518557ed4ca66fbaa11146bea2a5a6d Mon Sep 17 00:00:00 2001 From: sixer1182 Date: Thu, 9 Jan 2020 18:14:23 +0100 Subject: [PATCH 5/5] [change] (PHPLIB-245) Update CHANGELOG.md and README.md. --- CHANGELOG.md | 2 +- README.md | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fea84f6..e48af782 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a ### Added * Example for Payment Type `Przelewy24`. -* Enabled recurring payment for SEPA direct debit. +* Enabled recurring payment for SEPA direct debit (guaranteed). ### Fixed * A bug which led to an error when trying to cancel the initial transaction of a charged invoice. diff --git a/README.md b/README.md index f3b88f16..5094b82e 100755 --- a/README.md +++ b/README.md @@ -26,8 +26,7 @@ Please refer to the following documentation for installation instructions and us * PayPal + Recurring * Prepayment * Przelewy24 -* SEPA direct debit + Recurring -* SEPA direct debit guaranteed +* SEPA direct debit (guaranteed) + Recurring * SOFORT * EPS * FlexiPay® Direct (PIS)