Skip to content

Commit 7eab387

Browse files
authored
Merge pull request #202 from unzerdev/CC-1768/open-banking
CC-1768 : Add Open Banking
2 parents 011cc4e + 07245ac commit 7eab387

File tree

9 files changed

+183
-1
lines changed

9 files changed

+183
-1
lines changed

src/Constants/IdStrings.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class IdStrings
5353
public const TWINT = 'twt';
5454
public const WECHATPAY = 'wcp';
5555

56+
public const OPEN_BANKING = 'obp';
57+
5658
// Resources
5759
public const BASKET = 'bsk';
5860
public const CUSTOMER = 'cst';
@@ -93,5 +95,6 @@ class IdStrings
9395
self::SOFORT,
9496
self::TWINT,
9597
self::WECHATPAY,
98+
self::OPEN_BANKING,
9699
];
97100
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace UnzerSDK\Resources\PaymentTypes;
4+
5+
6+
class OpenbankingPis extends BasePaymentType
7+
{
8+
9+
/** @var string|null $ibanCountry */
10+
protected $ibanCountry;
11+
12+
public function __construct(string $ibanCountry = null)
13+
{
14+
$this->ibanCountry = $ibanCountry;
15+
}
16+
17+
/**
18+
* @return string|null
19+
*/
20+
public function getIbanCountry(): ?string
21+
{
22+
return $this->ibanCountry;
23+
}
24+
25+
/**
26+
* @param string|null $ibanCountry
27+
*
28+
* @return OpenbankingPis
29+
*/
30+
public function setIbanCountry(string $ibanCountry): OpenbankingPis
31+
{
32+
$this->ibanCountry = $ibanCountry;
33+
return $this;
34+
}
35+
36+
37+
}

src/Services/ResourceService.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
use UnzerSDK\Resources\PaymentTypes\Invoice;
3535
use UnzerSDK\Resources\PaymentTypes\InvoiceSecured;
3636
use UnzerSDK\Resources\PaymentTypes\Klarna;
37+
use UnzerSDK\Resources\PaymentTypes\OpenbankingPis;
3738
use UnzerSDK\Resources\PaymentTypes\PaylaterDirectDebit;
3839
use UnzerSDK\Resources\PaymentTypes\PaylaterInstallment;
3940
use UnzerSDK\Resources\PaymentTypes\PaylaterInvoice;
@@ -945,6 +946,9 @@ public static function getTypeInstanceFromIdString($typeId): BasePaymentType
945946
case IdStrings::WECHATPAY:
946947
$paymentType = new Wechatpay();
947948
break;
949+
case IdStrings::OPEN_BANKING:
950+
$paymentType = new OpenbankingPis();
951+
break;
948952
default:
949953
throw new RuntimeException('Invalid payment type!');
950954
break;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"ibanCountry": "DE"
3+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"id": "s-obp-q0nucec6itwe",
3+
"method": "openbanking-pis",
4+
"recurring": false,
5+
"geoLocation": {
6+
"clientIp": "0:0:0:0:0:0:0:1",
7+
"countryIsoA2": ""
8+
},
9+
"processing": {
10+
"uniqueId": "31HA07BC8127DC45EE6946C3B070FF71",
11+
"shortId": "5550.0369.6888",
12+
"traceId": "24c0a2ecbe3d54a838c76444d4bdcd1f"
13+
}
14+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
/** @noinspection PhpUnhandledExceptionInspection */
4+
/** @noinspection PhpDocMissingThrowsInspection */
5+
/**
6+
* This class defines integration tests to verify interface and functionality of the payment method paypal.
7+
*
8+
* @link https://docs.unzer.com/
9+
*
10+
*/
11+
12+
namespace UnzerSDK\test\integration\PaymentTypes;
13+
14+
use UnzerSDK\Resources\PaymentTypes\BasePaymentType;
15+
use UnzerSDK\Resources\PaymentTypes\OpenbankingPis;
16+
use UnzerSDK\test\BaseIntegrationTest;
17+
18+
class OpenBankingTest extends BaseIntegrationTest
19+
{
20+
/**
21+
* Verify OpenBanking payment type can be created and fetched.
22+
*
23+
* @test
24+
*
25+
* @return BasePaymentType
26+
*/
27+
public function openBankingShouldBeCreatableAndFetchable(): BasePaymentType
28+
{
29+
$openBanking = $this->unzer->createPaymentType(new OpenbankingPis('DE'));
30+
$this->assertInstanceOf(OpenbankingPis::class, $openBanking);
31+
$this->assertNotEmpty($openBanking->getId());
32+
33+
$fetchedOpenBanking = $this->unzer->fetchPaymentType($openBanking->getId());
34+
$this->assertInstanceOf(OpenbankingPis::class, $fetchedOpenBanking);
35+
$this->assertNotSame($openBanking, $fetchedOpenBanking);
36+
$this->assertEquals($openBanking->expose(), $fetchedOpenBanking->expose());
37+
38+
return $fetchedOpenBanking;
39+
}
40+
41+
42+
43+
/**
44+
* Verify OpenBanking can charge.
45+
*
46+
* @test
47+
*
48+
* @depends openBankingShouldBeCreatableAndFetchable
49+
*
50+
* @param OpenbankingPis $openBanking
51+
*/
52+
public function openBankingShouldBeChargeable(OpenbankingPis $openBanking): void
53+
{
54+
$charge = $this->unzer->performCharge(100.0, 'EUR', self::RETURN_URL);
55+
$this->assertNotNull($charge);
56+
$this->assertNotEmpty($charge->getId());
57+
}
58+
59+
60+
}

test/integration/Resources/PaypageV2Test.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use UnzerSDK\Resources\PaymentTypes\Googlepay;
2020
use UnzerSDK\Resources\PaymentTypes\Ideal;
2121
use UnzerSDK\Resources\PaymentTypes\Klarna;
22+
use UnzerSDK\Resources\PaymentTypes\OpenbankingPis;
2223
use UnzerSDK\Resources\PaymentTypes\PaylaterDirectDebit;
2324
use UnzerSDK\Resources\PaymentTypes\PaylaterInstallment;
2425
use UnzerSDK\Resources\PaymentTypes\PaylaterInvoice;
@@ -295,7 +296,9 @@ public function paymentMethodsConfigsDataProvider()
295296
->addMethodConfig(Bancontact::class, $enabledConfig)
296297
->addMethodConfig(PostFinanceEfinance::class, $enabledConfig)
297298
->addMethodConfig(PostFinanceCard::class, $enabledConfig)
298-
->addMethodConfig(Twint::class, $enabledConfig);
299+
->addMethodConfig(Twint::class, $enabledConfig)
300+
->addMethodConfig(OpenbankingPis::class, $enabledConfig)
301+
;
299302

300303
$withPaylaterConfig = (new PaymentMethodsConfigs())
301304
->addMethodConfig(PaylaterInvoice::class, $paylaterConfig);
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace UnzerSDK\test\unit\Resources\PaymentTypes;
4+
5+
use UnzerSDK\Resources\PaymentTypes\OpenbankingPis;
6+
use UnzerSDK\test\BasePaymentTest;
7+
use UnzerSDK\test\Fixtures\JsonProvider;
8+
9+
class OpenBankingTest extends BasePaymentTest
10+
{
11+
/**
12+
* Verify the resource data is set properly.
13+
*
14+
* @test
15+
*/
16+
public function constructorShouldSetParameters(): void
17+
{
18+
$countryCode = 'DE';
19+
20+
$openBanking = new OpenbankingPis($countryCode);
21+
22+
23+
$this->assertEquals($countryCode, $openBanking->getIbanCountry());
24+
}
25+
26+
/**
27+
* Test OpenBanking json serialization.
28+
*
29+
* @test
30+
*/
31+
public function jsonSerialization(): void
32+
{
33+
$openBankingObject = new OpenbankingPis("DE",);
34+
35+
$expectedJson = JsonProvider::getJsonFromFile('openBanking/createRequest.json');
36+
$this->assertJsonStringEqualsJsonString($expectedJson, $openBankingObject->jsonSerialize());
37+
}
38+
39+
/**
40+
* Test OpenBanking json response handling.
41+
*
42+
* @test
43+
*/
44+
public function openBankingAuthorizationShouldBeMappedCorrectly(): void
45+
{
46+
$openBanking = new OpenbankingPis('DE');
47+
48+
$jsonResponse = JsonProvider::getJsonFromFile('openBanking/fetchResponse.json');
49+
50+
$jsonObject = json_decode($jsonResponse, false, 512, JSON_THROW_ON_ERROR);
51+
$openBanking->handleResponse($jsonObject);
52+
53+
$this->assertEquals('s-obp-q0nucec6itwe', $openBanking->getId());
54+
}
55+
}

test/unit/Services/ResourceServiceTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
use UnzerSDK\Resources\PaymentTypes\Invoice;
3838
use UnzerSDK\Resources\PaymentTypes\InvoiceSecured;
3939
use UnzerSDK\Resources\PaymentTypes\Klarna;
40+
use UnzerSDK\Resources\PaymentTypes\OpenbankingPis;
4041
use UnzerSDK\Resources\PaymentTypes\PaylaterInvoice;
4142
use UnzerSDK\Resources\PaymentTypes\Paypal;
4243
use UnzerSDK\Resources\PaymentTypes\PIS;
@@ -1424,6 +1425,7 @@ public function fetchShouldCallFetchResourceDP(): array
14241425
'PaymentType HirePurchaseDirectDebit sandbox' => ['fetchPaymentType', ['s-hdd-12345678'], $getPaymentTypeCB(InstallmentSecured::class)],
14251426
'PaymentType InstallmentSecured sandbox' => ['fetchPaymentType', ['s-ins-12345678'], $getPaymentTypeCB(InstallmentSecured::class)],
14261427
'PaymentType Bancontact sandbox' => ['fetchPaymentType', ['s-bct-12345678'], $getPaymentTypeCB(Bancontact::class)],
1428+
'PaymentType OpenBanking sandbox' => ['fetchPaymentType', ['s-obp-12345678'], $getPaymentTypeCB(OpenbankingPis::class)],
14271429
'PaymentType Alipay production' => ['fetchPaymentType', ['p-ali-12345678'], $getPaymentTypeCB(Alipay::class)],
14281430
'PaymentType Bancontact production' => ['fetchPaymentType', ['p-bct-12345678'], $getPaymentTypeCB(Bancontact::class)],
14291431
'PaymentType Card production' => ['fetchPaymentType', ['p-crd-12345678'], $getPaymentTypeCB(Card::class)],
@@ -1446,6 +1448,7 @@ public function fetchShouldCallFetchResourceDP(): array
14461448
'PaymentType SepaDirectDebitSecured production' => ['fetchPaymentType', ['p-dds-12345678'], $getPaymentTypeCB(SepaDirectDebitSecured::class)],
14471449
'PaymentType Sofort production' => ['fetchPaymentType', ['p-sft-12345678'], $getPaymentTypeCB(Sofort::class)],
14481450
'PaymentType Wechatpay production' => ['fetchPaymentType', ['p-wcp-12345678'], $getPaymentTypeCB(Wechatpay::class)],
1451+
'PaymentType OpenBanking production' => ['fetchPaymentType', ['p-obp-12345678'], $getPaymentTypeCB(OpenbankingPis::class)],
14491452
];
14501453
}
14511454

0 commit comments

Comments
 (0)