@@ -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
0 commit comments