-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathAddressService.php
More file actions
123 lines (105 loc) · 3.23 KB
/
Copy pathAddressService.php
File metadata and controls
123 lines (105 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
namespace EasyPost\Service;
use EasyPost\Http\HttpMethod;
use EasyPost\Http\Requestor;
use EasyPost\Util\InternalUtil;
/**
* Address service containing all the logic to make API calls.
*/
class AddressService extends BaseService
{
/**
* Retrieve an address.
*
* @param string $id
* @return mixed
*/
public function retrieve(string $id): mixed
{
return self::retrieveResource(self::serviceModelClassName(self::class), $id);
}
/**
* Retrieve all addresses.
*
* @param mixed $params
* @return mixed
*/
public function all(mixed $params = null): mixed
{
return self::allResources(self::serviceModelClassName(self::class), $params);
}
/**
* Retrieve the next page of Address collection
*
* @param mixed $addresses
* @param int|null $pageSize
* @return mixed
*/
public function getNextPage(mixed $addresses, ?int $pageSize = null)
{
return $this->getNextPageResources(self::serviceModelClassName(self::class), $addresses, $pageSize);
}
/**
* Create an address.
*
* @param mixed $params
* @return mixed
*/
public function create(mixed $params = null): mixed
{
$wrappedParams = [];
if (isset($params['verify'])) {
$verify = $params['verify'];
unset($params['verify']);
$wrappedParams['verify'] = $verify;
}
if (isset($params['verify_strict'])) {
$verifyStrict = $params['verify_strict'];
unset($params['verify_strict']);
$wrappedParams['verify_strict'] = $verifyStrict;
}
if (isset($params['verify_carrier'])) {
$verifyCarrier = $params['verify_carrier'];
unset($params['verify_carrier']);
$wrappedParams['verify_carrier'] = $verifyCarrier;
}
$wrappedParams['address'] = $params;
return self::createResource(self::serviceModelClassName(self::class), $wrappedParams);
}
/**
* Create and verify an address.
*
* @param mixed $params
* @return mixed
*/
public function createAndVerify(mixed $params = null): mixed
{
$wrappedParams = [];
if (isset($params['verify_carrier'])) {
$verifyCarrier = $params['verify_carrier'];
unset($params['verify_carrier']);
$wrappedParams['verify_carrier'] = $verifyCarrier;
}
$wrappedParams['address'] = $params;
$url = self::classUrl(self::serviceModelClassName(self::class));
$response = Requestor::request(
$this->client,
HttpMethod::POST,
$url . '/create_and_verify',
$wrappedParams
);
return InternalUtil::convertToEasyPostObject($this->client, $response['address']);
}
/**
* Verify an address.
*
* @param string $id
* @return mixed
*/
public function verify(string $id): mixed
{
$url = $this->instanceUrl(self::serviceModelClassName(self::class), $id) . '/verify';
$response = Requestor::request($this->client, HttpMethod::GET, $url, null);
return InternalUtil::convertToEasyPostObject($this->client, $response['address']);
}
}