From b2d05fe77b5fb7450ff9886d3eb52c8be77e3c01 Mon Sep 17 00:00:00 2001 From: Kayla Daniels Date: Mon, 8 Feb 2016 22:29:48 -0500 Subject: [PATCH 1/4] abstract parameters into trait --- src/Omnipay/Common/AbstractGateway.php | 35 ++-------- src/Omnipay/Common/HasParametersTrait.php | 64 +++++++++++++++++++ src/Omnipay/Common/Helper.php | 6 +- src/Omnipay/Common/Item.php | 36 +---------- .../Common/Message/AbstractRequest.php | 12 ++-- src/Omnipay/Common/ParameterizedInterface.php | 20 ++++++ tests/Omnipay/Common/HelperTest.php | 8 +-- 7 files changed, 106 insertions(+), 75 deletions(-) create mode 100644 src/Omnipay/Common/HasParametersTrait.php create mode 100644 src/Omnipay/Common/ParameterizedInterface.php diff --git a/src/Omnipay/Common/AbstractGateway.php b/src/Omnipay/Common/AbstractGateway.php index d87669b6..6ecde32c 100755 --- a/src/Omnipay/Common/AbstractGateway.php +++ b/src/Omnipay/Common/AbstractGateway.php @@ -42,8 +42,10 @@ * * @see GatewayInterface */ -abstract class AbstractGateway implements GatewayInterface +abstract class AbstractGateway implements GatewayInterface, ParameterizedInterface { + use HasParametersTrait; + /** * @var ParameterBag */ @@ -101,7 +103,7 @@ public function initialize(array $parameters = array()) } } - Helper::initialize($this, $parameters); + Helper::initializeParameters($this, $parameters); return $this; } @@ -114,35 +116,6 @@ public function getDefaultParameters() return array(); } - /** - * @return array - */ - public function getParameters() - { - return $this->parameters->all(); - } - - /** - * @param string $key - * @return mixed - */ - public function getParameter($key) - { - return $this->parameters->get($key); - } - - /** - * @param string $key - * @param mixed $value - * @return $this - */ - public function setParameter($key, $value) - { - $this->parameters->set($key, $value); - - return $this; - } - /** * @return boolean */ diff --git a/src/Omnipay/Common/HasParametersTrait.php b/src/Omnipay/Common/HasParametersTrait.php new file mode 100644 index 00000000..d71a6dfc --- /dev/null +++ b/src/Omnipay/Common/HasParametersTrait.php @@ -0,0 +1,64 @@ +parameters->set($key, $value); + + return $this; + } + + /** + * Get one parameter. + * + * @return mixed A single parameter value. + */ + public function getParameter($key) + { + return $this->parameters->get($key); + } + + /** + * Get all parameters. + * + * @return array An associative array of parameters. + */ + public function getParameters() + { + return $this->parameters->all(); + } + + /** + * Initialize the object with parameters. + * + * If any unknown parameters passed, they will be ignored. + * + * @param array $parameters An associative array of parameters + * @return $this. + */ + public function initialize(array $parameters = []) + { + $this->parameters = new ParameterBag; + + Helper::initializeParameters($this, $parameters); + + return $this; + } +} diff --git a/src/Omnipay/Common/Helper.php b/src/Omnipay/Common/Helper.php index 9ccc7de2..7577ca4d 100644 --- a/src/Omnipay/Common/Helper.php +++ b/src/Omnipay/Common/Helper.php @@ -76,16 +76,18 @@ public static function validateLuhn($number) * Parameters are automatically converted to camelCase. Any parameters which do * not match a setter on the target object are ignored. * - * @param mixed $target The object to set parameters on + * @param ParameterizedInterface $target The object to set parameters on * @param array $parameters An array of parameters to set */ - public static function initialize($target, $parameters) + public static function initializeParameters(ParameterizedInterface $target, array $parameters = []) { if (is_array($parameters)) { foreach ($parameters as $key => $value) { $method = 'set'.ucfirst(static::camelCase($key)); if (method_exists($target, $method)) { $target->$method($value); + } else { + $target->setParameter($key, $value); } } } diff --git a/src/Omnipay/Common/Item.php b/src/Omnipay/Common/Item.php index 6fbb6fb5..476504bc 100644 --- a/src/Omnipay/Common/Item.php +++ b/src/Omnipay/Common/Item.php @@ -12,8 +12,10 @@ * * @see ItemInterface */ -class Item implements ItemInterface +class Item implements ItemInterface, ParameterizedInterface { + use HasParametersTrait; + /** * @var ParameterBag */ @@ -29,38 +31,6 @@ public function __construct($parameters = null) $this->initialize($parameters); } - /** - * Initialize this item with the specified parameters - * - * @param array|null $parameters An array of parameters to set on this object - * @return $this Item - */ - public function initialize($parameters = null) - { - $this->parameters = new ParameterBag; - - Helper::initialize($this, $parameters); - - return $this; - } - - public function getParameters() - { - return $this->parameters->all(); - } - - protected function getParameter($key) - { - return $this->parameters->get($key); - } - - protected function setParameter($key, $value) - { - $this->parameters->set($key, $value); - - return $this; - } - /** * {@inheritDoc} */ diff --git a/src/Omnipay/Common/Message/AbstractRequest.php b/src/Omnipay/Common/Message/AbstractRequest.php index aec0f946..6eea7c77 100644 --- a/src/Omnipay/Common/Message/AbstractRequest.php +++ b/src/Omnipay/Common/Message/AbstractRequest.php @@ -5,6 +5,7 @@ namespace Omnipay\Common\Message; +use Omnipay\Common\HasParametersTrait; use Omnipay\Common\Http\ClientInterface; use Omnipay\Common\CreditCard; use Omnipay\Common\Currency; @@ -13,6 +14,7 @@ use Omnipay\Common\Helper; use Omnipay\Common\ItemBag; use Omnipay\Common\ParameterBag; +use Omnipay\Common\ParameterizedInterface; use Psr\Http\Message\ServerRequestInterface; use InvalidArgumentException; @@ -59,7 +61,7 @@ * @see RequestInterface * @see AbstractResponse */ -abstract class AbstractRequest implements RequestInterface +abstract class AbstractRequest implements RequestInterface, ParameterizedInterface { /** * The request parameters @@ -122,7 +124,7 @@ public function __construct(ClientInterface $httpClient, ServerRequestInterface * @return $this * @throws RuntimeException */ - public function initialize(array $parameters = array()) + public function initialize(array $parameters = []) { if (null !== $this->response) { throw new RuntimeException('Request cannot be modified after it has been sent!'); @@ -130,7 +132,7 @@ public function initialize(array $parameters = array()) $this->parameters = new ParameterBag; - Helper::initialize($this, $parameters); + Helper::initializeParameters($this, $parameters); return $this; } @@ -151,7 +153,7 @@ public function getParameters() * @param string $key The parameter key * @return mixed */ - protected function getParameter($key) + public function getParameter($key) { return $this->parameters->get($key); } @@ -164,7 +166,7 @@ protected function getParameter($key) * @return AbstractRequest Provides a fluent interface * @throws RuntimeException if a request parameter is modified after the request has been sent. */ - protected function setParameter($key, $value) + public function setParameter($key, $value) { if (null !== $this->response) { throw new RuntimeException('Request cannot be modified after it has been sent!'); diff --git a/src/Omnipay/Common/ParameterizedInterface.php b/src/Omnipay/Common/ParameterizedInterface.php new file mode 100644 index 00000000..b4624a6d --- /dev/null +++ b/src/Omnipay/Common/ParameterizedInterface.php @@ -0,0 +1,20 @@ +shouldReceive('setName')->once()->with('adrian'); $target->shouldReceive('setNumber')->once()->with('1234'); - Helper::initialize($target, array('name' => 'adrian', 'number' => '1234')); + Helper::initializeParameters($target, ['name' => 'adrian', 'number' => '1234']); } public function testInitializeIgnoresInvalidParameters() @@ -69,7 +69,7 @@ public function testInitializeIgnoresInvalidParameters() $target = m::mock('\Omnipay\Common\CreditCard'); $target->shouldReceive('setName')->once()->with('adrian'); - Helper::initialize($target, array('name' => 'adrian', 'extra' => 'invalid')); + Helper::initializeParameters($target, ['name' => 'adrian', 'extra' => 'invalid']); } public function testGetGatewayShortNameSimple() From 3b563273dd3836571f6782d5d2186247cdba28ed Mon Sep 17 00:00:00 2001 From: Kayla Daniels Date: Mon, 8 Feb 2016 22:30:09 -0500 Subject: [PATCH 2/4] abstract Customer object out of CreditCard object --- src/Omnipay/Common/CreditCard.php | 1067 +---------------------- src/Omnipay/Common/Customer.php | 414 +++++++++ tests/Omnipay/Common/CreditCardTest.php | 355 +------- tests/Omnipay/Common/CustomerTest.php | 161 ++++ 4 files changed, 613 insertions(+), 1384 deletions(-) create mode 100644 src/Omnipay/Common/Customer.php create mode 100644 tests/Omnipay/Common/CustomerTest.php diff --git a/src/Omnipay/Common/CreditCard.php b/src/Omnipay/Common/CreditCard.php index 7ae1b2fe..136b5923 100644 --- a/src/Omnipay/Common/CreditCard.php +++ b/src/Omnipay/Common/CreditCard.php @@ -89,8 +89,10 @@ * * If any unknown parameters are passed in, they will be ignored. No error is thrown. */ -class CreditCard +class CreditCard implements ParameterizedInterface { + use HasParametersTrait; + const BRAND_VISA = 'visa'; const BRAND_MASTERCARD = 'mastercard'; const BRAND_DISCOVER = 'discover'; @@ -115,7 +117,7 @@ class CreditCard * @link https://github.com/Shopify/active_merchant/blob/master/lib/active_merchant/billing/credit_card_methods.rb * @var array */ - protected $supported_cards = array( + protected $supported_cards = [ self::BRAND_VISA => '/^4\d{12}(\d{3})?$/', self::BRAND_MASTERCARD => '/^(5[1-5]\d{4}|677189)\d{10}$/', self::BRAND_DISCOVER => '/^(6011|65\d{2}|64[4-9]\d)\d{12}|(62\d{14})$/', @@ -128,21 +130,24 @@ class CreditCard self::BRAND_MAESTRO => '/^(5[06-8]|6\d)\d{10,17}$/', self::BRAND_FORBRUGSFORENINGEN => '/^600722\d{10}$/', self::BRAND_LASER => '/^(6304|6706|6709|6771(?!89))\d{8}(\d{4}|\d{6,7})?$/', - ); + ]; /** - * Internal storage of all of the card parameters. - * - * @var ParameterBag + * @var Customer + */ + private $shippingCustomer; + + /** + * @var Customer */ - protected $parameters; + private $billingCustomer; /** * Create a new CreditCard object using the specified parameters * * @param array $parameters An array of parameters to set on the new object */ - public function __construct($parameters = null) + public function __construct(array $parameters = []) { $this->initialize($parameters); } @@ -182,58 +187,8 @@ public function addSupportedBrand($name, $expression) } $this->supported_cards[$name] = $expression; - return true; - } - - /** - * Initialize the object with parameters. - * - * If any unknown parameters passed, they will be ignored. - * - * @param array $parameters An associative array of parameters - * @return CreditCard provides a fluent interface. - */ - public function initialize($parameters = null) - { - $this->parameters = new ParameterBag; - - Helper::initialize($this, $parameters); - - return $this; - } - - /** - * Get all parameters. - * - * @return array An associative array of parameters. - */ - public function getParameters() - { - return $this->parameters->all(); - } - - /** - * Get one parameter. - * - * @return mixed A single parameter value. - */ - protected function getParameter($key) - { - return $this->parameters->get($key); - } - - /** - * Set one parameter. - * - * @param string $key Parameter key - * @param mixed $value Parameter value - * @return CreditCard provides a fluent interface. - */ - protected function setParameter($key, $value) - { - $this->parameters->set($key, $value); - return $this; + return true; } /** @@ -271,7 +226,7 @@ protected function setYearParameter($key, $value) */ public function validate() { - foreach (array('number', 'expiryMonth', 'expiryYear') as $key) { + foreach (['number', 'expiryMonth', 'expiryYear'] as $key) { if (!$this->getParameter($key)) { throw new InvalidCreditCardException("The $key parameter is required"); } @@ -290,102 +245,6 @@ public function validate() } } - /** - * Get Card Title. - * - * @return string - */ - public function getTitle() - { - return $this->getBillingTitle(); - } - - /** - * Set Card Title. - * - * @param string $value Parameter value - * @return CreditCard provides a fluent interface. - */ - public function setTitle($value) - { - $this->setBillingTitle($value); - $this->setShippingTitle($value); - - return $this; - } - - /** - * Get Card First Name. - * - * @return string - */ - public function getFirstName() - { - return $this->getBillingFirstName(); - } - - /** - * Set Card First Name (Billing and Shipping). - * - * @param string $value Parameter value - * @return CreditCard provides a fluent interface. - */ - public function setFirstName($value) - { - $this->setBillingFirstName($value); - $this->setShippingFirstName($value); - - return $this; - } - - /** - * Get Card Last Name. - * - * @return string - */ - public function getLastName() - { - return $this->getBillingLastName(); - } - - /** - * Set Card Last Name (Billing and Shipping). - * - * @param string $value Parameter value - * @return CreditCard provides a fluent interface. - */ - public function setLastName($value) - { - $this->setBillingLastName($value); - $this->setShippingLastName($value); - - return $this; - } - - /** - * Get Card Name. - * - * @return string - */ - public function getName() - { - return $this->getBillingName(); - } - - /** - * Set Card Name (Billing and Shipping). - * - * @param string $value Parameter value - * @return CreditCard provides a fluent interface. - */ - public function setName($value) - { - $this->setBillingName($value); - $this->setShippingName($value); - - return $this; - } - /** * Get Card Number. * @@ -601,909 +460,51 @@ public function setIssueNumber($value) } /** - * Get the card billing title. - * - * @return string - */ - public function getBillingTitle() - { - return $this->getParameter('billingTitle'); - } - - /** - * Sets the card billing title. - * - * @param string $value - * @return CreditCard provides a fluent interface. - */ - public function setBillingTitle($value) - { - return $this->setParameter('billingTitle', $value); - } - - /** - * Get the card billing name. - * - * @return string - */ - public function getBillingName() - { - return trim($this->getBillingFirstName() . ' ' . $this->getBillingLastName()); - } - - /** - * Sets the card billing name. - * - * @param string $value - * @return CreditCard provides a fluent interface. - */ - public function setBillingName($value) - { - $names = explode(' ', $value, 2); - $this->setBillingFirstName($names[0]); - $this->setBillingLastName(isset($names[1]) ? $names[1] : null); - - return $this; - } - - /** - * Get the first part of the card billing name. - * - * @return string - */ - public function getBillingFirstName() - { - return $this->getParameter('billingFirstName'); - } - - /** - * Sets the first part of the card billing name. - * - * @param string $value - * @return CreditCard provides a fluent interface. - */ - public function setBillingFirstName($value) - { - return $this->setParameter('billingFirstName', $value); - } - - /** - * Get the last part of the card billing name. - * - * @return string - */ - public function getBillingLastName() - { - return $this->getParameter('billingLastName'); - } - - /** - * Sets the last part of the card billing name. - * - * @param string $value - * @return CreditCard provides a fluent interface. - */ - public function setBillingLastName($value) - { - return $this->setParameter('billingLastName', $value); - } - - /** - * Get the billing company name. - * - * @return string - */ - public function getBillingCompany() - { - return $this->getParameter('billingCompany'); - } - - /** - * Sets the billing company name. - * - * @param string $value - * @return CreditCard provides a fluent interface. - */ - public function setBillingCompany($value) - { - return $this->setParameter('billingCompany', $value); - } - - /** - * Get the billing address, line 1. - * - * @return string - */ - public function getBillingAddress1() - { - return $this->getParameter('billingAddress1'); - } - - /** - * Sets the billing address, line 1. - * - * @param string $value - * @return CreditCard provides a fluent interface. - */ - public function setBillingAddress1($value) - { - return $this->setParameter('billingAddress1', $value); - } - - /** - * Get the billing address, line 2. - * - * @return string - */ - public function getBillingAddress2() - { - return $this->getParameter('billingAddress2'); - } - - /** - * Sets the billing address, line 2. - * - * @param string $value - * @return CreditCard provides a fluent interface. - */ - public function setBillingAddress2($value) - { - return $this->setParameter('billingAddress2', $value); - } - - /** - * Get the billing city. - * - * @return string - */ - public function getBillingCity() - { - return $this->getParameter('billingCity'); - } - - /** - * Sets billing city. - * - * @param string $value - * @return CreditCard provides a fluent interface. - */ - public function setBillingCity($value) - { - return $this->setParameter('billingCity', $value); - } - - /** - * Get the billing postcode. - * - * @return string + * @param Customer $customer */ - public function getBillingPostcode() + public function setCustomer(Customer $customer) { - return $this->getParameter('billingPostcode'); + $this->setBillingCustomer($customer); + $this->setShippingCustomer($customer); } /** - * Sets the billing postcode. - * - * @param string $value - * @return CreditCard provides a fluent interface. - */ - public function setBillingPostcode($value) - { - return $this->setParameter('billingPostcode', $value); - } - - /** - * Get the billing state. - * - * @return string - */ - public function getBillingState() - { - return $this->getParameter('billingState'); - } - - /** - * Sets the billing state. - * - * @param string $value - * @return CreditCard provides a fluent interface. + * @param Customer $customer */ - public function setBillingState($value) + private function setBillingCustomer(Customer $customer) { - return $this->setParameter('billingState', $value); + $this->billingCustomer = $customer; } /** - * Get the billing country name. - * - * @return string + * @param Customer $customer */ - public function getBillingCountry() + private function setShippingCustomer(Customer $customer) { - return $this->getParameter('billingCountry'); + $this->shippingCustomer = $customer; } /** - * Sets the billing country name. - * - * @param string $value - * @return CreditCard provides a fluent interface. + * @return Customer */ - public function setBillingCountry($value) + public function getShippingCustomer() { - return $this->setParameter('billingCountry', $value); + return $this->shippingCustomer; } /** - * Get the billing phone number. - * - * @return string + * @return Customer */ - public function getBillingPhone() + public function getBillingCustomer() { - return $this->getParameter('billingPhone'); + return $this->billingCustomer; } /** - * Sets the billing phone number. - * - * @param string $value - * @return CreditCard provides a fluent interface. - */ - public function setBillingPhone($value) - { - return $this->setParameter('billingPhone', $value); - } - - /** - * Get the billing phone number extension. - * - * @return string - */ - public function getBillingPhoneExtension() - { - return $this->getParameter('billingPhoneExtension'); - } - - /** - * Sets the billing phone number extension. - * - * @param string $value - * @return CreditCard provides a fluent interface. - */ - public function setBillingPhoneExtension($value) - { - return $this->setParameter('billingPhoneExtension', $value); - } - - /** - * Get the billing fax number. - * - * @return string - */ - public function getBillingFax() - { - return $this->getParameter('billingFax'); - } - - /** - * Sets the billing fax number. - * - * @param string $value - * @return CreditCard provides a fluent interface. - */ - public function setBillingFax($value) - { - return $this->setParameter('billingFax', $value); - } - - /** - * Get the title of the card shipping name. - * - * @return string - */ - public function getShippingTitle() - { - return $this->getParameter('shippingTitle'); - } - - /** - * Sets the title of the card shipping name. - * - * @param string $value - * @return CreditCard provides a fluent interface. - */ - public function setShippingTitle($value) - { - return $this->setParameter('shippingTitle', $value); - } - - /** - * Get the card shipping name. - * - * @return string - */ - public function getShippingName() - { - return trim($this->getShippingFirstName() . ' ' . $this->getShippingLastName()); - } - - /** - * Sets the card shipping name. - * - * @param string $value - * @return CreditCard provides a fluent interface. - */ - public function setShippingName($value) - { - $names = explode(' ', $value, 2); - $this->setShippingFirstName($names[0]); - $this->setShippingLastName(isset($names[1]) ? $names[1] : null); - - return $this; - } - - /** - * Get the first part of the card shipping name. - * - * @return string - */ - public function getShippingFirstName() - { - return $this->getParameter('shippingFirstName'); - } - - /** - * Sets the first part of the card shipping name. - * - * @param string $value - * @return CreditCard provides a fluent interface. - */ - public function setShippingFirstName($value) - { - return $this->setParameter('shippingFirstName', $value); - } - - /** - * Get the last part of the card shipping name. - * - * @return string - */ - public function getShippingLastName() - { - return $this->getParameter('shippingLastName'); - } - - /** - * Sets the last part of the card shipping name. - * - * @param string $value - * @return CreditCard provides a fluent interface. - */ - public function setShippingLastName($value) - { - return $this->setParameter('shippingLastName', $value); - } - - /** - * Get the shipping company name. - * - * @return string - */ - public function getShippingCompany() - { - return $this->getParameter('shippingCompany'); - } - - /** - * Sets the shipping company name. - * - * @param string $value - * @return CreditCard provides a fluent interface. - */ - public function setShippingCompany($value) - { - return $this->setParameter('shippingCompany', $value); - } - - /** - * Get the shipping address, line 1. - * - * @return string - */ - public function getShippingAddress1() - { - return $this->getParameter('shippingAddress1'); - } - - /** - * Sets the shipping address, line 1. - * - * @param string $value - * @return CreditCard provides a fluent interface. - */ - public function setShippingAddress1($value) - { - return $this->setParameter('shippingAddress1', $value); - } - - /** - * Get the shipping address, line 2. - * - * @return string - */ - public function getShippingAddress2() - { - return $this->getParameter('shippingAddress2'); - } - - /** - * Sets the shipping address, line 2. - * - * @param string $value - * @return CreditCard provides a fluent interface. - */ - public function setShippingAddress2($value) - { - return $this->setParameter('shippingAddress2', $value); - } - - /** - * Get the shipping city. - * - * @return string - */ - public function getShippingCity() - { - return $this->getParameter('shippingCity'); - } - - /** - * Sets the shipping city. - * - * @param string $value - * @return CreditCard provides a fluent interface. - */ - public function setShippingCity($value) - { - return $this->setParameter('shippingCity', $value); - } - - /** - * Get the shipping postcode. - * - * @return string - */ - public function getShippingPostcode() - { - return $this->getParameter('shippingPostcode'); - } - - /** - * Sets the shipping postcode. - * - * @param string $value - * @return CreditCard provides a fluent interface. - */ - public function setShippingPostcode($value) - { - return $this->setParameter('shippingPostcode', $value); - } - - /** - * Get the shipping state. - * - * @return string - */ - public function getShippingState() - { - return $this->getParameter('shippingState'); - } - - /** - * Sets the shipping state. - * - * @param string $value - * @return CreditCard provides a fluent interface. - */ - public function setShippingState($value) - { - return $this->setParameter('shippingState', $value); - } - - /** - * Get the shipping country. - * - * @return string - */ - public function getShippingCountry() - { - return $this->getParameter('shippingCountry'); - } - - /** - * Sets the shipping country. - * - * @param string $value - * @return CreditCard provides a fluent interface. - */ - public function setShippingCountry($value) - { - return $this->setParameter('shippingCountry', $value); - } - - /** - * Get the shipping phone number. - * - * @return string - */ - public function getShippingPhone() - { - return $this->getParameter('shippingPhone'); - } - - /** - * Sets the shipping phone number. - * - * @param string $value - * @return CreditCard provides a fluent interface. - */ - public function setShippingPhone($value) - { - return $this->setParameter('shippingPhone', $value); - } - - /** - * Get the shipping phone number extension. - * - * @return string - */ - public function getShippingPhoneExtension() - { - return $this->getParameter('shippingPhoneExtension'); - } - - /** - * Sets the shipping phone number extension. - * - * @param string $value - * @return CreditCard provides a fluent interface. - */ - public function setShippingPhoneExtension($value) - { - return $this->setParameter('shippingPhoneExtension', $value); - } - - /** - * Get the shipping fax number. - * - * @return string - */ - public function getShippingFax() - { - return $this->getParameter('shippingFax'); - } - - /** - * Sets the shipping fax number. - * - * @param string $value - * @return CreditCard provides a fluent interface. - */ - public function setShippingFax($value) - { - return $this->setParameter('shippingFax', $value); - } - - /** - * Get the billing address, line 1. - * - * @return string - */ - public function getAddress1() - { - return $this->getParameter('billingAddress1'); - } - - /** - * Sets the billing and shipping address, line 1. - * - * @param string $value - * @return CreditCard provides a fluent interface. - */ - public function setAddress1($value) - { - $this->setParameter('billingAddress1', $value); - $this->setParameter('shippingAddress1', $value); - - return $this; - } - - /** - * Get the billing address, line 2. - * - * @return string - */ - public function getAddress2() - { - return $this->getParameter('billingAddress2'); - } - - /** - * Sets the billing and shipping address, line 2. - * - * @param string $value - * @return CreditCard provides a fluent interface. - */ - public function setAddress2($value) - { - $this->setParameter('billingAddress2', $value); - $this->setParameter('shippingAddress2', $value); - - return $this; - } - - /** - * Get the billing city. - * - * @return string - */ - public function getCity() - { - return $this->getParameter('billingCity'); - } - - /** - * Sets the billing and shipping city. - * - * @param string $value - * @return CreditCard provides a fluent interface. - */ - public function setCity($value) - { - $this->setParameter('billingCity', $value); - $this->setParameter('shippingCity', $value); - - return $this; - } - - /** - * Get the billing postcode. - * - * @return string - */ - public function getPostcode() - { - return $this->getParameter('billingPostcode'); - } - - /** - * Sets the billing and shipping postcode. - * - * @param string $value - * @return CreditCard provides a fluent interface. - */ - public function setPostcode($value) - { - $this->setParameter('billingPostcode', $value); - $this->setParameter('shippingPostcode', $value); - - return $this; - } - - /** - * Get the billing state. - * - * @return string - */ - public function getState() - { - return $this->getParameter('billingState'); - } - - /** - * Sets the billing and shipping state. - * - * @param string $value - * @return CreditCard provides a fluent interface. - */ - public function setState($value) - { - $this->setParameter('billingState', $value); - $this->setParameter('shippingState', $value); - - return $this; - } - - /** - * Get the billing country. - * - * @return string - */ - public function getCountry() - { - return $this->getParameter('billingCountry'); - } - - /** - * Sets the billing and shipping country. - * - * @param string $value - * @return CreditCard provides a fluent interface. - */ - public function setCountry($value) - { - $this->setParameter('billingCountry', $value); - $this->setParameter('shippingCountry', $value); - - return $this; - } - - /** - * Get the billing phone number. - * - * @return string - */ - public function getPhone() - { - return $this->getParameter('billingPhone'); - } - - /** - * Sets the billing and shipping phone number. - * - * @param string $value - * @return CreditCard provides a fluent interface. - */ - public function setPhone($value) - { - $this->setParameter('billingPhone', $value); - $this->setParameter('shippingPhone', $value); - - return $this; - } - - /** - * Get the billing phone number extension. - * - * @return string - */ - public function getPhoneExtension() - { - return $this->getParameter('billingPhoneExtension'); - } - - /** - * Sets the billing and shipping phone number extension. - * - * @param string $value - * @return CreditCard provides a fluent interface. - */ - public function setPhoneExtension($value) - { - $this->setParameter('billingPhoneExtension', $value); - $this->setParameter('shippingPhoneExtension', $value); - - return $this; - } - - /** - * Get the billing fax number.. - * - * @return string - */ - public function getFax() - { - return $this->getParameter('billingFax'); - } - - /** - * Sets the billing and shipping fax number. - * - * @param string $value - * @return CreditCard provides a fluent interface. - */ - public function setFax($value) - { - $this->setParameter('billingFax', $value); - $this->setParameter('shippingFax', $value); - - return $this; - } - - /** - * Get the card billing company name. - * - * @return string - */ - public function getCompany() - { - return $this->getParameter('billingCompany'); - } - - /** - * Sets the billing and shipping company name. - * - * @param string $value - * @return CreditCard provides a fluent interface. - */ - public function setCompany($value) - { - $this->setParameter('billingCompany', $value); - $this->setParameter('shippingCompany', $value); - - return $this; - } - - /** - * Get the cardholder's email address. - * - * @return string - */ - public function getEmail() - { - return $this->getParameter('email'); - } - - /** - * Sets the cardholder's email address. - * - * @param string $value - * @return CreditCard provides a fluent interface. - */ - public function setEmail($value) - { - return $this->setParameter('email', $value); - } - - /** - * Get the cardholder's birthday. - * - * @return string - */ - public function getBirthday($format = 'Y-m-d') - { - $value = $this->getParameter('birthday'); - - return $value ? $value->format($format) : null; - } - - /** - * Sets the cardholder's birthday. - * - * @param string $value - * @return CreditCard provides a fluent interface. - */ - public function setBirthday($value) - { - if ($value) { - $value = new DateTime($value, new DateTimeZone('UTC')); - } else { - $value = null; - } - - return $this->setParameter('birthday', $value); - } - - /** - * Get the cardholder's gender. - * - * @return string - */ - public function getGender() - { - return $this->getParameter('gender'); - } - - /** - * Sets the cardholder's gender. - * - * @param string $value - * @return CreditCard provides a fluent interface. + * @return Customer */ - public function setGender($value) + public function getCustomer() { - return $this->setParameter('gender', $value); + return $this->getBillingCustomer(); } } diff --git a/src/Omnipay/Common/Customer.php b/src/Omnipay/Common/Customer.php new file mode 100644 index 00000000..c0a7d191 --- /dev/null +++ b/src/Omnipay/Common/Customer.php @@ -0,0 +1,414 @@ +initialize($parameters); + } + + /** + * Get Card Title. + * + * @return string + */ + public function getTitle() + { + return $this->getParameter('title'); + } + + /** + * Set Card Title. + * + * @param string $value Parameter value + * @return CreditCard provides a fluent interface. + */ + public function setTitle($value) + { + $this->setParameter('title', $value); + + return $this; + } + + /** + * Get Card First Name. + * + * @return string + */ + public function getFirstName() + { + return $this->getParameter('firstName'); + } + + /** + * Set Card First Name (Billing and Shipping). + * + * @param string $value Parameter value + * @return CreditCard provides a fluent interface. + */ + public function setFirstName($value) + { + $this->setParameter('firstName', $value); + + return $this; + } + + /** + * Get Card Last Name. + * + * @return string + */ + public function getLastName() + { + return $this->getParameter('lastName'); + } + + /** + * Set Card Last Name (Billing and Shipping). + * + * @param string $value Parameter value + * @return CreditCard provides a fluent interface. + */ + public function setLastName($value) + { + $this->setParameter('lastName', $value); + + return $this; + } + + /** + * Get Card Name. + * + * @return string + */ + public function getName() + { + return trim($this->getFirstName() . ' ' . $this->getLastName()); + } + + /** + * Set Card Name (Billing and Shipping). + * + * @param string $value Parameter value + * @return CreditCard provides a fluent interface. + */ + public function setName($value) + { + $names = explode(' ', $value, 2); + $this->setFirstName($names[0]); + $this->setLastName(isset($names[1]) ? $names[1] : null); + + return $this; + } + + /** + * Get the address, line 1. + * + * @return string + */ + public function getAddress1() + { + return $this->getParameter('address1'); + } + + /** + * Sets the address, line 1. + * + * @param string $value + * @return CreditCard provides a fluent interface. + */ + public function setAddress1($value) + { + $this->setParameter('address1', $value); + + return $this; + } + + /** + * Get the address, line 2. + * + * @return string + */ + public function getAddress2() + { + return $this->getParameter('address2'); + } + + /** + * Sets the address, line 2. + * + * @param string $value + * @return CreditCard provides a fluent interface. + */ + public function setAddress2($value) + { + $this->setParameter('address2', $value); + + return $this; + } + + /** + * Get the city. + * + * @return string + */ + public function getCity() + { + return $this->getParameter('city'); + } + + /** + * Sets the city. + * + * @param string $value + * @return CreditCard provides a fluent interface. + */ + public function setCity($value) + { + $this->setParameter('city', $value); + + return $this; + } + + /** + * Get the postcode. + * + * @return string + */ + public function getPostcode() + { + return $this->getParameter('postcode'); + } + + /** + * Sets the postcode. + * + * @param string $value + * @return CreditCard provides a fluent interface. + */ + public function setPostcode($value) + { + $this->setParameter('postcode', $value); + + return $this; + } + + /** + * Get the state. + * + * @return string + */ + public function getState() + { + return $this->getParameter('state'); + } + + /** + * Sets the state. + * + * @param string $value + * @return CreditCard provides a fluent interface. + */ + public function setState($value) + { + $this->setParameter('state', $value); + + return $this; + } + + /** + * Get the country. + * + * @return string + */ + public function getCountry() + { + return $this->getParameter('country'); + } + + /** + * Sets the country. + * + * @param string $value + * @return CreditCard provides a fluent interface. + */ + public function setCountry($value) + { + $this->setParameter('country', $value); + + return $this; + } + + /** + * Get the phone number. + * + * @return string + */ + public function getPhone() + { + return $this->getParameter('phone'); + } + + /** + * Sets the phone number. + * + * @param string $value + * @return CreditCard provides a fluent interface. + */ + public function setPhone($value) + { + $this->setParameter('phone', $value); + + return $this; + } + + /** + * Get the phone number extension. + * + * @return string + */ + public function getPhoneExtension() + { + return $this->getParameter('phoneExtension'); + } + + /** + * Sets the phone number extension. + * + * @param string $value + * @return CreditCard provides a fluent interface. + */ + public function setPhoneExtension($value) + { + $this->setParameter('phoneExtension', $value); + + return $this; + } + + /** + * Get the fax number.. + * + * @return string + */ + public function getFax() + { + return $this->getParameter('fax'); + } + + /** + * Sets the fax number. + * + * @param string $value + * @return CreditCard provides a fluent interface. + */ + public function setFax($value) + { + $this->setParameter('fax', $value); + + return $this; + } + + /** + * Get the card company name. + * + * @return string + */ + public function getCompany() + { + return $this->getParameter('company'); + } + + /** + * Sets the company name. + * + * @param string $value + * @return CreditCard provides a fluent interface. + */ + public function setCompany($value) + { + $this->setParameter('company', $value); + + return $this; + } + + /** + * Get the cardholder's email address. + * + * @return string + */ + public function getEmail() + { + return $this->getParameter('email'); + } + + /** + * Sets the cardholder's email address. + * + * @param string $value + * @return CreditCard provides a fluent interface. + */ + public function setEmail($value) + { + return $this->setParameter('email', $value); + } + + /** + * Get the cardholder's birthday. + * + * @return string + */ + public function getBirthday($format = 'Y-m-d') + { + $value = $this->getParameter('birthday'); + + return $value ? $value->format($format) : null; + } + + /** + * Sets the cardholder's birthday. + * + * @param string $value + * @return CreditCard provides a fluent interface. + */ + public function setBirthday($value) + { + if ($value) { + $value = new DateTime($value, new DateTimeZone('UTC')); + } else { + $value = null; + } + + return $this->setParameter('birthday', $value); + } + + /** + * Get the cardholder's gender. + * + * @return string + */ + public function getGender() + { + return $this->getParameter('gender'); + } + + /** + * Sets the cardholder's gender. + * + * @param string $value + * @return CreditCard provides a fluent interface. + */ + public function setGender($value) + { + return $this->setParameter('gender', $value); + } +} diff --git a/tests/Omnipay/Common/CreditCardTest.php b/tests/Omnipay/Common/CreditCardTest.php index 47649de4..ea2c704b 100644 --- a/tests/Omnipay/Common/CreditCardTest.php +++ b/tests/Omnipay/Common/CreditCardTest.php @@ -10,8 +10,6 @@ public function setUp() { $this->card = new CreditCard; $this->card->setNumber('4111111111111111'); - $this->card->setFirstName('Example'); - $this->card->setLastName('Customer'); $this->card->setExpiryMonth('4'); $this->card->setExpiryYear(gmdate('Y')+2); $this->card->setCvv('123'); @@ -19,29 +17,26 @@ public function setUp() public function testConstructWithParams() { - $card = new CreditCard(array('name' => 'Test Customer')); - $this->assertSame('Test Customer', $card->getName()); + $card = new CreditCard(array('number' => '4111111111111111')); + $this->assertSame('4111111111111111', $card->getNumber()); } public function testInitializeWithParams() { $card = new CreditCard; - $card->initialize(array('name' => 'Test Customer')); - $this->assertSame('Test Customer', $card->getName()); + $card->initialize(array('number' => '4111111111111111')); + $this->assertSame('4111111111111111', $card->getNumber()); } public function testGetParamters() { $card = new CreditCard(array( - 'name' => 'Example Customer', 'number' => '1234', 'expiryMonth' => 6, 'expiryYear' => 2016, )); $parameters = $card->getParameters(); - $this->assertSame('Example', $parameters['billingFirstName']); - $this->assertSame('Customer', $parameters['billingLastName']); $this->assertSame('1234', $parameters['number']); $this->assertSame(6, $parameters['expiryMonth']); $this->assertSame(2016, $parameters['expiryYear']); @@ -124,52 +119,6 @@ public function testCustomBrandWorks() $this->assertEquals('omniexpress', $this->card->getBrand()); } - public function testTitle() - { - $this->card->setTitle('Mr.'); - $this->assertEquals('Mr.', $this->card->getTitle()); - } - - public function testFirstName() - { - $this->card->setFirstName('Bob'); - $this->assertEquals('Bob', $this->card->getFirstName()); - } - - public function testLastName() - { - $this->card->setLastName('Smith'); - $this->assertEquals('Smith', $this->card->getLastName()); - } - - public function testGetName() - { - $this->card->setFirstName('Bob'); - $this->card->setLastName('Smith'); - $this->assertEquals('Bob Smith', $this->card->getName()); - } - - public function testSetName() - { - $this->card->setName('Bob Smith'); - $this->assertEquals('Bob', $this->card->getFirstName()); - $this->assertEquals('Smith', $this->card->getLastName()); - } - - public function testSetNameWithOneName() - { - $this->card->setName('Bob'); - $this->assertEquals('Bob', $this->card->getFirstName()); - $this->assertEquals('', $this->card->getLastName()); - } - - public function testSetNameWithMultipleNames() - { - $this->card->setName('Bob John Smith'); - $this->assertEquals('Bob', $this->card->getFirstName()); - $this->assertEquals('John Smith', $this->card->getLastName()); - } - public function testNumber() { $this->card->setNumber('4000000000000000'); @@ -330,302 +279,6 @@ public function testIssueNumber() $this->assertSame('12', $this->card->getIssueNumber()); } - public function testBillingTitle() - { - $this->card->setBillingTitle('Mrs.'); - $this->assertEquals('Mrs.', $this->card->getBillingTitle()); - $this->assertEquals('Mrs.', $this->card->getTitle()); - } - - public function testBillingFirstName() - { - $this->card->setBillingFirstName('Bob'); - $this->assertEquals('Bob', $this->card->getBillingFirstName()); - $this->assertEquals('Bob', $this->card->getFirstName()); - } - - public function testBillingLastName() - { - $this->card->setBillingLastName('Smith'); - $this->assertEquals('Smith', $this->card->getBillingLastName()); - $this->assertEquals('Smith', $this->card->getLastName()); - } - - public function testBillingName() - { - $this->card->setBillingFirstName('Bob'); - $this->card->setBillingLastName('Smith'); - $this->assertEquals('Bob Smith', $this->card->getBillingName()); - - $this->card->setBillingName('John Foo'); - $this->assertEquals('John', $this->card->getBillingFirstName()); - $this->assertEquals('Foo', $this->card->getBillingLastName()); - } - - public function testBillingCompany() - { - $this->card->setBillingCompany('SuperSoft'); - $this->assertEquals('SuperSoft', $this->card->getBillingCompany()); - $this->assertEquals('SuperSoft', $this->card->getCompany()); - } - - public function testBillingAddress1() - { - $this->card->setBillingAddress1('31 Spooner St'); - $this->assertEquals('31 Spooner St', $this->card->getBillingAddress1()); - $this->assertEquals('31 Spooner St', $this->card->getAddress1()); - } - - public function testBillingAddress2() - { - $this->card->setBillingAddress2('Suburb'); - $this->assertEquals('Suburb', $this->card->getBillingAddress2()); - $this->assertEquals('Suburb', $this->card->getAddress2()); - } - - public function testBillingCity() - { - $this->card->setBillingCity('Quahog'); - $this->assertEquals('Quahog', $this->card->getBillingCity()); - $this->assertEquals('Quahog', $this->card->getCity()); - } - - public function testBillingPostcode() - { - $this->card->setBillingPostcode('12345'); - $this->assertEquals('12345', $this->card->getBillingPostcode()); - $this->assertEquals('12345', $this->card->getPostcode()); - } - - public function testBillingState() - { - $this->card->setBillingState('RI'); - $this->assertEquals('RI', $this->card->getBillingState()); - $this->assertEquals('RI', $this->card->getState()); - } - - public function testBillingCountry() - { - $this->card->setBillingCountry('US'); - $this->assertEquals('US', $this->card->getBillingCountry()); - $this->assertEquals('US', $this->card->getCountry()); - } - - public function testBillingPhone() - { - $this->card->setBillingPhone('12345'); - $this->assertSame('12345', $this->card->getBillingPhone()); - $this->assertSame('12345', $this->card->getPhone()); - } - - public function testBillingPhoneExtension() - { - $this->card->setBillingPhoneExtension('001'); - $this->assertSame('001', $this->card->getBillingPhoneExtension()); - $this->assertSame('001', $this->card->getPhoneExtension()); - } - - public function testBillingFax() - { - $this->card->setBillingFax('54321'); - $this->assertSame('54321', $this->card->getBillingFax()); - $this->assertSame('54321', $this->card->getFax()); - } - - public function testShippingTitle() - { - $this->card->setShippingTitle('Dr.'); - $this->assertEquals('Dr.', $this->card->getShippingTitle()); - } - - public function testShippingFirstName() - { - $this->card->setShippingFirstName('James'); - $this->assertEquals('James', $this->card->getShippingFirstName()); - } - - public function testShippingLastName() - { - $this->card->setShippingLastName('Doctor'); - $this->assertEquals('Doctor', $this->card->getShippingLastName()); - } - - public function testShippingName() - { - $this->card->setShippingFirstName('Bob'); - $this->card->setShippingLastName('Smith'); - $this->assertEquals('Bob Smith', $this->card->getShippingName()); - - $this->card->setShippingName('John Foo'); - $this->assertEquals('John', $this->card->getShippingFirstName()); - $this->assertEquals('Foo', $this->card->getShippingLastName()); - } - - public function testShippingCompany() - { - $this->card->setShippingCompany('SuperSoft'); - $this->assertEquals('SuperSoft', $this->card->getShippingCompany()); - } - - public function testShippingAddress1() - { - $this->card->setShippingAddress1('31 Spooner St'); - $this->assertEquals('31 Spooner St', $this->card->getShippingAddress1()); - } - - public function testShippingAddress2() - { - $this->card->setShippingAddress2('Suburb'); - $this->assertEquals('Suburb', $this->card->getShippingAddress2()); - } - - public function testShippingCity() - { - $this->card->setShippingCity('Quahog'); - $this->assertEquals('Quahog', $this->card->getShippingCity()); - } - - public function testShippingPostcode() - { - $this->card->setShippingPostcode('12345'); - $this->assertEquals('12345', $this->card->getShippingPostcode()); - } - - public function testShippingState() - { - $this->card->setShippingState('RI'); - $this->assertEquals('RI', $this->card->getShippingState()); - } - - public function testShippingCountry() - { - $this->card->setShippingCountry('US'); - $this->assertEquals('US', $this->card->getShippingCountry()); - } - - public function testShippingPhone() - { - $this->card->setShippingPhone('12345'); - $this->assertEquals('12345', $this->card->getShippingPhone()); - } - - public function testShippingPhoneExtension() - { - $this->card->setShippingPhoneExtension('001'); - $this->assertEquals('001', $this->card->getShippingPhoneExtension()); - } - - public function testShippingFax() - { - $this->card->setShippingFax('54321'); - $this->assertEquals('54321', $this->card->getShippingFax()); - } - - public function testCompany() - { - $this->card->setCompany('FooBar'); - $this->assertEquals('FooBar', $this->card->getCompany()); - $this->assertEquals('FooBar', $this->card->getBillingCompany()); - $this->assertEquals('FooBar', $this->card->getShippingCompany()); - } - - public function testAddress1() - { - $this->card->setAddress1('31 Spooner St'); - $this->assertEquals('31 Spooner St', $this->card->getAddress1()); - $this->assertEquals('31 Spooner St', $this->card->getBillingAddress1()); - $this->assertEquals('31 Spooner St', $this->card->getShippingAddress1()); - } - - public function testAddress2() - { - $this->card->setAddress2('Suburb'); - $this->assertEquals('Suburb', $this->card->getAddress2()); - $this->assertEquals('Suburb', $this->card->getBillingAddress2()); - $this->assertEquals('Suburb', $this->card->getShippingAddress2()); - } - - public function testCity() - { - $this->card->setCity('Quahog'); - $this->assertEquals('Quahog', $this->card->getCity()); - $this->assertEquals('Quahog', $this->card->getBillingCity()); - $this->assertEquals('Quahog', $this->card->getShippingCity()); - } - - public function testPostcode() - { - $this->card->setPostcode('12345'); - $this->assertEquals('12345', $this->card->getPostcode()); - $this->assertEquals('12345', $this->card->getBillingPostcode()); - $this->assertEquals('12345', $this->card->getShippingPostcode()); - } - - public function testState() - { - $this->card->setState('RI'); - $this->assertEquals('RI', $this->card->getState()); - $this->assertEquals('RI', $this->card->getBillingState()); - $this->assertEquals('RI', $this->card->getShippingState()); - } - - public function testCountry() - { - $this->card->setCountry('US'); - $this->assertEquals('US', $this->card->getCountry()); - $this->assertEquals('US', $this->card->getBillingCountry()); - $this->assertEquals('US', $this->card->getShippingCountry()); - } - - public function testPhone() - { - $this->card->setPhone('12345'); - $this->assertEquals('12345', $this->card->getPhone()); - $this->assertEquals('12345', $this->card->getBillingPhone()); - $this->assertEquals('12345', $this->card->getShippingPhone()); - } - - public function testPhoneExtension() - { - $this->card->setPhoneExtension('001'); - $this->assertEquals('001', $this->card->getPhoneExtension()); - $this->assertEquals('001', $this->card->getBillingPhoneExtension()); - $this->assertEquals('001', $this->card->getShippingPhoneExtension()); - } - - public function testFax() - { - $this->card->setFax('54321'); - $this->assertEquals('54321', $this->card->getFax()); - $this->assertEquals('54321', $this->card->getBillingFax()); - $this->assertEquals('54321', $this->card->getShippingFax()); - } - - public function testEmail() - { - $this->card->setEmail('adrian@example.com'); - $this->assertEquals('adrian@example.com', $this->card->getEmail()); - } - - public function testBirthday() - { - $this->card->setBirthday('01-02-2000'); - $this->assertEquals('2000-02-01', $this->card->getBirthday()); - $this->assertEquals('01/02/2000', $this->card->getBirthday('d/m/Y')); - } - - public function testBirthdayEmpty() - { - $this->card->setBirthday(''); - $this->assertNull($this->card->getBirthday()); - } - - public function testGender() - { - $this->card->setGender('female'); - $this->assertEquals('female', $this->card->getGender()); - } - /** * @expectedException Omnipay\Common\Exception\InvalidCreditCardException * @expectedExceptionMessage Card number is invalid diff --git a/tests/Omnipay/Common/CustomerTest.php b/tests/Omnipay/Common/CustomerTest.php new file mode 100644 index 00000000..229a8579 --- /dev/null +++ b/tests/Omnipay/Common/CustomerTest.php @@ -0,0 +1,161 @@ +setTitle('Mr.'); + $this->assertEquals('Mr.', $customer->getTitle()); + } + + public function testFirstName() + { + $customer = new Customer(); + $customer->setFirstName('Bob'); + $this->assertEquals('Bob', $customer->getFirstName()); + } + + public function testLastName() + { + $customer = new Customer(); + $customer->setLastName('Smith'); + $this->assertEquals('Smith', $customer->getLastName()); + } + + public function testGetName() + { + $customer = new Customer(); + $customer->setFirstName('Bob'); + $customer->setLastName('Smith'); + $this->assertEquals('Bob Smith', $customer->getName()); + } + + public function testSetName() + { + $customer = new Customer(); + $customer->setName('Bob Smith'); + $this->assertEquals('Bob', $customer->getFirstName()); + $this->assertEquals('Smith', $customer->getLastName()); + } + + public function testSetNameWithOneName() + { + $customer = new Customer(); + $customer->setName('Bob'); + $this->assertEquals('Bob', $customer->getFirstName()); + $this->assertEquals('', $customer->getLastName()); + } + + public function testSetNameWithMultipleNames() + { + $customer = new Customer(); + $customer->setName('Bob John Smith'); + $this->assertEquals('Bob', $customer->getFirstName()); + $this->assertEquals('John Smith', $customer->getLastName()); + } + + public function testCompany() + { + $customer = new Customer(); + $customer->setCompany('FooBar'); + $this->assertEquals('FooBar', $customer->getCompany()); + } + + public function testAddress1() + { + $customer = new Customer(); + $customer->setAddress1('31 Spooner St'); + $this->assertEquals('31 Spooner St', $customer->getAddress1()); + } + + public function testAddress2() + { + $customer = new Customer(); + $customer->setAddress2('Suburb'); + $this->assertEquals('Suburb', $customer->getAddress2()); + } + + public function testCity() + { + $customer = new Customer(); + $customer->setCity('Quahog'); + $this->assertEquals('Quahog', $customer->getCity()); + } + + public function testPostcode() + { + $customer = new Customer(); + $customer->setPostcode('12345'); + $this->assertEquals('12345', $customer->getPostcode()); + } + + public function testState() + { + $customer = new Customer(); + $customer->setState('RI'); + $this->assertEquals('RI', $customer->getState()); + } + + public function testCountry() + { + $customer = new Customer(); + $customer->setCountry('US'); + $this->assertEquals('US', $customer->getCountry()); + } + + public function testPhone() + { + $customer = new Customer(); + $customer->setPhone('12345'); + $this->assertEquals('12345', $customer->getPhone()); + } + + public function testPhoneExtension() + { + $customer = new Customer(); + $customer->setPhoneExtension('001'); + $this->assertEquals('001', $customer->getPhoneExtension()); + } + + public function testFax() + { + $customer = new Customer(); + $customer->setFax('54321'); + $this->assertEquals('54321', $customer->getFax()); + } + + public function testEmail() + { + $customer = new Customer(); + $customer->setEmail('adrian@example.com'); + $this->assertEquals('adrian@example.com', $customer->getEmail()); + } + + public function testBirthday() + { + $customer = new Customer(); + $customer->setBirthday('01-02-2000'); + $this->assertEquals('2000-02-01', $customer->getBirthday()); + $this->assertEquals('01/02/2000', $customer->getBirthday('d/m/Y')); + } + + public function testBirthdayEmpty() + { + $customer = new Customer(); + $customer->setBirthday(''); + $this->assertNull($customer->getBirthday()); + } + + public function testGender() + { + $customer = new Customer(); + $customer->setGender('female'); + $this->assertEquals('female', $customer->getGender()); + } +} From 83aecd0dc2ba51ba15b6846270aca44edb395859 Mon Sep 17 00:00:00 2001 From: Kayla Daniels Date: Mon, 8 Feb 2016 22:46:04 -0500 Subject: [PATCH 3/4] fix styling and tests --- composer.json | 1 + src/Omnipay/Common/AbstractGateway.php | 5 ---- src/Omnipay/Common/Item.php | 9 ++------ src/Omnipay/Common/ParameterizedInterface.php | 6 ++--- tests/Omnipay/Common/AbstractGatewayTest.php | 2 +- tests/Omnipay/Common/HelperTest.php | 23 +------------------ 6 files changed, 8 insertions(+), 38 deletions(-) diff --git a/composer.json b/composer.json index 1f680de6..e81c6866 100644 --- a/composer.json +++ b/composer.json @@ -29,6 +29,7 @@ "require": { "php": ">=5.6", "alcohol/iso4217": "^3.1", + "beberlei/assert": "^2.4", "guzzlehttp/guzzle": "^6.0", "psr/http-message": "^1.0", "zendframework/zend-diactoros": "^1.1.0" diff --git a/src/Omnipay/Common/AbstractGateway.php b/src/Omnipay/Common/AbstractGateway.php index 6ecde32c..e69c0b78 100755 --- a/src/Omnipay/Common/AbstractGateway.php +++ b/src/Omnipay/Common/AbstractGateway.php @@ -46,11 +46,6 @@ abstract class AbstractGateway implements GatewayInterface, ParameterizedInterfa { use HasParametersTrait; - /** - * @var ParameterBag - */ - protected $parameters; - /** * @var ClientInterface */ diff --git a/src/Omnipay/Common/Item.php b/src/Omnipay/Common/Item.php index 476504bc..7c4e1c6d 100644 --- a/src/Omnipay/Common/Item.php +++ b/src/Omnipay/Common/Item.php @@ -16,17 +16,12 @@ class Item implements ItemInterface, ParameterizedInterface { use HasParametersTrait; - /** - * @var ParameterBag - */ - protected $parameters; - /** * Create a new item with the specified parameters * - * @param array|null $parameters An array of parameters to set on the new object + * @param array $parameters An array of parameters to set on the new object */ - public function __construct($parameters = null) + public function __construct(array $parameters = []) { $this->initialize($parameters); } diff --git a/src/Omnipay/Common/ParameterizedInterface.php b/src/Omnipay/Common/ParameterizedInterface.php index b4624a6d..e3a45d6e 100644 --- a/src/Omnipay/Common/ParameterizedInterface.php +++ b/src/Omnipay/Common/ParameterizedInterface.php @@ -2,19 +2,19 @@ interface ParameterizedInterface { - function setParameter($key, $value); + public function setParameter($key, $value); /** * Get one parameter. * * @return mixed A single parameter value. */ - function getParameter($key); + public function getParameter($key); /** * Get all parameters. * * @return array An associative array of parameters. */ - function getParameters(); + public function getParameters(); } diff --git a/tests/Omnipay/Common/AbstractGatewayTest.php b/tests/Omnipay/Common/AbstractGatewayTest.php index 26d25ba2..a94bf87e 100755 --- a/tests/Omnipay/Common/AbstractGatewayTest.php +++ b/tests/Omnipay/Common/AbstractGatewayTest.php @@ -55,7 +55,7 @@ public function testInitializeParameters() 'unknown' => '42', )); - $this->assertSame(array('currency' => 'USD'), $this->gateway->getParameters()); + $this->assertSame(array('currency' => 'USD', 'unknown' => '42'), $this->gateway->getParameters()); } public function testGetDefaultParameters() diff --git a/tests/Omnipay/Common/HelperTest.php b/tests/Omnipay/Common/HelperTest.php index 55b7a4e5..5325310b 100644 --- a/tests/Omnipay/Common/HelperTest.php +++ b/tests/Omnipay/Common/HelperTest.php @@ -43,33 +43,12 @@ public function testValidateLuhnNull() $this->assertTrue($result); } - public function testInitializeIgnoresNull() - { - $target = m::mock(); - Helper::initializeParameters($target, null); - } - - public function testInitializeIgnoresString() - { - $target = m::mock(); - Helper::initializeParameters($target, 'invalid'); - } - public function testInitializeCallsSetters() { $target = m::mock('\Omnipay\Common\CreditCard'); - $target->shouldReceive('setName')->once()->with('adrian'); $target->shouldReceive('setNumber')->once()->with('1234'); - Helper::initializeParameters($target, ['name' => 'adrian', 'number' => '1234']); - } - - public function testInitializeIgnoresInvalidParameters() - { - $target = m::mock('\Omnipay\Common\CreditCard'); - $target->shouldReceive('setName')->once()->with('adrian'); - - Helper::initializeParameters($target, ['name' => 'adrian', 'extra' => 'invalid']); + Helper::initializeParameters($target, ['number' => '1234']); } public function testGetGatewayShortNameSimple() From 24325f1c50c63494ef4540b417e1adaa8ebaa6f6 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Sat, 13 Feb 2016 15:07:55 +0100 Subject: [PATCH 4/4] Fix composer, update phpdocs --- composer.json | 1 - src/Omnipay/Common/Customer.php | 78 ++++++++++++++++----------------- 2 files changed, 39 insertions(+), 40 deletions(-) diff --git a/composer.json b/composer.json index e81c6866..1f680de6 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,6 @@ "require": { "php": ">=5.6", "alcohol/iso4217": "^3.1", - "beberlei/assert": "^2.4", "guzzlehttp/guzzle": "^6.0", "psr/http-message": "^1.0", "zendframework/zend-diactoros": "^1.1.0" diff --git a/src/Omnipay/Common/Customer.php b/src/Omnipay/Common/Customer.php index c0a7d191..5d05078b 100644 --- a/src/Omnipay/Common/Customer.php +++ b/src/Omnipay/Common/Customer.php @@ -18,7 +18,7 @@ public function __construct(array $parameters = []) } /** - * Get Card Title. + * Get Customer Title. * * @return string */ @@ -28,7 +28,7 @@ public function getTitle() } /** - * Set Card Title. + * Set Customer Title. * * @param string $value Parameter value * @return CreditCard provides a fluent interface. @@ -41,7 +41,7 @@ public function setTitle($value) } /** - * Get Card First Name. + * Get Customer First Name. * * @return string */ @@ -51,10 +51,10 @@ public function getFirstName() } /** - * Set Card First Name (Billing and Shipping). + * Set Customer First Name (Billing and Shipping). * * @param string $value Parameter value - * @return CreditCard provides a fluent interface. + * @return $this provides a fluent interface. */ public function setFirstName($value) { @@ -64,7 +64,7 @@ public function setFirstName($value) } /** - * Get Card Last Name. + * Get Customer Last Name. * * @return string */ @@ -74,10 +74,10 @@ public function getLastName() } /** - * Set Card Last Name (Billing and Shipping). + * Set Customer Last Name (Billing and Shipping). * * @param string $value Parameter value - * @return CreditCard provides a fluent interface. + * @return $this provides a fluent interface. */ public function setLastName($value) { @@ -87,7 +87,7 @@ public function setLastName($value) } /** - * Get Card Name. + * Get Customer Name. * * @return string */ @@ -97,10 +97,10 @@ public function getName() } /** - * Set Card Name (Billing and Shipping). + * Set Customer Name (Billing and Shipping). * * @param string $value Parameter value - * @return CreditCard provides a fluent interface. + * @return $this provides a fluent interface. */ public function setName($value) { @@ -125,7 +125,7 @@ public function getAddress1() * Sets the address, line 1. * * @param string $value - * @return CreditCard provides a fluent interface. + * @return $this provides a fluent interface. */ public function setAddress1($value) { @@ -135,7 +135,7 @@ public function setAddress1($value) } /** - * Get the address, line 2. + * Get the address, line 2. * * @return string */ @@ -148,7 +148,7 @@ public function getAddress2() * Sets the address, line 2. * * @param string $value - * @return CreditCard provides a fluent interface. + * @return $this provides a fluent interface. */ public function setAddress2($value) { @@ -158,7 +158,7 @@ public function setAddress2($value) } /** - * Get the city. + * Get the city. * * @return string */ @@ -171,7 +171,7 @@ public function getCity() * Sets the city. * * @param string $value - * @return CreditCard provides a fluent interface. + * @return $this provides a fluent interface. */ public function setCity($value) { @@ -181,7 +181,7 @@ public function setCity($value) } /** - * Get the postcode. + * Get the postcode. * * @return string */ @@ -194,7 +194,7 @@ public function getPostcode() * Sets the postcode. * * @param string $value - * @return CreditCard provides a fluent interface. + * @return $this provides a fluent interface. */ public function setPostcode($value) { @@ -204,7 +204,7 @@ public function setPostcode($value) } /** - * Get the state. + * Get the state. * * @return string */ @@ -217,7 +217,7 @@ public function getState() * Sets the state. * * @param string $value - * @return CreditCard provides a fluent interface. + * @return $this provides a fluent interface. */ public function setState($value) { @@ -227,7 +227,7 @@ public function setState($value) } /** - * Get the country. + * Get the country. * * @return string */ @@ -240,7 +240,7 @@ public function getCountry() * Sets the country. * * @param string $value - * @return CreditCard provides a fluent interface. + * @return $this provides a fluent interface. */ public function setCountry($value) { @@ -250,7 +250,7 @@ public function setCountry($value) } /** - * Get the phone number. + * Get the phone number. * * @return string */ @@ -263,7 +263,7 @@ public function getPhone() * Sets the phone number. * * @param string $value - * @return CreditCard provides a fluent interface. + * @return $this provides a fluent interface. */ public function setPhone($value) { @@ -273,7 +273,7 @@ public function setPhone($value) } /** - * Get the phone number extension. + * Get the phone number extension. * * @return string */ @@ -286,7 +286,7 @@ public function getPhoneExtension() * Sets the phone number extension. * * @param string $value - * @return CreditCard provides a fluent interface. + * @return $this provides a fluent interface. */ public function setPhoneExtension($value) { @@ -296,7 +296,7 @@ public function setPhoneExtension($value) } /** - * Get the fax number.. + * Get the fax number.. * * @return string */ @@ -309,7 +309,7 @@ public function getFax() * Sets the fax number. * * @param string $value - * @return CreditCard provides a fluent interface. + * @return $this provides a fluent interface. */ public function setFax($value) { @@ -319,7 +319,7 @@ public function setFax($value) } /** - * Get the card company name. + * Get the company name. * * @return string */ @@ -332,7 +332,7 @@ public function getCompany() * Sets the company name. * * @param string $value - * @return CreditCard provides a fluent interface. + * @return $this provides a fluent interface. */ public function setCompany($value) { @@ -342,7 +342,7 @@ public function setCompany($value) } /** - * Get the cardholder's email address. + * Get the customer's email address. * * @return string */ @@ -352,10 +352,10 @@ public function getEmail() } /** - * Sets the cardholder's email address. + * Sets the customer's email address. * * @param string $value - * @return CreditCard provides a fluent interface. + * @return $this provides a fluent interface. */ public function setEmail($value) { @@ -363,7 +363,7 @@ public function setEmail($value) } /** - * Get the cardholder's birthday. + * Get the customer's birthday. * * @return string */ @@ -375,10 +375,10 @@ public function getBirthday($format = 'Y-m-d') } /** - * Sets the cardholder's birthday. + * Sets the customer's birthday. * * @param string $value - * @return CreditCard provides a fluent interface. + * @return $this provides a fluent interface. */ public function setBirthday($value) { @@ -392,7 +392,7 @@ public function setBirthday($value) } /** - * Get the cardholder's gender. + * Get the customer's gender. * * @return string */ @@ -402,10 +402,10 @@ public function getGender() } /** - * Sets the cardholder's gender. + * Sets the customer's gender. * * @param string $value - * @return CreditCard provides a fluent interface. + * @return $this provides a fluent interface. */ public function setGender($value) {