Skip to content

Commit 71e2f1f

Browse files
authored
[CC-2287] Fix cause of basket v3 and customer v2 tests failing. (#209)
* [CC-2287] Fix cause of basket v3 and customer v2 tests failing.
1 parent 41c8c2b commit 71e2f1f

File tree

11 files changed

+43
-33
lines changed

11 files changed

+43
-33
lines changed

src/Services/HttpService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ public function send(
100100
?string $uri = null,
101101
?AbstractUnzerResource $resource = null,
102102
string $httpMethod = HttpAdapterInterface::REQUEST_GET,
103-
string $apiVersion = Unzer::API_VERSION
103+
string $apiVersion = null
104104
): string {
105105
if (!$resource instanceof AbstractUnzerResource) {
106106
throw new RuntimeException('Transfer object is empty!');
107107
}
108108
$unzerObj = $resource->getUnzerObject();
109109

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

112112
return $this->sendRequest($apiRequest);
113113
}

src/Services/IdService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public static function getResourceTypeFromIdString(string $typeId): ?string
117117
return $typeIdString;
118118
}
119119

120-
public static function isUUDIResource(string $id): bool
120+
public static function isUUIDResource(string $id): bool
121121
{
122122
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);
123123
return count($matches) > 0;

src/Services/ResourceService.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function setUnzer(Unzer $unzer): ResourceServiceInterface
120120
public function send(
121121
AbstractUnzerResource $resource,
122122
string $httpMethod = HttpAdapterInterface::REQUEST_GET,
123-
string $apiVersion = Unzer::API_VERSION
123+
string $apiVersion = null
124124
): stdClass
125125
{
126126
$apiConfig = $resource->getApiConfig();
@@ -346,7 +346,7 @@ public function deleteResource(AbstractUnzerResource &$resource): ?AbstractUnzer
346346
* @throws RuntimeException A RuntimeException is thrown when there is an error while using the SDK.
347347
* @throws Exception
348348
*/
349-
public function fetchResource(AbstractUnzerResource $resource, string $apiVersion = Unzer::API_VERSION): AbstractUnzerResource
349+
public function fetchResource(AbstractUnzerResource $resource, string $apiVersion = null): AbstractUnzerResource
350350
{
351351
$method = HttpAdapterInterface::REQUEST_GET;
352352
$response = $this->send($resource, $method, $apiVersion);
@@ -553,16 +553,15 @@ public function createBasket(Basket $basket): Basket
553553
public function fetchBasket($basket): Basket
554554
{
555555
$basketObj = $basket;
556-
$isV3Basket = false;
557556

558557
if (is_string($basket)) {
559-
$isV3Basket = IdService::isUUDIResource($basket);
558+
$isV3Basket = IdService::isUUIDResource($basket);
560559
$basketObj = $isV3Basket ? new BasketV3() : new Basket();
561560
$basketObj->setId($basket);
562561
}
563562

564563
$basketObj->setParentResource($this->unzer);
565-
$basketVersion = $isV3Basket ? ApiVersions::V3 : ApiVersions::V2;
564+
$basketVersion = $basketObj->getApiVersion() === ApiVersions::V3 ? ApiVersions::V3 : ApiVersions::V2;
566565

567566
try {
568567
$this->fetchResource($basketObj, $basketVersion);
@@ -658,7 +657,7 @@ public function fetchCustomer($customer): Customer
658657
$customerObject = $customer;
659658

660659
if (is_string($customer)) {
661-
$isUUID = IdService::isUUDIResource($customer);
660+
$isUUID = IdService::isUUIDResource($customer);
662661
$customerObject = $isUUID ? new CustomerV2() : new Customer();
663662
$customerObject->setId($customer);
664663
}

test/integration/PaymentTypes/PaypalTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ public function paypalShouldBeAuthorizable(Paypal $paypal): void
8181
$this->assertNotEmpty($authorization->getRedirectUrl());
8282

8383
$payment = $authorization->getPayment();
84-
$this->getUnzerObject()->performChargeOnPayment($payment, new Charge(100.0, 'EUR', self::RETURN_URL));
8584
$this->assertNotNull($payment);
8685
$this->assertTrue($payment->isPending());
8786
}

test/integration/Resources/BasketV2Test.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121

2222
class BasketV2Test extends BaseIntegrationTest
2323
{
24-
//<editor-fold desc="Basket v2 tests">
25-
2624
/**
2725
* Verify basket can be created and fetched.
2826
*
@@ -299,10 +297,6 @@ public function chargeTransactionsShouldCreateBasketIfItDoesNotExistYet(): void
299297
$this->assertEquals($basket->expose(), $fetchedPayment->getBasket()->expose());
300298
}
301299

302-
//</editor-fold>
303-
304-
//<editor-fold desc="Data Providers">
305-
306300
/**
307301
* @return array
308302
*/
@@ -315,6 +309,4 @@ public function basketItemWithInvalidUrlWillThrowAnErrorDP(): array
315309
'invalid not available' => [true, 'https://files.readme.io/does-not-exist.jpg', ApiResponseCodes::API_ERROR_BASKET_ITEM_IMAGE_INVALID_URL]
316310
];
317311
}
318-
319-
//</editor-fold>
320312
}

test/integration/Resources/BasketV3Test.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use UnzerSDK\test\BaseIntegrationTest;
2020

2121
/**
22-
* @group skip
2322
*/
2423
class BasketV3Test extends BaseIntegrationTest
2524
{
@@ -44,7 +43,7 @@ public function minV3BasketShouldBeCreatableAndFetchable(): void
4443
$basketItem = new BasketItem();
4544
$basketItem->setBasketItemReferenceId('item1')
4645
->setQuantity(1)
47-
->setAmountPerUnitGross(100)
46+
->setAmountPerUnitGross(99.99)
4847
->setTitle('title');
4948
$basket->addBasketItem($basketItem);
5049
$this->assertEmpty($basket->getId());
@@ -53,7 +52,7 @@ public function minV3BasketShouldBeCreatableAndFetchable(): void
5352
$this->assertNotEmpty($basket->getId());
5453
$this->unzer->prepareJwtToken();
5554

56-
$fetchedBasket = $this->unzer->fetchBasket($basket->getId())->setOrderId('');
55+
$fetchedBasket = $this->unzer->fetchBasket($basket->getId())->setOrderId($orderId);
5756
$this->assertEquals($basket->expose(), $fetchedBasket->expose());
5857
}
5958

test/integration/Resources/CustomerV2Test.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
/**
1616
* @backupStaticAttributes enabled
1717
* @group CC-2016
18-
* @group skip
1918
*/
2019
class CustomerV2Test extends BaseIntegrationTest
2120
{

test/integration/Resources/LinkpayV2Test.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
*/
1313
class LinkpayV2Test extends BaseIntegrationTest
1414
{
15+
private static ?string $token = null;
16+
17+
protected function setUp(): void
18+
{
19+
parent::setUp();
20+
self::$token = $this->unzer->prepareJwtToken(self::$token);
21+
}
22+
1523
/**
1624
* @test
1725
*/
@@ -128,7 +136,8 @@ public function updateLinkpayExpiryDate()
128136
$this->assertEquals($paypage->getCurrency(), $updatePaypage->getCurrency());
129137
$this->assertEquals($paypage->getAlias(), $updatePaypage->getAlias());
130138
$this->assertEquals($paypage->getAmountSettings(), $updatePaypage->getAmountSettings());
131-
$this->assertEquals($paypage->getResources(), $updatePaypage->getResources());
139+
140+
$this->assertNotEmpty($updatePaypage->getResources()->getMetadataId());
132141
}
133142

134143
/**
@@ -167,8 +176,11 @@ public function updateLinkpayAmount()
167176
$this->assertEquals($paypage->getCurrency(), $updatePaypage->getCurrency());
168177
$this->assertEquals($paypage->getAlias(), $updatePaypage->getAlias());
169178
$this->assertEquals($paypage->getAmountSettings(), $updatePaypage->getAmountSettings());
170-
$this->assertEquals($paypage->getResources(), $updatePaypage->getResources());
171179
$this->assertEquals($paypage->getExpiresAt(), $updatePaypage->getExpiresAt());
180+
181+
$this->assertNotEmpty($updatePaypage->getResources()->getMetadataId());
182+
$this->assertEmpty($updatePaypage->getResources()->getCustomerId());
183+
$this->assertEmpty($updatePaypage->getResources()->getBasketId());
172184
}
173185

174186
/**
@@ -208,8 +220,11 @@ public function updateLinkpayAmountSettings()
208220
$this->assertEquals($paypage->getAmount(), $updatePaypage->getAmount());
209221
$this->assertEquals($paypage->getCurrency(), $updatePaypage->getCurrency());
210222
$this->assertEquals($paypage->getExpiresAt(), $updatePaypage->getExpiresAt());
211-
$this->assertEquals($paypage->getResources(), $updatePaypage->getResources());
212223
$this->assertEquals('linkpay', $paypage->getType());
224+
225+
$this->assertNotEmpty($updatePaypage->getResources()->getMetadataId());
226+
$this->assertEmpty($updatePaypage->getResources()->getCustomerId());
227+
$this->assertEmpty($updatePaypage->getResources()->getBasketId());
213228
}
214229

215230
/**

test/integration/Resources/PaypageV2Test.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace UnzerSDK\test\integration\Resources;
44

5+
use UnzerSDK\Constants\CustomerGroups;
56
use UnzerSDK\Constants\ExemptionType;
67
use UnzerSDK\Constants\PaypageCheckoutTypes;
78
use UnzerSDK\Resources\EmbeddedResources\Paypage\PaymentMethodConfig;
@@ -41,6 +42,14 @@
4142
*/
4243
class PaypageV2Test extends BaseIntegrationTest
4344
{
45+
private static ?string $token = null;
46+
47+
protected function setUp(): void
48+
{
49+
parent::setUp();
50+
self::$token = $this->unzer->prepareJwtToken(self::$token);
51+
}
52+
4453
/**
4554
* @test
4655
*/
@@ -99,7 +108,6 @@ public function JwtTokenShouldBeReusedForMultipleRequests()
99108
$this->assertNull($paypageSecond->getRedirectUrl());
100109

101110
// Create Firt paypage
102-
$this->assertNull($unzer->getJwtToken());
103111
$unzer->createPaypage($paypageFirst);
104112
$InitialJwtToken = $unzer->getJwtToken();
105113
$this->assertNotNull($InitialJwtToken);
@@ -228,7 +236,7 @@ public function createPaypageWithRiskData()
228236
$unzer = $this->getUnzerObject();
229237
$risk = new Risk();
230238

231-
$risk->setCustomerGroup('neutral')
239+
$risk->setCustomerGroup(CustomerGroups::NEUTRAL)
232240
->setConfirmedAmount('1234')
233241
->setConfirmedOrders('42')
234242
->setRegistrationLevel('1')
@@ -299,8 +307,7 @@ public function paymentMethodsConfigsDataProvider()
299307
->addMethodConfig(PostFinanceEfinance::class, $enabledConfig)
300308
->addMethodConfig(PostFinanceCard::class, $enabledConfig)
301309
->addMethodConfig(Twint::class, $enabledConfig)
302-
->addMethodConfig(OpenbankingPis::class, $enabledConfig)
303-
;
310+
->addMethodConfig(OpenbankingPis::class, $enabledConfig);
304311

305312
$withPaylaterConfig = (new PaymentMethodsConfigs())
306313
->addMethodConfig(PaylaterInvoice::class, $paylaterConfig);

test/unit/Services/IdServiceTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class IdServiceTest extends BasePaymentTest
1616
*/
1717
public function idWithUniqueIdReturnsTrue(string $id)
1818
{
19-
$isUUID = IdService::isUUDIResource($id);
19+
$isUUID = IdService::isUUIDResource($id);
2020
$this->assertTrue($isUUID);
2121
}
2222

@@ -29,7 +29,7 @@ public function idWithUniqueIdReturnsTrue(string $id)
2929
*/
3030
public function shortIdShouldReturnFalse(string $id)
3131
{
32-
$isUUID = IdService::isUUDIResource($id);
32+
$isUUID = IdService::isUUIDResource($id);
3333
$this->assertFalse($isUUID);
3434
}
3535

0 commit comments

Comments
 (0)