diff --git a/src/Resources/Recurring.php b/src/Resources/Recurring.php index 28bd4b2d..413db441 100644 --- a/src/Resources/Recurring.php +++ b/src/Resources/Recurring.php @@ -39,7 +39,7 @@ class Recurring extends AbstractHeidelpayResource /** @var string $returnUrl */ protected $returnUrl; - /** @var string $redirectUrl */ + /** @var string|null $redirectUrl */ protected $redirectUrl; /** @var string $paymentTypeId */ @@ -96,19 +96,19 @@ public function setPaymentTypeId(string $paymentTypeId): Recurring } /** - * @return string + * @return string|null */ - public function getRedirectUrl(): string + public function getRedirectUrl() { return $this->redirectUrl; } /** - * @param string $redirectUrl + * @param string|null $redirectUrl * * @return Recurring */ - protected function setRedirectUrl(string $redirectUrl): Recurring + protected function setRedirectUrl($redirectUrl): Recurring { $this->redirectUrl = $redirectUrl; return $this; diff --git a/src/Services/EnvironmentService.php b/src/Services/EnvironmentService.php index 1d9d7356..8cd265f9 100755 --- a/src/Services/EnvironmentService.php +++ b/src/Services/EnvironmentService.php @@ -80,23 +80,29 @@ public static function getTimeout(): int * Returns the private key string set via environment variable. * Returns the default key if the environment variable is not set. * + * @param bool $non3ds + * * @return string */ - public function getTestPrivateKey(): string + public function getTestPrivateKey($non3ds = false): string { - $key = $_SERVER[self::ENV_VAR_TEST_PRIVATE_KEY] ?? ''; - return empty($key) ? self::DEFAULT_TEST_PRIVATE_KEY : $key; + $variableName = self::ENV_VAR_TEST_PRIVATE_KEY . ($non3ds ? '_NON_3DS' : ''); + $key = $_SERVER[$variableName] ?? ''; + return empty($key) && !$non3ds ? self::DEFAULT_TEST_PRIVATE_KEY : $key; } /** * Returns the public key string set via environment variable. * Returns the default key if the environment variable is not set. * + * @param bool $non3ds + * * @return string */ - public function getTestPublicKey(): string + public function getTestPublicKey($non3ds = false): string { - $key = $_SERVER[self::ENV_VAR_TEST_PUBLIC_KEY] ?? ''; - return empty($key) ? self::DEFAULT_TEST_PUBLIC_KEY : $key; + $variableName = self::ENV_VAR_TEST_PUBLIC_KEY . ($non3ds ? '_NON_3DS' : ''); + $key = $_SERVER[$variableName] ?? ''; + return empty($key) && !$non3ds ? self::DEFAULT_TEST_PUBLIC_KEY : $key; } } diff --git a/test/BasePaymentTest.php b/test/BasePaymentTest.php index 34faf0af..bbdc8e3a 100755 --- a/test/BasePaymentTest.php +++ b/test/BasePaymentTest.php @@ -129,11 +129,11 @@ public function assertTransactionResourceHasBeenCreated($transactionType) /** * Asserts whether the given transaction was successful. * - * @param AbstractTransactionType $transaction + * @param AbstractTransactionType|Recurring $transaction * * @throws AssertionFailedError */ - protected function assertSuccess(AbstractTransactionType $transaction) + protected function assertSuccess($transaction) { $this->assertTrue($transaction->isSuccess()); $this->assertFalse($transaction->isPending()); @@ -143,11 +143,11 @@ protected function assertSuccess(AbstractTransactionType $transaction) /** * Asserts whether the given transaction was a failure. * - * @param AbstractTransactionType $transaction + * @param AbstractTransactionType|Recurring $transaction * * @throws AssertionFailedError */ - protected function assertError(AbstractTransactionType $transaction) + protected function assertError($transaction) { $this->assertFalse($transaction->isSuccess()); $this->assertFalse($transaction->isPending()); diff --git a/test/integration/RecurringPaymentTest.php b/test/integration/RecurringPaymentTest.php index 5be3f1c2..e1661996 100644 --- a/test/integration/RecurringPaymentTest.php +++ b/test/integration/RecurringPaymentTest.php @@ -26,10 +26,12 @@ use heidelpayPHP\Constants\ApiResponseCodes; use heidelpayPHP\Exceptions\HeidelpayApiException; +use heidelpayPHP\Heidelpay; use heidelpayPHP\Resources\PaymentTypes\Card; use heidelpayPHP\Resources\PaymentTypes\Paypal; use heidelpayPHP\Resources\PaymentTypes\SepaDirectDebit; use heidelpayPHP\Resources\PaymentTypes\SepaDirectDebitGuaranteed; +use heidelpayPHP\Services\EnvironmentService; use heidelpayPHP\test\BasePaymentTest; use PHPUnit\Framework\Exception; use RuntimeException; @@ -83,20 +85,26 @@ public function recurringForCardWith3dsShouldReturnAttributes() * * @throws HeidelpayApiException A HeidelpayApiException is thrown if there is an error returned on API-request. * @throws RuntimeException A RuntimeException is thrown when there is an error while using the SDK. - * - * @group skip */ public function recurringForCardWithout3dsShouldActivateRecurringAtOnce() { + $privateKey = (new EnvironmentService())->getTestPrivateKey(true); + if (empty($privateKey)) { + $this->markTestIncomplete('No non 3ds private key set'); + } + $heidelpay = new Heidelpay($privateKey); + + $heidelpay->setDebugMode(true)->setDebugHandler($this->heidelpay->getDebugHandler()); + /** @var Card $card */ - $card = $this->heidelpay->createPaymentType($this->createCardObject()->set3ds(false)); + $card = $heidelpay->createPaymentType($this->createCardObject()->set3ds(false)); $this->assertFalse($card->isRecurring()); $recurring = $card->activateRecurring('https://dev.heidelpay.com'); - $this->assertPending($recurring); + $this->assertSuccess($recurring); /** @var Card $fetchedCard */ - $fetchedCard = $this->heidelpay->fetchPaymentType($card->getId()); + $fetchedCard = $heidelpay->fetchPaymentType($card->getId()); $this->assertTrue($fetchedCard->isRecurring()); }