Skip to content

Added support for shipping information #120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/Message/CreateCustomerRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,32 @@ public function setEmail($value)
return $this->setParameter('email', $value);
}

/**
* Get the customer's shipping address.
*
* @return array
*/
public function getShipping()
{
return $this->getParameter('shipping');
}

/**
* Sets the customer's shipping address.
*
* @param array $value
* @return CreateCustomerRequest provides a fluent interface.
*/
public function setShipping($value)
{
return $this->setParameter('shipping', $value);
}

public function getName()
{
return $this->getParameter('name');
}

/**
* Sets the customer's name.
*
Expand Down Expand Up @@ -156,6 +177,9 @@ public function getData()
$data['source'] = $this->getSource();
}

if ($this->getShipping()) {
$data['shipping'] = $this->getShipping();
}
if ($this->getName()) {
$data['name'] = $this->getName();
}
Expand Down
29 changes: 27 additions & 2 deletions src/Message/UpdateCustomerRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,34 @@ public function getEmail()
* Sets the customer's email address.
*
* @param string $value
* @return CreateCustomerRequest provides a fluent interface.
* @return UpdateCustomerRequest provides a fluent interface.
*/
public function setEmail($value)
{
return $this->setParameter('email', $value);
}

/**
* Get the customer's shipping address.
*
* @return array
*/
public function getShipping()
{
return $this->getParameter('shipping');
}

/**
* Sets the customer's shipping address.
*
* @param array $value
* @return UpdateCustomerRequest provides a fluent interface.
*/
public function setShipping($value)
{
return $this->setParameter('shipping', $value);
}

/**
* Get the customer's source.
*
Expand All @@ -71,7 +92,7 @@ public function getSource()
* Sets the customer's source.
*
* @param string $value
* @return CreateCustomerRequest provides a fluent interface.
* @return UpdateCustomerRequest provides a fluent interface.
*/
public function setSource($value)
{
Expand Down Expand Up @@ -102,6 +123,10 @@ public function getData()
$data['source'] = $this->getSource();
}

if ($this->getShipping()) {
$data['shipping'] = $this->getShipping();
}

return $data;
}

Expand Down
4 changes: 4 additions & 0 deletions tests/Message/CreateCustomerRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ public function testEndpoint()

public function testData()
{
$shipping = array('name' => 'John Doe', ['address' => ['line1' => 'Some street']]);

$this->request->setEmail('[email protected]');
$this->request->setDescription('New customer');
$this->request->setShipping($shipping);
$this->request->setMetadata(['field' => 'value']);
$this->request->setPaymentMethod('payment_method_id');
$this->request->setName('Customer Name');
Expand All @@ -33,6 +36,7 @@ public function testData()
$this->assertSame('New customer', $data['description']);
$this->assertArrayHasKey('field', $data['metadata']);
$this->assertSame('value', $data['metadata']['field']);
$this->assertSame($shipping, $data['shipping']);
$this->assertSame('payment_method_id', $data['payment_method']);
$this->assertSame('Customer Name', $data['name']);
}
Expand Down
4 changes: 4 additions & 0 deletions tests/Message/UpdateCustomerRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,20 @@ public function testEndpoint()

public function testData()
{
$shipping = array('name' => 'John Doe', ['address' => ['line1' => 'Some street']]);

$this->request->setEmail('[email protected]');
$this->request->setDescription('New customer');
$this->request->setMetadata(array('field' => 'value'));
$this->request->setshipping($shipping);

$data = $this->request->getData();

$this->assertSame('[email protected]', $data['email']);
$this->assertSame('New customer', $data['description']);
$this->assertArrayHasKey('field', $data['metadata']);
$this->assertSame('value', $data['metadata']['field']);
$this->assertSame($shipping, $data['shipping']);
}

public function testDataWithToken()
Expand Down