From e24566a665f41687d6f281550b37cefb32f8ea7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20K=C3=BCndig?= Date: Sat, 30 Mar 2019 15:46:05 +0100 Subject: [PATCH] Added support for shipping information --- src/Message/CreateCustomerRequest.php | 25 ++++++++++++++++++ src/Message/UpdateCustomerRequest.php | 29 +++++++++++++++++++-- tests/Message/CreateCustomerRequestTest.php | 4 +++ tests/Message/UpdateCustomerRequestTest.php | 4 +++ 4 files changed, 60 insertions(+), 2 deletions(-) diff --git a/src/Message/CreateCustomerRequest.php b/src/Message/CreateCustomerRequest.php index 13d7953e..9ef2290c 100644 --- a/src/Message/CreateCustomerRequest.php +++ b/src/Message/CreateCustomerRequest.php @@ -104,6 +104,27 @@ 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 getSource() { return $this->getParameter('source'); @@ -140,6 +161,10 @@ public function getData() $data['source'] = $this->getSource(); } + if ($this->getShipping()) { + $data['shipping'] = $this->getShipping(); + } + return $data; } diff --git a/src/Message/UpdateCustomerRequest.php b/src/Message/UpdateCustomerRequest.php index d05cf8c9..90e55993 100644 --- a/src/Message/UpdateCustomerRequest.php +++ b/src/Message/UpdateCustomerRequest.php @@ -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. * @@ -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) { @@ -102,6 +123,10 @@ public function getData() $data['source'] = $this->getSource(); } + if ($this->getShipping()) { + $data['shipping'] = $this->getShipping(); + } + return $data; } diff --git a/tests/Message/CreateCustomerRequestTest.php b/tests/Message/CreateCustomerRequestTest.php index 5ce8a827..5424333c 100644 --- a/tests/Message/CreateCustomerRequestTest.php +++ b/tests/Message/CreateCustomerRequestTest.php @@ -18,9 +18,12 @@ public function testEndpoint() public function testData() { + $shipping = array('name' => 'John Doe', ['address' => ['line1' => 'Some street']]); + $this->request->setEmail('customer@business.dom'); $this->request->setDescription('New customer'); $this->request->setMetadata(array('field' => 'value')); + $this->request->setShipping($shipping); $data = $this->request->getData(); @@ -28,6 +31,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']); } public function testDataWithToken() diff --git a/tests/Message/UpdateCustomerRequestTest.php b/tests/Message/UpdateCustomerRequestTest.php index 6cf362f1..4834362b 100644 --- a/tests/Message/UpdateCustomerRequestTest.php +++ b/tests/Message/UpdateCustomerRequestTest.php @@ -19,9 +19,12 @@ public function testEndpoint() public function testData() { + $shipping = array('name' => 'John Doe', ['address' => ['line1' => 'Some street']]); + $this->request->setEmail('customer@business.dom'); $this->request->setDescription('New customer'); $this->request->setMetadata(array('field' => 'value')); + $this->request->setshipping($shipping); $data = $this->request->getData(); @@ -29,6 +32,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']); } public function testDataWithToken()