Skip to content

Commit 7090de7

Browse files
committed
[CC-2016] Add customerV2 resource.
1 parent 274650b commit 7090de7

File tree

5 files changed

+536
-7
lines changed

5 files changed

+536
-7
lines changed

src/Apis/PaymentApiJwtConfig.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace UnzerSDK\Apis;
4+
5+
use UnzerSDK\Apis\Constants\AuthorizationMethods;
6+
7+
8+
/**
9+
* Config for Payment API (PAPI).
10+
*/
11+
class PaymentApiJwtConfig implements ApiConfig
12+
{
13+
private const DOMAIN = 'api.unzer.com';
14+
private const TEST_DOMAIN = 'sbx-api.unzer.com';
15+
private const INT_DOMAIN = 'stg-api.unzer.com';
16+
17+
public static function getDomain(): string
18+
{
19+
return self::DOMAIN;
20+
}
21+
22+
public static function getIntegrationDomain(): string
23+
{
24+
return self::INT_DOMAIN;
25+
}
26+
27+
public static function getTestDomain(): string
28+
{
29+
return self::TEST_DOMAIN;
30+
}
31+
32+
public static function getAuthorizationMethod(): string
33+
{
34+
return AuthorizationMethods::BEARER;
35+
}
36+
}

src/Resources/CustomerFactory.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use UnzerSDK\Constants\CompanyRegistrationTypes;
77
use UnzerSDK\Resources\EmbeddedResources\Address;
88
use UnzerSDK\Resources\EmbeddedResources\CompanyInfo;
9+
use UnzerSDK\Resources\V2\Customer as CustomerV2;
910

1011
/**
1112
* Creates the different Customer objects.
@@ -15,6 +16,18 @@
1516
*/
1617
class CustomerFactory
1718
{
19+
private static int $version = 1;
20+
21+
public static function setVersion(int $version): void
22+
{
23+
self::$version = $version;
24+
}
25+
26+
public static function getVersion(): int
27+
{
28+
return self::$version;
29+
}
30+
1831
/**
1932
* Creates a local Customer object for B2C transactions.
2033
* Please use Unzer::createCustomer(...) to create the customer resource on the API side.
@@ -26,7 +39,7 @@ class CustomerFactory
2639
*/
2740
public static function createCustomer(string $firstname, string $lastname): Customer
2841
{
29-
return (new Customer())->setFirstname($firstname)->setLastname($lastname);
42+
return self::getCustomer()->setFirstname($firstname)->setLastname($lastname);
3043
}
3144

3245
/**
@@ -58,7 +71,7 @@ public static function createNotRegisteredB2bCustomer(
5871
->setFunction('OWNER')
5972
->setCommercialSector($commercialSector);
6073

61-
return (new Customer())
74+
return self::getCustomer()
6275
->setFirstname($firstname)
6376
->setLastname($lastname)
6477
->setBirthDate($birthDate)
@@ -89,9 +102,17 @@ public static function createRegisteredB2bCustomer(
89102
->setCommercialRegisterNumber($commercialRegisterNumber)
90103
->setCommercialSector($commercialSector);
91104

92-
return (new Customer())
105+
return self::getCustomer()
93106
->setCompany($company)
94107
->setBillingAddress($billingAddress)
95108
->setCompanyInfo($companyInfo);
96109
}
110+
111+
/**
112+
* @return Customer
113+
*/
114+
protected static function getCustomer(): Customer
115+
{
116+
return (self::$version == 2) ? new CustomerV2() : new Customer();
117+
}
97118
}

src/Resources/V2/Customer.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace UnzerSDK\Resources\V2;
4+
5+
use UnzerSDK\Apis\PaymentApiJwtConfig;
6+
use UnzerSDK\Resources\Customer as CustomerV1;
7+
8+
class Customer extends CustomerV1
9+
{
10+
public function getApiVersion(): string
11+
{
12+
return "v2";
13+
}
14+
15+
public function getApiConfig(): string
16+
{
17+
return PaymentApiJwtConfig::class;
18+
}
19+
20+
21+
}

test/Fixtures/CustomerFixtureTrait.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function getMaximumCustomer(): Customer
5757
*/
5858
public function getMaximumCustomerInclShippingAddress(): Customer
5959
{
60-
return $this->getMaximumCustomer()->setShippingAddress($this->getShippingAddress());
60+
return $this->getMaximumCustomer($version)->setShippingAddress($this->getShippingAddress());
6161
}
6262

6363
/**
@@ -74,7 +74,8 @@ public function getMinimalNotRegisteredB2bCustomer(): Customer
7474
$this->getBillingAddress(),
7575
7676
'Unzer GmbH',
77-
CompanyCommercialSectorItems::WAREHOUSING_AND_SUPPORT_ACTIVITIES_FOR_TRANSPORTATION
77+
CompanyCommercialSectorItems::WAREHOUSING_AND_SUPPORT_ACTIVITIES_FOR_TRANSPORTATION,
78+
$version
7879
);
7980
}
8081

@@ -85,7 +86,7 @@ public function getMinimalNotRegisteredB2bCustomer(): Customer
8586
*/
8687
public function getMaximalNotRegisteredB2bCustomer(): Customer
8788
{
88-
$customer = $this->getMinimalNotRegisteredB2bCustomer()
89+
$customer = $this->getMinimalNotRegisteredB2bCustomer($version)
8990
->setShippingAddress($this->getShippingAddress())
9091
->setSalutation(Salutations::MR)
9192
->setMobile('+49172123456')
@@ -111,7 +112,7 @@ public function getMaximalNotRegisteredB2bCustomer(): Customer
111112
*/
112113
public function getMinimalRegisteredB2bCustomer(): Customer
113114
{
114-
return CustomerFactory::createRegisteredB2bCustomer($this->getBillingAddress(), '123456789', 'Unzer GmbH');
115+
return CustomerFactory::createRegisteredB2bCustomer($this->getBillingAddress(), '123456789', 'Unzer GmbH', CompanyCommercialSectorItems::OTHER, $version);
115116
}
116117

117118
/**

0 commit comments

Comments
 (0)