Skip to content

Commit fefa3f3

Browse files
feature/INT-1655 - Support for negotiating Accounts API schema version via the Accept header (#351)
* New accept header for Accounts * Account 3.0 models * Accounts 3.0 schema test fixes * php doc + test completion * Completion of schemas and tests * doc precission fix + test examples extension
1 parent 321a822 commit fefa3f3

24 files changed

Lines changed: 1414 additions & 119 deletions

lib/Checkout/Accounts/AccountsClient.php

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ class AccountsClient extends Client
2525
const RESERVE_RULES_PATH = "reserve-rules";
2626
const REQUIREMENTS_PATH = "requirements";
2727

28+
/**
29+
* The latest Accounts API schema version, negotiated through the Accept header.
30+
*/
31+
const DEFAULT_SCHEMA_VERSION = "3.0";
32+
2833
private $filesApiClient;
2934

3035
public function __construct(
@@ -36,17 +41,33 @@ public function __construct(
3641
$this->filesApiClient = $filesApiClient;
3742
}
3843

44+
/**
45+
* Build the Accept header used to negotiate the Accounts API schema version.
46+
*
47+
* @param string $schemaVersion
48+
* @return Headers
49+
*/
50+
private function buildSchemaVersionHeaders($schemaVersion)
51+
{
52+
$headers = new Headers();
53+
$headers->accept = "application/json;schema_version=" . $schemaVersion;
54+
return $headers;
55+
}
56+
3957
/**
4058
* @param OnboardEntityRequest $entityRequest
59+
* @param string $schemaVersion The Accounts API schema version to request (default: latest, 3.0)
4160
* @return array
4261
* @throws CheckoutApiException
4362
*/
44-
public function createEntity(OnboardEntityRequest $entityRequest)
63+
public function createEntity(OnboardEntityRequest $entityRequest, $schemaVersion = self::DEFAULT_SCHEMA_VERSION)
4564
{
4665
return $this->apiClient->post(
4766
$this->buildPath(self::ACCOUNTS_PATH, self::ENTITIES_PATH),
4867
$entityRequest,
49-
$this->sdkAuthorization()
68+
$this->sdkAuthorization(),
69+
null,
70+
$this->buildSchemaVersionHeaders($schemaVersion)
5071
);
5172
}
5273

@@ -66,29 +87,36 @@ public function retrievePaymentInstrumentDetails($entityId, $paymentInstrumentId
6687

6788
/**
6889
* @param $entityId
90+
* @param string $schemaVersion The Accounts API schema version to request (default: latest, 3.0)
6991
* @return array
7092
* @throws CheckoutApiException
7193
*/
72-
public function getEntity($entityId)
94+
public function getEntity($entityId, $schemaVersion = self::DEFAULT_SCHEMA_VERSION)
7395
{
7496
return $this->apiClient->get(
7597
$this->buildPath(self::ACCOUNTS_PATH, self::ENTITIES_PATH, $entityId),
76-
$this->sdkAuthorization()
98+
$this->sdkAuthorization(),
99+
$this->buildSchemaVersionHeaders($schemaVersion)
77100
);
78101
}
79102

80103
/**
81104
* @param $entityId
82105
* @param OnboardEntityRequest $entityRequest
106+
* @param string $schemaVersion The Accounts API schema version to request (default: latest, 3.0)
83107
* @return array
84108
* @throws CheckoutApiException
85109
*/
86-
public function updateEntity($entityId, OnboardEntityRequest $entityRequest)
87-
{
110+
public function updateEntity(
111+
$entityId,
112+
OnboardEntityRequest $entityRequest,
113+
$schemaVersion = self::DEFAULT_SCHEMA_VERSION
114+
) {
88115
return $this->apiClient->put(
89116
$this->buildPath(self::ACCOUNTS_PATH, self::ENTITIES_PATH, $entityId),
90117
$entityRequest,
91-
$this->sdkAuthorization()
118+
$this->sdkAuthorization(),
119+
$this->buildSchemaVersionHeaders($schemaVersion)
92120
);
93121
}
94122

@@ -361,14 +389,16 @@ public function retrieveFile($entityId, $fileId)
361389
* Retrieve the list of pending requirements for a sub-entity.
362390
*
363391
* @param string $entityId The sub-entity's ID (Required)
392+
* @param string $schemaVersion The Accounts API schema version to request (default: latest, 3.0)
364393
* @return array
365394
* @throws CheckoutApiException
366395
*/
367-
public function getEntityRequirements($entityId)
396+
public function getEntityRequirements($entityId, $schemaVersion = self::DEFAULT_SCHEMA_VERSION)
368397
{
369398
return $this->apiClient->get(
370399
$this->buildPath(self::ACCOUNTS_PATH, self::ENTITIES_PATH, $entityId, self::REQUIREMENTS_PATH),
371-
$this->sdkAuthorization()
400+
$this->sdkAuthorization(),
401+
$this->buildSchemaVersionHeaders($schemaVersion)
372402
);
373403
}
374404

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace Checkout\Accounts;
4+
5+
/**
6+
* The terms of service the sub-entity agreed to (Accounts API v3.0, SaaS onboarding).
7+
*/
8+
class AgreedTerms
9+
{
10+
/**
11+
* The date and time the terms were agreed.
12+
* [Required]
13+
* Format: date-time (RFC 3339)
14+
*
15+
* @var string
16+
*/
17+
public $date;
18+
19+
/**
20+
* The IP address from which the terms were agreed.
21+
* [Required]
22+
*
23+
* @var string
24+
*/
25+
public $ip_address;
26+
27+
/**
28+
* The name of the person who agreed to the terms.
29+
* [Required]
30+
*
31+
* @var string
32+
*/
33+
public $name;
34+
35+
/**
36+
* The email address of the person who agreed to the terms.
37+
* [Required]
38+
* Format: email
39+
*
40+
* @var string
41+
*/
42+
public $email;
43+
44+
/**
45+
* The version of the terms that were agreed.
46+
* [Required]
47+
*
48+
* @var string
49+
*/
50+
public $version;
51+
}

lib/Checkout/Accounts/BusinessType.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,23 @@
44

55
class BusinessType
66
{
7+
public static $individual_or_sole_proprietorship = "individual_or_sole_proprietorship";
78
public static $general_partnership = "general_partnership";
89
public static $limited_partnership = "limited_partnership";
10+
public static $scottish_limited_partnership = "scottish_limited_partnership";
911
public static $public_limited_company = "public_limited_company";
1012
public static $limited_company = "limited_company";
13+
public static $limited_liability_corporation = "limited_liability_corporation";
14+
public static $private_corporation = "private_corporation";
15+
public static $publicly_traded_corporation = "publicly_traded_corporation";
1116
public static $professional_association = "professional_association";
1217
public static $unincorporated_association = "unincorporated_association";
1318
public static $auto_entrepreneur = "auto_entrepreneur";
19+
public static $government_agency = "government_agency";
20+
public static $non_profit_entity = "non_profit_entity";
21+
public static $trust = "trust";
22+
public static $club_or_society = "club_or_society";
23+
public static $regulated_financial_institution = "regulated_financial_institution";
24+
public static $cftc_registered_entity = "cftc_registered_entity";
25+
public static $sec_registered_entity = "sec_registered_entity";
1426
}

lib/Checkout/Accounts/Company.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,121 @@
44

55
use Checkout\Common\Address;
66

7+
/**
8+
* Information about the company represented by a sub-entity.
9+
* Which fields are required depends on the sub-entity's region and onboarding variant.
10+
*/
711
class Company
812
{
913
/**
14+
* The company's registration number.
15+
* [Required]
16+
* Format: region-specific (validated by the API against the sub-entity's country)
17+
*
1018
* @var string
1119
*/
1220
public $business_registration_number;
1321

1422
/**
23+
* The company's business type.
24+
* [Required]
25+
* Enum: "individual_or_sole_proprietorship", "limited_company", "public_limited_company",
26+
* "limited_partnership", "general_partnership", "scottish_limited_partnership",
27+
* "government_agency", "non_profit_entity", "trust", "club_or_society",
28+
* "unincorporated_association"
29+
*
1530
* @var string value of BusinessType
1631
*/
1732
public $business_type;
1833

1934
/**
35+
* The company's registered legal name.
36+
* [Required]
37+
* Length: 2 to 300 characters
38+
*
2039
* @var string
2140
*/
2241
public $legal_name;
2342

2443
/**
44+
* The name the company trades under.
45+
* [Required]
46+
* Length: 2 to 300 characters
47+
*
2548
* @var string
2649
*/
2750
public $trading_name;
2851

2952
/**
53+
* Additional names the company trades under.
54+
* [Optional]
55+
* Format: array of string (Accounts API v3.0)
56+
*
57+
* @var array of string
58+
*/
59+
public $additional_trading_names;
60+
61+
/**
62+
* Indicates whether the sub-entity is a registered legal entity.
63+
* [Optional] (Accounts API v3.0)
64+
*
65+
* @var bool
66+
*/
67+
public $is_registered_company;
68+
69+
/**
70+
* The regulatory licence number of the company.
71+
* [Optional]
72+
* Length: max 32 characters
73+
*
74+
* @var string
75+
*/
76+
public $regulatory_licence_number;
77+
78+
/**
79+
* The date the company was incorporated.
80+
* [Required] for the full onboarding variants (Accounts API v3.0)
81+
*
82+
* @var DateOfIncorporation
83+
*/
84+
public $date_of_incorporation;
85+
86+
/**
87+
* The company's principal (place of business) address.
88+
* [Required]
89+
*
3090
* @var Address
3191
*/
3292
public $principal_address;
3393

3494
/**
95+
* The company's registered address.
96+
* [Required]
97+
*
3598
* @var Address
3699
*/
37100
public $registered_address;
38101

39102
/**
103+
* A company verification document.
104+
* [Optional]
105+
*
40106
* @var EntityDocument
41107
*/
42108
public $document;
43109

44110
/**
111+
* The company's representatives (persons of interest).
112+
* [Required]
113+
*
45114
* @var array of Representative
46115
*/
47116
public $representatives;
48117

49118
/**
119+
* The company's financial details.
120+
* [Optional]
121+
*
50122
* @var EntityFinancialDetails
51123
*/
52124
public $financial_details;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Checkout\Accounts;
4+
5+
class CompanyPosition
6+
{
7+
public static $ceo = "ceo";
8+
public static $cfo = "cfo";
9+
public static $coo = "coo";
10+
public static $managing_member = "managing_member";
11+
public static $general_partner = "general_partner";
12+
public static $president = "president";
13+
public static $vice_president = "vice_president";
14+
public static $treasurer = "treasurer";
15+
public static $other_senior_management = "other_senior_management";
16+
public static $other_executive_officer = "other_executive_officer";
17+
public static $other_non_executive_non_senior = "other_non_executive_non_senior";
18+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Checkout\Accounts;
4+
5+
/**
6+
* The date a company was incorporated (Accounts API v3.0).
7+
*/
8+
class DateOfIncorporation
9+
{
10+
/**
11+
* The day of the month the company was incorporated.
12+
* [Optional]
13+
* Range: 1 to 31
14+
*
15+
* @var int
16+
*/
17+
public $day;
18+
19+
/**
20+
* The month the company was incorporated.
21+
* [Required]
22+
* Range: 1 to 12
23+
*
24+
* @var int
25+
*/
26+
public $month;
27+
28+
/**
29+
* The year the company was incorporated.
30+
* [Required]
31+
* Range: 1500 to 2999
32+
*
33+
* @var int
34+
*/
35+
public $year;
36+
}

lib/Checkout/Accounts/EntityRoles.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ class EntityRoles
66
{
77
public static $ubo = "ubo";
88
public static $legal_representative = "legal_representative";
9+
public static $authorised_signatory = "authorised_signatory";
10+
public static $director = "director";
11+
public static $control_person = "control_person";
912
}

lib/Checkout/Accounts/Headers.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,18 @@
55
class Headers
66
{
77
/**
8+
* Value for the If-Match header, used to identify a specific version of a
9+
* reserve rule to update (for example "Y3Y9MCZydj0w"). Etag.
10+
*
811
* @var string
912
*/
1013
public $if_match;
14+
15+
/**
16+
* Value for the Accept header, used to negotiate the Accounts API schema version
17+
* (for example "application/json;schema_version=3.0").
18+
*
19+
* @var string
20+
*/
21+
public $accept;
1122
}

0 commit comments

Comments
 (0)