Skip to content

Commit 2f11c07

Browse files
committed
Add option to send contact first and last names instead of a single string
1 parent b0d3e7b commit 2f11c07

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ Get a business account at Australia Post and request API access
2525
2626
$shipment = $auspost->newShipment()
2727
->setFrom(new \Cognito\Auspost\Address([
28-
'name' => 'Joe Tester',
28+
'first_name' => 'Joe',
29+
'last_name' => 'Tester',
30+
// OR 'name' => 'Joe Tester',
2931
'lines' => [
3032
'11 MyStreetname Court',
3133
],
@@ -35,7 +37,8 @@ Get a business account at Australia Post and request API access
3537
'country' => 'AU',
3638
]))
3739
->setTo(new \Cognito\Auspost\Address([
38-
'name' => 'Mary Tester',
40+
'first_name' => 'Mary',
41+
'last_name' => 'Tester',
3942
'lines' => [
4043
'10 ReceiverStreetname St',
4144
],

src/Address.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* @author Josh Marshall <josh@jmarshall.com.au>
1010
*
1111
* @property string $type
12+
* @property string $first_name
13+
* @property string $last_name
1214
* @property string $name
1315
* @property string $business_name
1416
* @property string[] $lines
@@ -22,6 +24,8 @@
2224
class Address {
2325

2426
public $type = '';
27+
public $first_name = '';
28+
public $last_name = '';
2529
public $name = '';
2630
public $business_name = '';
2731
public $lines = [];
@@ -41,5 +45,18 @@ public function __construct($details = []) {
4145
}
4246
$this->$key = $data;
4347
}
48+
if (!$this->name) {
49+
$this->name = trim($this->first_name . ' ' . $this->last_name);
50+
}
51+
if (!$this->first_name) {
52+
$parts = explode(' ', $this->name, 2);
53+
if (count($parts) > 1) {
54+
$this->first_name = $parts[0];
55+
$this->last_name = $parts[1];
56+
} else {
57+
$this->first_name = $this->name;
58+
$this->last_name = $this->name;
59+
}
60+
}
4461
}
4562
}

src/Auspost.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ private function closeSocket() {
470470
/**
471471
* Convert the lines of response data into an associative array.
472472
*
473-
* @param array $data lines of response data
473+
* @param string $data lines of response data
474474
* @return array associative array
475475
*/
476476
private function convertResponse($data) {

0 commit comments

Comments
 (0)