From 949d181058e3d301ad780447a211203270cf7dd2 Mon Sep 17 00:00:00 2001 From: sixer1182 Date: Mon, 20 Jan 2020 09:54:04 +0100 Subject: [PATCH 1/2] [change] (PHPLIB-245) Add tests to verify new api behaviour. --- test/integration/PaymentTest.php | 51 ++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/test/integration/PaymentTest.php b/test/integration/PaymentTest.php index 037e619c..7db8addb 100755 --- a/test/integration/PaymentTest.php +++ b/test/integration/PaymentTest.php @@ -28,6 +28,7 @@ use heidelpayPHP\Constants\ApiResponseCodes; use heidelpayPHP\Exceptions\HeidelpayApiException; use heidelpayPHP\Resources\Payment; +use heidelpayPHP\Resources\PaymentTypes\Card; use heidelpayPHP\Resources\PaymentTypes\Paypal; use heidelpayPHP\Resources\TransactionTypes\Authorization; use heidelpayPHP\Resources\TransactionTypes\Charge; @@ -237,4 +238,54 @@ public function paymentShouldBeFetchedByOrderIdIfIdIsNotSet() $this->assertNotSame($payment, $fetchedPayment); $this->assertEquals($payment->expose(), $fetchedPayment->expose()); } + + /** + * Verify orderId does not need to be unique. + * + * @test + * @throws HeidelpayApiException + * @throws RuntimeException + */ + public function shouldAllowNonUniqueOrderId() + { + $orderId = self::generateRandomId(); + + /** @var Card $card */ + $card = $this->heidelpay->createPaymentType($this->createCardObject()); + $card->charge(1023, 'EUR', self::RETURN_URL, null, $orderId); + + try { + /** @var Card $card2 */ + $card2 = $this->heidelpay->createPaymentType($this->createCardObject()); + $card2->charge(1023, 'EUR', self::RETURN_URL, null, $orderId); + $this->assertTrue(true); + } catch (HeidelpayApiException $e) { + $this->assertTrue(false, "No exception expected here. ({$e->getMerchantMessage()})"); + } + } + + /** + * Verify invoiceId does not need to be unique. + * + * @test + * @throws HeidelpayApiException + * @throws RuntimeException + */ + public function shouldAllowNonUniqueInvoiceId() + { + $invoiceId = self::generateRandomId(); + + /** @var Card $card */ + $card = $this->heidelpay->createPaymentType($this->createCardObject()); + $card->charge(1023, 'EUR', self::RETURN_URL, null, null, null, null, null, $invoiceId); + + try { + /** @var Card $card2 */ + $card2 = $this->heidelpay->createPaymentType($this->createCardObject()); + $card2->charge(1023, 'EUR', self::RETURN_URL, null, null, null, null, null, $invoiceId); + $this->assertTrue(true); + } catch (HeidelpayApiException $e) { + $this->assertTrue(false, "No exception expected here. ({$e->getMerchantMessage()})"); + } + } } From 7323484cfc3a974694496c49f705f7442188d03e Mon Sep 17 00:00:00 2001 From: sixer1182 Date: Mon, 20 Jan 2020 13:24:14 +0100 Subject: [PATCH 2/2] [change] (PHPLIB-245) Remove obsolete test. --- test/integration/PaymentTest.php | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/test/integration/PaymentTest.php b/test/integration/PaymentTest.php index 7db8addb..7b865d20 100755 --- a/test/integration/PaymentTest.php +++ b/test/integration/PaymentTest.php @@ -196,29 +196,6 @@ public function chargePaymentShouldThrowErrorOnNonPaymentId() $this->heidelpay->chargePayment('s-crd-xlj0qhdiw40k'); } - /** - * Verify an Exception is thrown if the orderId already exists. - * - * @test - * - * @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. - */ - public function apiShouldReturnErrorIfOrderIdAlreadyExists() - { - $orderId = str_replace(' ', '', microtime()); - - $paypal = $this->heidelpay->createPaymentType(new Paypal()); - $authorization = $this->heidelpay->authorize(100.00, 'EUR', $paypal, 'http://heidelpay.com', null, $orderId, null, null, false); - $this->assertNotEmpty($authorization); - - $paypal2 = $this->heidelpay->createPaymentType(new Paypal()); - - $this->expectException(HeidelpayApiException::class); - $this->expectExceptionCode(ApiResponseCodes::API_ERROR_ORDER_ID_ALREADY_IN_USE); - $this->heidelpay->authorize(101.00, 'EUR', $paypal2, 'http://heidelpay.com', null, $orderId, null, null, false); - } - /** * Verify a payment is fetched by orderId if the id is not set. * @@ -243,6 +220,7 @@ public function paymentShouldBeFetchedByOrderIdIfIdIsNotSet() * Verify orderId does not need to be unique. * * @test + * * @throws HeidelpayApiException * @throws RuntimeException */ @@ -268,6 +246,7 @@ public function shouldAllowNonUniqueOrderId() * Verify invoiceId does not need to be unique. * * @test + * * @throws HeidelpayApiException * @throws RuntimeException */