Skip to content

Commit

Permalink
Add option to send contact first and last names instead of a single s…
Browse files Browse the repository at this point in the history
…tring
  • Loading branch information
joshbmarshall committed Jun 14, 2021
1 parent b0d3e7b commit 2f11c07
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ Get a business account at Australia Post and request API access
$shipment = $auspost->newShipment()
->setFrom(new \Cognito\Auspost\Address([
'name' => 'Joe Tester',
'first_name' => 'Joe',
'last_name' => 'Tester',
// OR 'name' => 'Joe Tester',
'lines' => [
'11 MyStreetname Court',
],
Expand All @@ -35,7 +37,8 @@ Get a business account at Australia Post and request API access
'country' => 'AU',
]))
->setTo(new \Cognito\Auspost\Address([
'name' => 'Mary Tester',
'first_name' => 'Mary',
'last_name' => 'Tester',
'lines' => [
'10 ReceiverStreetname St',
],
Expand Down
17 changes: 17 additions & 0 deletions src/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* @author Josh Marshall <[email protected]>
*
* @property string $type
* @property string $first_name
* @property string $last_name
* @property string $name
* @property string $business_name
* @property string[] $lines
Expand All @@ -22,6 +24,8 @@
class Address {

public $type = '';
public $first_name = '';
public $last_name = '';
public $name = '';
public $business_name = '';
public $lines = [];
Expand All @@ -41,5 +45,18 @@ public function __construct($details = []) {
}
$this->$key = $data;
}
if (!$this->name) {
$this->name = trim($this->first_name . ' ' . $this->last_name);
}
if (!$this->first_name) {
$parts = explode(' ', $this->name, 2);
if (count($parts) > 1) {
$this->first_name = $parts[0];
$this->last_name = $parts[1];
} else {
$this->first_name = $this->name;
$this->last_name = $this->name;
}
}
}
}
2 changes: 1 addition & 1 deletion src/Auspost.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ private function closeSocket() {
/**
* Convert the lines of response data into an associative array.
*
* @param array $data lines of response data
* @param string $data lines of response data
* @return array associative array
*/
private function convertResponse($data) {
Expand Down

0 comments on commit 2f11c07

Please sign in to comment.