Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Services/HttpService.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ public function send(
?string $uri = null,
?AbstractUnzerResource $resource = null,
string $httpMethod = HttpAdapterInterface::REQUEST_GET,
string $apiVersion = Unzer::API_VERSION
string $apiVersion = null
): string {
if (!$resource instanceof AbstractUnzerResource) {
throw new RuntimeException('Transfer object is empty!');
}
$unzerObj = $resource->getUnzerObject();

$apiRequest = (new ApiRequest($uri, $resource, $httpMethod, $unzerObj, $apiVersion));
$apiRequest = (new ApiRequest($uri, $resource, $httpMethod, $unzerObj, $apiVersion ?? $resource->getApiVersion()));

return $this->sendRequest($apiRequest);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Services/IdService.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public static function getResourceTypeFromIdString(string $typeId): ?string
return $typeIdString;
}

public static function isUUDIResource(string $id): bool
public static function isUUIDResource(string $id): bool
{
preg_match('/^[sp]-([a-z]{3}|p24)-[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/', $id, $matches);
return count($matches) > 0;
Expand Down
11 changes: 5 additions & 6 deletions src/Services/ResourceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function setUnzer(Unzer $unzer): ResourceServiceInterface
public function send(
AbstractUnzerResource $resource,
string $httpMethod = HttpAdapterInterface::REQUEST_GET,
string $apiVersion = Unzer::API_VERSION
string $apiVersion = null
): stdClass
{
$apiConfig = $resource->getApiConfig();
Expand Down Expand Up @@ -346,7 +346,7 @@ public function deleteResource(AbstractUnzerResource &$resource): ?AbstractUnzer
* @throws RuntimeException A RuntimeException is thrown when there is an error while using the SDK.
* @throws Exception
*/
public function fetchResource(AbstractUnzerResource $resource, string $apiVersion = Unzer::API_VERSION): AbstractUnzerResource
public function fetchResource(AbstractUnzerResource $resource, string $apiVersion = null): AbstractUnzerResource
{
$method = HttpAdapterInterface::REQUEST_GET;
$response = $this->send($resource, $method, $apiVersion);
Expand Down Expand Up @@ -553,16 +553,15 @@ public function createBasket(Basket $basket): Basket
public function fetchBasket($basket): Basket
{
$basketObj = $basket;
$isV3Basket = false;

if (is_string($basket)) {
$isV3Basket = IdService::isUUDIResource($basket);
$isV3Basket = IdService::isUUIDResource($basket);
$basketObj = $isV3Basket ? new BasketV3() : new Basket();
$basketObj->setId($basket);
}

$basketObj->setParentResource($this->unzer);
$basketVersion = $isV3Basket ? ApiVersions::V3 : ApiVersions::V2;
$basketVersion = $basketObj->getApiVersion() === ApiVersions::V3 ? ApiVersions::V3 : ApiVersions::V2;

try {
$this->fetchResource($basketObj, $basketVersion);
Expand Down Expand Up @@ -658,7 +657,7 @@ public function fetchCustomer($customer): Customer
$customerObject = $customer;

if (is_string($customer)) {
$isUUID = IdService::isUUDIResource($customer);
$isUUID = IdService::isUUIDResource($customer);
$customerObject = $isUUID ? new CustomerV2() : new Customer();
$customerObject->setId($customer);
}
Expand Down
1 change: 0 additions & 1 deletion test/integration/PaymentTypes/PaypalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ public function paypalShouldBeAuthorizable(Paypal $paypal): void
$this->assertNotEmpty($authorization->getRedirectUrl());

$payment = $authorization->getPayment();
$this->getUnzerObject()->performChargeOnPayment($payment, new Charge(100.0, 'EUR', self::RETURN_URL));
$this->assertNotNull($payment);
$this->assertTrue($payment->isPending());
}
Expand Down
8 changes: 0 additions & 8 deletions test/integration/Resources/BasketV2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

class BasketV2Test extends BaseIntegrationTest
{
//<editor-fold desc="Basket v2 tests">

/**
* Verify basket can be created and fetched.
*
Expand Down Expand Up @@ -299,10 +297,6 @@ public function chargeTransactionsShouldCreateBasketIfItDoesNotExistYet(): void
$this->assertEquals($basket->expose(), $fetchedPayment->getBasket()->expose());
}

//</editor-fold>

//<editor-fold desc="Data Providers">

/**
* @return array
*/
Expand All @@ -315,6 +309,4 @@ public function basketItemWithInvalidUrlWillThrowAnErrorDP(): array
'invalid not available' => [true, 'https://files.readme.io/does-not-exist.jpg', ApiResponseCodes::API_ERROR_BASKET_ITEM_IMAGE_INVALID_URL]
];
}

//</editor-fold>
}
5 changes: 2 additions & 3 deletions test/integration/Resources/BasketV3Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use UnzerSDK\test\BaseIntegrationTest;

/**
* @group skip
*/
class BasketV3Test extends BaseIntegrationTest
{
Expand All @@ -44,7 +43,7 @@ public function minV3BasketShouldBeCreatableAndFetchable(): void
$basketItem = new BasketItem();
$basketItem->setBasketItemReferenceId('item1')
->setQuantity(1)
->setAmountPerUnitGross(100)
->setAmountPerUnitGross(99.99)
->setTitle('title');
$basket->addBasketItem($basketItem);
$this->assertEmpty($basket->getId());
Expand All @@ -53,7 +52,7 @@ public function minV3BasketShouldBeCreatableAndFetchable(): void
$this->assertNotEmpty($basket->getId());
$this->unzer->prepareJwtToken();

$fetchedBasket = $this->unzer->fetchBasket($basket->getId())->setOrderId('');
$fetchedBasket = $this->unzer->fetchBasket($basket->getId())->setOrderId($orderId);
$this->assertEquals($basket->expose(), $fetchedBasket->expose());
}

Expand Down
1 change: 0 additions & 1 deletion test/integration/Resources/CustomerV2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
/**
* @backupStaticAttributes enabled
* @group CC-2016
* @group skip
*/
class CustomerV2Test extends BaseIntegrationTest
{
Expand Down
21 changes: 18 additions & 3 deletions test/integration/Resources/LinkpayV2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
*/
class LinkpayV2Test extends BaseIntegrationTest
{
private static ?string $token = null;

protected function setUp(): void
{
parent::setUp();
self::$token = $this->unzer->prepareJwtToken(self::$token);
}

/**
* @test
*/
Expand Down Expand Up @@ -128,7 +136,8 @@ public function updateLinkpayExpiryDate()
$this->assertEquals($paypage->getCurrency(), $updatePaypage->getCurrency());
$this->assertEquals($paypage->getAlias(), $updatePaypage->getAlias());
$this->assertEquals($paypage->getAmountSettings(), $updatePaypage->getAmountSettings());
$this->assertEquals($paypage->getResources(), $updatePaypage->getResources());

$this->assertNotEmpty($updatePaypage->getResources()->getMetadataId());
}

/**
Expand Down Expand Up @@ -167,8 +176,11 @@ public function updateLinkpayAmount()
$this->assertEquals($paypage->getCurrency(), $updatePaypage->getCurrency());
$this->assertEquals($paypage->getAlias(), $updatePaypage->getAlias());
$this->assertEquals($paypage->getAmountSettings(), $updatePaypage->getAmountSettings());
$this->assertEquals($paypage->getResources(), $updatePaypage->getResources());
$this->assertEquals($paypage->getExpiresAt(), $updatePaypage->getExpiresAt());

$this->assertNotEmpty($updatePaypage->getResources()->getMetadataId());
$this->assertEmpty($updatePaypage->getResources()->getCustomerId());
$this->assertEmpty($updatePaypage->getResources()->getBasketId());
}

/**
Expand Down Expand Up @@ -208,8 +220,11 @@ public function updateLinkpayAmountSettings()
$this->assertEquals($paypage->getAmount(), $updatePaypage->getAmount());
$this->assertEquals($paypage->getCurrency(), $updatePaypage->getCurrency());
$this->assertEquals($paypage->getExpiresAt(), $updatePaypage->getExpiresAt());
$this->assertEquals($paypage->getResources(), $updatePaypage->getResources());
$this->assertEquals('linkpay', $paypage->getType());

$this->assertNotEmpty($updatePaypage->getResources()->getMetadataId());
$this->assertEmpty($updatePaypage->getResources()->getCustomerId());
$this->assertEmpty($updatePaypage->getResources()->getBasketId());
}

/**
Expand Down
15 changes: 11 additions & 4 deletions test/integration/Resources/PaypageV2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace UnzerSDK\test\integration\Resources;

use UnzerSDK\Constants\CustomerGroups;
use UnzerSDK\Constants\ExemptionType;
use UnzerSDK\Constants\PaypageCheckoutTypes;
use UnzerSDK\Resources\EmbeddedResources\Paypage\PaymentMethodConfig;
Expand Down Expand Up @@ -41,6 +42,14 @@
*/
class PaypageV2Test extends BaseIntegrationTest
{
private static ?string $token = null;

protected function setUp(): void
{
parent::setUp();
self::$token = $this->unzer->prepareJwtToken(self::$token);
}

/**
* @test
*/
Expand Down Expand Up @@ -99,7 +108,6 @@ public function JwtTokenShouldBeReusedForMultipleRequests()
$this->assertNull($paypageSecond->getRedirectUrl());

// Create Firt paypage
$this->assertNull($unzer->getJwtToken());
$unzer->createPaypage($paypageFirst);
$InitialJwtToken = $unzer->getJwtToken();
$this->assertNotNull($InitialJwtToken);
Expand Down Expand Up @@ -228,7 +236,7 @@ public function createPaypageWithRiskData()
$unzer = $this->getUnzerObject();
$risk = new Risk();

$risk->setCustomerGroup('neutral')
$risk->setCustomerGroup(CustomerGroups::NEUTRAL)
->setConfirmedAmount('1234')
->setConfirmedOrders('42')
->setRegistrationLevel('1')
Expand Down Expand Up @@ -299,8 +307,7 @@ public function paymentMethodsConfigsDataProvider()
->addMethodConfig(PostFinanceEfinance::class, $enabledConfig)
->addMethodConfig(PostFinanceCard::class, $enabledConfig)
->addMethodConfig(Twint::class, $enabledConfig)
->addMethodConfig(OpenbankingPis::class, $enabledConfig)
;
->addMethodConfig(OpenbankingPis::class, $enabledConfig);

$withPaylaterConfig = (new PaymentMethodsConfigs())
->addMethodConfig(PaylaterInvoice::class, $paylaterConfig);
Expand Down
4 changes: 2 additions & 2 deletions test/unit/Services/IdServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class IdServiceTest extends BasePaymentTest
*/
public function idWithUniqueIdReturnsTrue(string $id)
{
$isUUID = IdService::isUUDIResource($id);
$isUUID = IdService::isUUIDResource($id);
$this->assertTrue($isUUID);
}

Expand All @@ -29,7 +29,7 @@ public function idWithUniqueIdReturnsTrue(string $id)
*/
public function shortIdShouldReturnFalse(string $id)
{
$isUUID = IdService::isUUDIResource($id);
$isUUID = IdService::isUUIDResource($id);
$this->assertFalse($isUUID);
}

Expand Down
4 changes: 2 additions & 2 deletions test/unit/Services/ResourceServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ public function fetchBasketShouldCallV1EnpointIfBasketWasNotFound(): void

$resourceServiceMock->expects(self::exactly(2))
->method('fetchResource')
->withConsecutive([$basket, BasePaymentTest::API_VERSION_2], [$basket, Unzer::API_VERSION])
->withConsecutive([$basket, BasePaymentTest::API_VERSION_2], [$basket])
->will($this->returnCallback(function ($basket, $version) {
if ($version === BasePaymentTest::API_VERSION_2) {
throw new UnzerApiException(null, null, ApiResponseCodes::API_ERROR_BASKET_NOT_FOUND);
Expand Down Expand Up @@ -1092,7 +1092,7 @@ public function fetchBasketShouldCallFetchResourceMaxTwoTimes(): void

$resourceServiceMock->expects(self::exactly(2))
->method('fetchResource')
->withConsecutive([$basket, BasePaymentTest::API_VERSION_2], [$basket, Unzer::API_VERSION])
->withConsecutive([$basket, BasePaymentTest::API_VERSION_2], [$basket])
->willThrowException(new UnzerApiException(null, null, ApiResponseCodes::API_ERROR_BASKET_NOT_FOUND));

$this->expectException(UnzerApiException::class);
Expand Down