diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d9e0f36..e48af782 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 (guaranteed). ### Fixed * A bug which led to an error when trying to cancel the initial transaction of a charged invoice. @@ -79,6 +80,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 df0c3502..5094b82e 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/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/src/Resources/PaymentTypes/SepaDirectDebit.php b/src/Resources/PaymentTypes/SepaDirectDebit.php index 722bff92..33b40783 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 59dc86c7..5d99819d 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 43c0a3f4..5be3f1c2 100644 --- a/test/integration/RecurringPaymentTest.php +++ b/test/integration/RecurringPaymentTest.php @@ -28,6 +28,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; @@ -114,4 +116,44 @@ 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')); + $this->assertFalse($dd->isRecurring()); + $dd->charge(10.0, 'EUR', self::RETURN_URL); + $dd = $this->heidelpay->fetchPaymentType($dd->getId()); + $this->assertTrue($dd->isRecurring()); + + $this->expectException(HeidelpayApiException::class); + $this->expectExceptionCode(ApiResponseCodes::API_ERROR_RECURRING_ALREADY_ACTIVE); + $this->heidelpay->activateRecurringPayment($dd, self::RETURN_URL); + } + + /** + * 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')); + + $this->expectException(HeidelpayApiException::class); + $this->expectExceptionCode(ApiResponseCodes::API_ERROR_ACTIVATE_RECURRING_VIA_TRANSACTION); + $ddg->activateRecurring('https://dev.heidelpay.com'); + } }