Skip to content

Commit 39a4d4b

Browse files
Formats address of Payer in response into an array before creating Payer entity (#95)
* Changes address type of Payer Entity to be String * Formats Payers response address into an array
1 parent 555c3e5 commit 39a4d4b

File tree

5 files changed

+76
-6
lines changed

5 files changed

+76
-6
lines changed

src/EntryPoint/PayersEntryPoint.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected function createPayerFromResponse($response)
3434
$response->company_name,
3535
$response->first_name,
3636
$response->last_name,
37-
$response->address,
37+
$this->formatAddress($response->address),
3838
$response->city,
3939
$response->state_or_province,
4040
$response->country,
@@ -49,4 +49,12 @@ protected function createPayerFromResponse($response)
4949
$this->setIdProperty($payer, $response->id);
5050
return $payer;
5151
}
52+
53+
private function formatAddress($address) {
54+
if(is_null($address)) {
55+
return null;
56+
} else {
57+
return [$address];
58+
}
59+
}
5260
}

src/Model/Payer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,4 +389,4 @@ public function setUpdatedAt($updatedAt)
389389
$this->updatedAt = $updatedAt;
390390
return $this;
391391
}
392-
}
392+
}

tests/EntryPoint/PayersEntryPointTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ class PayersEntryPointTest extends BaseCurrencyCloudTestCase
1313
*/
1414
public function canRetrieveWithoutOnBehalfOf()
1515
{
16-
$data = '{"id":"543477161-91de-012f-e284-1e0030c7f3123","legal_entity_type":"company","company_name":"Acme Corporation","first_name":"","last_name":"","address":["164 Bishopsgate","London"],"city":"London","state_or_province":"","country":"GB","identification_type":"incorporation_number","identification_value":"123123","postcode":"EC2M 4LX","date_of_birth":"2014-01-12T12:24:19+00:00","created_at":"2014-01-12T12:24:19+00:00","updated_at":"2014-01-12T12:24:19+00:00"}';
16+
$data = '{"id":"543477161-91de-012f-e284-1e0030c7f3123","legal_entity_type":"company","company_name":"Acme Corporation","first_name":"","last_name":"","address":"164 Bishopsgate,London","city":"London","state_or_province":"","country":"GB","identification_type":"incorporation_number","identification_value":"123123","postcode":"EC2M 4LX","date_of_birth":"2014-01-12T12:24:19+00:00","created_at":"2014-01-12T12:24:19+00:00","updated_at":"2014-01-12T12:24:19+00:00"}';
17+
$data2 = '{"id":"543477161-91de-012f-e284-1e0030c7f3123","legal_entity_type":"company","company_name":"Acme Corporation","first_name":"","last_name":"","address":["164 Bishopsgate,London"],"city":"London","state_or_province":"","country":"GB","identification_type":"incorporation_number","identification_value":"123123","postcode":"EC2M 4LX","date_of_birth":"2014-01-12T12:24:19+00:00","created_at":"2014-01-12T12:24:19+00:00","updated_at":"2014-01-12T12:24:19+00:00"}';
1718

1819

1920
$entryPoint = new PayersEntryPoint($this->getMockedClient(
@@ -27,15 +28,16 @@ public function canRetrieveWithoutOnBehalfOf()
2728

2829
$item = $entryPoint->retrieve('hi');
2930

30-
$this->validateObjectStrictName($item, json_decode($data, true));
31+
$this->validateObjectStrictName($item, json_decode($data2, true));
3132
}
3233

3334
/**
3435
* @test
3536
*/
3637
public function canRetrieveWithOnBehalfOf()
3738
{
38-
$data = '{"id":"543477161-91de-012f-e284-1e0030c7f3123","legal_entity_type":"company","company_name":"Acme Corporation","first_name":"","last_name":"","address":["164 Bishopsgate","London"],"city":"London","state_or_province":"","country":"GB","identification_type":"incorporation_number","identification_value":"123123","postcode":"EC2M 4LX","date_of_birth":"2014-01-12T12:24:19+00:00","created_at":"2014-01-12T12:24:19+00:00","updated_at":"2014-01-12T12:24:19+00:00"}';
39+
$data = '{"id":"543477161-91de-012f-e284-1e0030c7f3123","legal_entity_type":"company","company_name":"Acme Corporation","first_name":"","last_name":"","address":"164 Bishopsgate,London","city":"London","state_or_province":"","country":"GB","identification_type":"incorporation_number","identification_value":"123123","postcode":"EC2M 4LX","date_of_birth":"2014-01-12T12:24:19+00:00","created_at":"2014-01-12T12:24:19+00:00","updated_at":"2014-01-12T12:24:19+00:00"}';
40+
$data2 = '{"id":"543477161-91de-012f-e284-1e0030c7f3123","legal_entity_type":"company","company_name":"Acme Corporation","first_name":"","last_name":"","address":["164 Bishopsgate,London"],"city":"London","state_or_province":"","country":"GB","identification_type":"incorporation_number","identification_value":"123123","postcode":"EC2M 4LX","date_of_birth":"2014-01-12T12:24:19+00:00","created_at":"2014-01-12T12:24:19+00:00","updated_at":"2014-01-12T12:24:19+00:00"}';
3941

4042

4143
$entryPoint = new PayersEntryPoint($this->getMockedClient(
@@ -49,6 +51,6 @@ public function canRetrieveWithOnBehalfOf()
4951

5052
$item = $entryPoint->retrieve('hi', 'test');
5153

52-
$this->validateObjectStrictName($item, json_decode($data, true));
54+
$this->validateObjectStrictName($item, json_decode($data2, true));
5355
}
5456
}

tests/VCR/Payers/Test.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
namespace CurrencyCloud\Tests\VCR\Payers;
3+
4+
use CurrencyCloud\Tests\BaseCurrencyCloudVCRTestCase;
5+
use DateTime;
6+
7+
class Test extends BaseCurrencyCloudVCRTestCase {
8+
9+
/**
10+
* @vcr Payers/can_get_payers.yaml
11+
* @test
12+
*/
13+
public function canGetPayer(){
14+
$payer = $this->getAuthenticatedClient()->payers()->retrieve("fa0b6125-6f81-4fc1-8861-544d7d5c9cdf");
15+
$this->assertSame("fa0b6125-6f81-4fc1-8861-544d7d5c9cdf",$payer->getId());
16+
$this->assertSame("individual",$payer->getLegalEntityType());
17+
$this->assertSame(null,$payer->getCompanyName());
18+
$this->assertSame("John",$payer->getFirstName());
19+
$this->assertSame("Test-Payer",$payer->getLastName());
20+
$this->assertSame(["123 Big Street"],$payer->getAddress());
21+
$this->assertSame("London",$payer->getCity());
22+
$this->assertSame(null,$payer->getStateOrProvince());
23+
$this->assertSame("GB",$payer->getCountry());
24+
$this->assertSame("W12",$payer->getPostcode());
25+
$this->assertSame("1969-12-31",$payer->getDateOfBirth()->format("Y-m-d"));
26+
$this->assertSame(null,$payer->getIdentificationType());
27+
$this->assertSame(null,$payer->getIdentificationValue());
28+
$this->assertSame("2020-06-16T16:57:14+00:00",$payer->getCreatedAt()->format(DateTime::RFC3339));
29+
$this->assertSame("2020-06-16T16:57:14+00:00",$payer->getUpdatedAt()->format(DateTime::RFC3339));
30+
}
31+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
-
2+
request:
3+
method: GET
4+
url: 'https://devapi.currencycloud.com/v2/payers/fa0b6125-6f81-4fc1-8861-544d7d5c9cdf'
5+
headers:
6+
X-Auth-Token: 038022bcd2f372cac7bab448db7b5c3b
7+
response:
8+
status: 200
9+
headers:
10+
Date: 'Mon, 05 Nov 2018 09:27:54 GMT'
11+
Content-Type: application/json
12+
X-Request-Id: 0ba3a275-9ac2-47f6-ae6b-5e507946cbd9
13+
body: '{
14+
"id": "fa0b6125-6f81-4fc1-8861-544d7d5c9cdf",
15+
"legal_entity_type": "individual",
16+
"company_name": null,
17+
"first_name": "John",
18+
"last_name": "Test-Payer",
19+
"address": "123 Big Street",
20+
"city": "London",
21+
"state_or_province": null,
22+
"country": "GB",
23+
"postcode": "W12",
24+
"date_of_birth": "1969-12-31",
25+
"identification_type": null,
26+
"identification_value": null,
27+
"created_at": "2020-06-16T16:57:14+00:00",
28+
"updated_at": "2020-06-16T16:57:14+00:00"
29+
}'

0 commit comments

Comments
 (0)