Skip to content
This repository has been archived by the owner on Mar 29, 2022. It is now read-only.

Commit

Permalink
Merge pull request #154 from heidelpay/change/PHPLIB-245/add-sepa-rec…
Browse files Browse the repository at this point in the history
…urring

Merge remote-tracking branch 'remotes/github/develop' into change/PHPLIB-245/add-sepa-recurring
  • Loading branch information
Simon Gabriel authored Jan 21, 2020
2 parents b548e20 + 36242eb commit 54a3f6d
Showing 1 changed file with 49 additions and 19 deletions.
68 changes: 49 additions & 19 deletions test/integration/PaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()})");
}
}
}

0 comments on commit 54a3f6d

Please sign in to comment.