Skip to content

Commit c7f606f

Browse files
authored
Merge pull request #134 from unzerdev/CC-126/liability_shift_indicator
Cc 126/liability shift indicator
2 parents 91cf9ac + 8bb1b77 commit c7f606f

File tree

6 files changed

+87
-2
lines changed

6 files changed

+87
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
1111

1212
* Enable PHP version 8.2 in composer.json.
1313
* Add paypage property to `Payment` class.
14+
* Add constants `\UnzerSDK\Constants\LiabilityShiftIndicator` for valid liability shift indicator values, relevant for card payment.
15+
* Charge and authorize transactions with card can contain that indicator in Api Response. (Accesed like:`$transaction->getAdditionalTransactionData()->card->liability`)
1416

1517
### Changed
1618

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* This file contains the valid Liability shift indicator values
4+
*
5+
* Copyright (C) 2020 - today Unzer E-Com GmbH
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*
19+
* @link https://dev.unzer.com/
20+
*
21+
* @package UnzerSDK\Constants
22+
*/
23+
namespace UnzerSDK\Constants;
24+
25+
class LiabilityShiftIndicator
26+
{
27+
public const ISSUER = 'ISSUER';
28+
public const MERCHANT = 'MERCHANT';
29+
}

src/Services/ResourceService.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,6 @@ public function fetchPayPage($payPage): Paypage
447447
return $payPageObject;
448448
}
449449

450-
451450
/**
452451
* {@inheritDoc}
453452
*/

test/integration/PaymentTypes/CardTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,32 @@ public function cardWith3dsFlagShouldSetItAlsoInTransactions(): void
265265
$this->assertFalse($charge->isCard3ds());
266266
}
267267

268+
/**
269+
* Verify card transaction returns Liability Shift Indicator.
270+
*
271+
* @test
272+
* @dataProvider cardTransactionReturnsLiabilityIndicatorDP()
273+
*/
274+
public function cardTransactionReturnsLiabilityIndicator($pan): void
275+
{
276+
$this->markTestSkipped('Requires a special config for card.');
277+
$card = $this->createCardObject()->setNumber($pan)->set3ds(false);
278+
/** @var Card $card */
279+
$card = $this->unzer->createPaymentType($card);
280+
$charge = $card->charge(12.34, 'EUR', 'https://docs.unzer.com');
281+
282+
// Verify Liability Indicator in response.
283+
$this->assertNotNull($charge->getAdditionalTransactionData());
284+
$this->assertNotNull($charge->getAdditionalTransactionData()->card->liability);
285+
286+
// Verify Liability Indicator In payment response.
287+
$fetchedPayment = $this->unzer->fetchPayment($charge->getPaymentId());
288+
$paymentCharge = $fetchedPayment->getCharge('s-chg-1', true);
289+
$this->assertNotNull($paymentCharge->getAdditionalTransactionData()->card->liability);
290+
291+
$this->getUnzerObject()->fetchCharge($charge);
292+
}
293+
268294
/**
269295
* Verify that the card can perform an authorization with a card.
270296
*
@@ -670,4 +696,14 @@ public function invalidRecurrenceTypesDP(): array
670696
'number' => [42],
671697
];
672698
}
699+
700+
public function cardTransactionReturnsLiabilityIndicatorDP()
701+
{
702+
return [
703+
'6799851000000032' => ['6799851000000032'],
704+
'5453010000059543' => ['5453010000059543'],
705+
'4711100000000000' => ['4711100000000000'],
706+
'4012001037461114' => ['4012001037461114']
707+
];
708+
}
673709
}

test/unit/Resources/PaymentTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ public function handleResponseShouldFetchAndUpdateCustomerIfItIsAlreadySet(): vo
819819
public function handleResponseShouldFetchAndUpdatePayPageIfItIsAlreadySet(): void
820820
{
821821
$payment = (new Payment())->setId('myPaymentId');
822-
$payPage = (new Paypage(0,'',''))->setId('payPageId');
822+
$payPage = (new Paypage(0, '', ''))->setId('payPageId');
823823

824824
$resourceServiceMock = $this->getMockBuilder(ResourceService::class)
825825
->disableOriginalConstructor()->setMethods(['fetchResource'])->getMock();

test/unit/Resources/TransactionTypes/AbstractTransactionTypeTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use PHPUnit\Framework\MockObject\MockObject;
3030
use stdClass;
3131
use UnzerSDK\Adapter\HttpAdapterInterface;
32+
use UnzerSDK\Constants\LiabilityShiftIndicator;
3233
use UnzerSDK\Constants\TransactionStatus;
3334
use UnzerSDK\Resources\Payment;
3435
use UnzerSDK\Resources\TransactionTypes\AbstractTransactionType;
@@ -268,6 +269,24 @@ public function fetchPaymentShouldFetchPaymentObject(): void
268269
$transactionType->fetchPayment();
269270
}
270271

272+
/**
273+
* Liability indicator response should stored in transaction
274+
*
275+
* @test
276+
*/
277+
public function liabilityResponseShouldBeStroedInTransaction()
278+
{
279+
$jsonRespone = '{"additionalTransactionData":{"card":{"liability":"MERCHANT"}}}';
280+
281+
$transaction = new DummyTransactionType();
282+
$transaction->handleResponse(json_decode($jsonRespone, false));
283+
$this->assertEquals($transaction->getAdditionalTransactionData()->card->liability, LiabilityShiftIndicator::MERCHANT);
284+
285+
$jsonRespone = '{"additionalTransactionData":{"card":{"liability":"ISSUER"}}}';
286+
$transaction->handleResponse(json_decode($jsonRespone, false));
287+
$this->assertEquals($transaction->getAdditionalTransactionData()->card->liability, LiabilityShiftIndicator::ISSUER);
288+
}
289+
271290
//<editor-fold desc="Data Providers">
272291

273292
/**

0 commit comments

Comments
 (0)