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
3 changes: 3 additions & 0 deletions src/Constants/IdStrings.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class IdStrings
public const TWINT = 'twt';
public const WECHATPAY = 'wcp';

public const OPEN_BANKING = 'obp';

// Resources
public const BASKET = 'bsk';
public const CUSTOMER = 'cst';
Expand Down Expand Up @@ -93,5 +95,6 @@ class IdStrings
self::SOFORT,
self::TWINT,
self::WECHATPAY,
self::OPEN_BANKING,
];
}
37 changes: 37 additions & 0 deletions src/Resources/PaymentTypes/OpenbankingPis.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace UnzerSDK\Resources\PaymentTypes;


class OpenbankingPis extends BasePaymentType
{

/** @var string|null $ibanCountry */
protected $ibanCountry;

public function __construct(string $ibanCountry = null)
{
$this->ibanCountry = $ibanCountry;
}

/**
* @return string|null
*/
public function getIbanCountry(): ?string
{
return $this->ibanCountry;
}

/**
* @param string|null $ibanCountry
*
* @return OpenbankingPis
*/
public function setIbanCountry(string $ibanCountry): OpenbankingPis
{
$this->ibanCountry = $ibanCountry;
return $this;
}


}
4 changes: 4 additions & 0 deletions src/Services/ResourceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use UnzerSDK\Resources\PaymentTypes\Invoice;
use UnzerSDK\Resources\PaymentTypes\InvoiceSecured;
use UnzerSDK\Resources\PaymentTypes\Klarna;
use UnzerSDK\Resources\PaymentTypes\OpenbankingPis;
use UnzerSDK\Resources\PaymentTypes\PaylaterDirectDebit;
use UnzerSDK\Resources\PaymentTypes\PaylaterInstallment;
use UnzerSDK\Resources\PaymentTypes\PaylaterInvoice;
Expand Down Expand Up @@ -945,6 +946,9 @@ public static function getTypeInstanceFromIdString($typeId): BasePaymentType
case IdStrings::WECHATPAY:
$paymentType = new Wechatpay();
break;
case IdStrings::OPEN_BANKING:
$paymentType = new OpenbankingPis();
break;
default:
throw new RuntimeException('Invalid payment type!');
break;
Expand Down
3 changes: 3 additions & 0 deletions test/Fixtures/jsonData/openBanking/createRequest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ibanCountry": "DE"
}
14 changes: 14 additions & 0 deletions test/Fixtures/jsonData/openBanking/fetchResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"id": "s-obp-q0nucec6itwe",
"method": "openbanking-pis",
"recurring": false,
"geoLocation": {
"clientIp": "0:0:0:0:0:0:0:1",
"countryIsoA2": ""
},
"processing": {
"uniqueId": "31HA07BC8127DC45EE6946C3B070FF71",
"shortId": "5550.0369.6888",
"traceId": "24c0a2ecbe3d54a838c76444d4bdcd1f"
}
}
60 changes: 60 additions & 0 deletions test/integration/PaymentTypes/OpenBankingTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

/** @noinspection PhpUnhandledExceptionInspection */
/** @noinspection PhpDocMissingThrowsInspection */
/**
* This class defines integration tests to verify interface and functionality of the payment method paypal.
*
* @link https://docs.unzer.com/
*
*/

namespace UnzerSDK\test\integration\PaymentTypes;

use UnzerSDK\Resources\PaymentTypes\BasePaymentType;
use UnzerSDK\Resources\PaymentTypes\OpenbankingPis;
use UnzerSDK\test\BaseIntegrationTest;

class OpenBankingTest extends BaseIntegrationTest
{
/**
* Verify OpenBanking payment type can be created and fetched.
*
* @test
*
* @return BasePaymentType
*/
public function openBankingShouldBeCreatableAndFetchable(): BasePaymentType
{
$openBanking = $this->unzer->createPaymentType(new OpenbankingPis('DE'));
$this->assertInstanceOf(OpenbankingPis::class, $openBanking);
$this->assertNotEmpty($openBanking->getId());

$fetchedOpenBanking = $this->unzer->fetchPaymentType($openBanking->getId());
$this->assertInstanceOf(OpenbankingPis::class, $fetchedOpenBanking);
$this->assertNotSame($openBanking, $fetchedOpenBanking);
$this->assertEquals($openBanking->expose(), $fetchedOpenBanking->expose());

return $fetchedOpenBanking;
}



/**
* Verify OpenBanking can charge.
*
* @test
*
* @depends openBankingShouldBeCreatableAndFetchable
*
* @param OpenbankingPis $openBanking
*/
public function openBankingShouldBeChargeable(OpenbankingPis $openBanking): void
{
$charge = $this->unzer->performCharge(100.0, 'EUR', self::RETURN_URL);
$this->assertNotNull($charge);
$this->assertNotEmpty($charge->getId());
}


}
5 changes: 4 additions & 1 deletion test/integration/Resources/PaypageV2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use UnzerSDK\Resources\PaymentTypes\Googlepay;
use UnzerSDK\Resources\PaymentTypes\Ideal;
use UnzerSDK\Resources\PaymentTypes\Klarna;
use UnzerSDK\Resources\PaymentTypes\OpenbankingPis;
use UnzerSDK\Resources\PaymentTypes\PaylaterDirectDebit;
use UnzerSDK\Resources\PaymentTypes\PaylaterInstallment;
use UnzerSDK\Resources\PaymentTypes\PaylaterInvoice;
Expand Down Expand Up @@ -295,7 +296,9 @@ public function paymentMethodsConfigsDataProvider()
->addMethodConfig(Bancontact::class, $enabledConfig)
->addMethodConfig(PostFinanceEfinance::class, $enabledConfig)
->addMethodConfig(PostFinanceCard::class, $enabledConfig)
->addMethodConfig(Twint::class, $enabledConfig);
->addMethodConfig(Twint::class, $enabledConfig)
->addMethodConfig(OpenbankingPis::class, $enabledConfig)
;

$withPaylaterConfig = (new PaymentMethodsConfigs())
->addMethodConfig(PaylaterInvoice::class, $paylaterConfig);
Expand Down
55 changes: 55 additions & 0 deletions test/unit/Resources/PaymentTypes/OpenBankingTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace UnzerSDK\test\unit\Resources\PaymentTypes;

use UnzerSDK\Resources\PaymentTypes\OpenbankingPis;
use UnzerSDK\test\BasePaymentTest;
use UnzerSDK\test\Fixtures\JsonProvider;

class OpenBankingTest extends BasePaymentTest
{
/**
* Verify the resource data is set properly.
*
* @test
*/
public function constructorShouldSetParameters(): void
{
$countryCode = 'DE';

$openBanking = new OpenbankingPis($countryCode);


$this->assertEquals($countryCode, $openBanking->getIbanCountry());
}

/**
* Test OpenBanking json serialization.
*
* @test
*/
public function jsonSerialization(): void
{
$openBankingObject = new OpenbankingPis("DE",);

$expectedJson = JsonProvider::getJsonFromFile('openBanking/createRequest.json');
$this->assertJsonStringEqualsJsonString($expectedJson, $openBankingObject->jsonSerialize());
}

/**
* Test OpenBanking json response handling.
*
* @test
*/
public function openBankingAuthorizationShouldBeMappedCorrectly(): void
{
$openBanking = new OpenbankingPis('DE');

$jsonResponse = JsonProvider::getJsonFromFile('openBanking/fetchResponse.json');

$jsonObject = json_decode($jsonResponse, false, 512, JSON_THROW_ON_ERROR);
$openBanking->handleResponse($jsonObject);

$this->assertEquals('s-obp-q0nucec6itwe', $openBanking->getId());
}
}
3 changes: 3 additions & 0 deletions test/unit/Services/ResourceServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use UnzerSDK\Resources\PaymentTypes\Invoice;
use UnzerSDK\Resources\PaymentTypes\InvoiceSecured;
use UnzerSDK\Resources\PaymentTypes\Klarna;
use UnzerSDK\Resources\PaymentTypes\OpenbankingPis;
use UnzerSDK\Resources\PaymentTypes\PaylaterInvoice;
use UnzerSDK\Resources\PaymentTypes\Paypal;
use UnzerSDK\Resources\PaymentTypes\PIS;
Expand Down Expand Up @@ -1424,6 +1425,7 @@ public function fetchShouldCallFetchResourceDP(): array
'PaymentType HirePurchaseDirectDebit sandbox' => ['fetchPaymentType', ['s-hdd-12345678'], $getPaymentTypeCB(InstallmentSecured::class)],
'PaymentType InstallmentSecured sandbox' => ['fetchPaymentType', ['s-ins-12345678'], $getPaymentTypeCB(InstallmentSecured::class)],
'PaymentType Bancontact sandbox' => ['fetchPaymentType', ['s-bct-12345678'], $getPaymentTypeCB(Bancontact::class)],
'PaymentType OpenBanking sandbox' => ['fetchPaymentType', ['s-obp-12345678'], $getPaymentTypeCB(OpenbankingPis::class)],
'PaymentType Alipay production' => ['fetchPaymentType', ['p-ali-12345678'], $getPaymentTypeCB(Alipay::class)],
'PaymentType Bancontact production' => ['fetchPaymentType', ['p-bct-12345678'], $getPaymentTypeCB(Bancontact::class)],
'PaymentType Card production' => ['fetchPaymentType', ['p-crd-12345678'], $getPaymentTypeCB(Card::class)],
Expand All @@ -1446,6 +1448,7 @@ public function fetchShouldCallFetchResourceDP(): array
'PaymentType SepaDirectDebitSecured production' => ['fetchPaymentType', ['p-dds-12345678'], $getPaymentTypeCB(SepaDirectDebitSecured::class)],
'PaymentType Sofort production' => ['fetchPaymentType', ['p-sft-12345678'], $getPaymentTypeCB(Sofort::class)],
'PaymentType Wechatpay production' => ['fetchPaymentType', ['p-wcp-12345678'], $getPaymentTypeCB(Wechatpay::class)],
'PaymentType OpenBanking production' => ['fetchPaymentType', ['p-obp-12345678'], $getPaymentTypeCB(OpenbankingPis::class)],
];
}

Expand Down
Loading