diff --git a/test/integration/PaymentTest.php b/test/integration/PaymentTest.php index 037e619c..7b865d20 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; @@ -196,45 +197,74 @@ public function chargePaymentShouldThrowErrorOnNonPaymentId() } /** - * Verify an Exception is thrown if the orderId already exists. + * Verify a payment is fetched by orderId if the id is not set. * * @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() + public function paymentShouldBeFetchedByOrderIdIfIdIsNotSet() { $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); + $payment = $authorization->getPayment(); + $fetchedPayment = $this->heidelpay->fetchPaymentByOrderId($orderId); + + $this->assertNotSame($payment, $fetchedPayment); + $this->assertEquals($payment->expose(), $fetchedPayment->expose()); + } - $paypal2 = $this->heidelpay->createPaymentType(new Paypal()); + /** + * Verify orderId does not need to be unique. + * + * @test + * + * @throws HeidelpayApiException + * @throws RuntimeException + */ + public function shouldAllowNonUniqueOrderId() + { + $orderId = self::generateRandomId(); - $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); + /** @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 a payment is fetched by orderId if the id is not set. + * Verify invoiceId does not need to be unique. * * @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. + * @throws HeidelpayApiException + * @throws RuntimeException */ - public function paymentShouldBeFetchedByOrderIdIfIdIsNotSet() + public function shouldAllowNonUniqueInvoiceId() { - $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); - $payment = $authorization->getPayment(); - $fetchedPayment = $this->heidelpay->fetchPaymentByOrderId($orderId); + $invoiceId = self::generateRandomId(); - $this->assertNotSame($payment, $fetchedPayment); - $this->assertEquals($payment->expose(), $fetchedPayment->expose()); + /** @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()})"); + } } }