Skip to content

Commit 3d086c7

Browse files
author
Peter
committed
Add/update CreditCard methods for consistency. Update tests
1 parent 06208d0 commit 3d086c7

File tree

2 files changed

+102
-14
lines changed

2 files changed

+102
-14
lines changed

src/Omnipay/Common/CreditCard.php

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,34 +149,39 @@ public function validate()
149149

150150
public function getFirstName()
151151
{
152-
return $this->getParameter('firstName');
152+
return $this->getBillingFirstName();
153153
}
154154

155155
public function setFirstName($value)
156156
{
157-
return $this->setParameter('firstName', $value);
157+
$this->setBillingFirstName($value);
158+
$this->setShippingFirstName($value);
159+
160+
return $this;
158161
}
159162

160163
public function getLastName()
161164
{
162-
return $this->getParameter('lastName');
165+
return $this->getBillingLastName();
163166
}
164167

165168
public function setLastName($value)
166169
{
167-
return $this->setParameter('lastName', $value);
170+
$this->setBillingLastName($value);
171+
$this->setShippingLastName($value);
172+
173+
return $this;
168174
}
169175

170176
public function getName()
171177
{
172-
return trim($this->getFirstName().' '.$this->getLastName());
178+
return $this->getBillingName();
173179
}
174180

175181
public function setName($value)
176182
{
177-
$names = explode(' ', $value, 2);
178-
$this->setParameter('firstName', $names[0]);
179-
$this->setParameter('lastName', isset($names[1]) ? $names[1] : null);
183+
$this->setBillingName($value);
184+
$this->setShippingName($value);
180185

181186
return $this;
182187
}
@@ -288,6 +293,40 @@ public function setIssueNumber($value)
288293
return $this->setParameter('issueNumber', $value);
289294
}
290295

296+
public function getBillingName()
297+
{
298+
return trim($this->getBillingFirstName() . ' ' . $this->getBillingLastName());
299+
}
300+
301+
public function setBillingName($value)
302+
{
303+
$names = explode(' ', $value, 2);
304+
$this->setBillingFirstName($names[0]);
305+
$this->setBillingLastName(isset($names[1]) ? $names[1] : null);
306+
307+
return $this;
308+
}
309+
310+
public function getBillingFirstName()
311+
{
312+
return $this->getParameter('billingFirstName');
313+
}
314+
315+
public function setBillingFirstName($value)
316+
{
317+
return $this->setParameter('billingFirstName', $value);
318+
}
319+
320+
public function getBillingLastName()
321+
{
322+
return $this->getParameter('billingLastName');
323+
}
324+
325+
public function setBillingLastName($value)
326+
{
327+
return $this->setParameter('billingLastName', $value);
328+
}
329+
291330
public function getBillingAddress1()
292331
{
293332
return $this->getParameter('billingAddress1');
@@ -358,6 +397,20 @@ public function setBillingPhone($value)
358397
return $this->setParameter('billingPhone', $value);
359398
}
360399

400+
public function getShippingName()
401+
{
402+
return trim($this->getShippingFirstName() . ' ' . $this->getShippingLastName());
403+
}
404+
405+
public function setShippingName($value)
406+
{
407+
$names = explode(' ', $value, 2);
408+
$this->setShippingFirstName($names[0]);
409+
$this->setShippingLastName(isset($names[1]) ? $names[1] : null);
410+
411+
return $this;
412+
}
413+
361414
public function getShippingFirstName()
362415
{
363416
return $this->getParameter('shippingFirstName');

tests/Omnipay/Common/CreditCardTest.php

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ public function testGetParamters()
4949
));
5050

5151
$parameters = $card->getParameters();
52-
$this->assertSame('Example', $parameters['firstName']);
53-
$this->assertSame('Customer', $parameters['lastName']);
52+
$this->assertSame('Example', $parameters['billingFirstName']);
53+
$this->assertSame('Customer', $parameters['billingLastName']);
5454
$this->assertSame('1234', $parameters['number']);
5555
$this->assertSame(6, $parameters['expiryMonth']);
5656
$this->assertSame(2016, $parameters['expiryYear']);
@@ -260,6 +260,13 @@ public function testStartYearTwoDigits()
260260
$this->assertSame(2012, $this->card->getStartYear());
261261
}
262262

263+
public function testStartDate()
264+
{
265+
$this->card->setStartMonth('11');
266+
$this->card->setStartYear('2012');
267+
$this->assertEquals('112012', $this->card->getStartDate('mY'));
268+
}
269+
263270
public function testCvv()
264271
{
265272
$this->card->setCvv('456');
@@ -272,6 +279,17 @@ public function testIssueNumber()
272279
$this->assertSame('12', $this->card->getIssueNumber());
273280
}
274281

282+
public function testBillingName()
283+
{
284+
$this->card->setBillingFirstName('Bob');
285+
$this->card->setBillingLastName('Smith');
286+
$this->assertEquals('Bob Smith', $this->card->getBillingName());
287+
288+
$this->card->setBillingName('John Foo');
289+
$this->assertEquals('John', $this->card->getBillingFirstName());
290+
$this->assertEquals('Foo', $this->card->getBillingLastName());
291+
}
292+
275293
public function testBillingAddress1()
276294
{
277295
$this->card->setBillingAddress1('31 Spooner St');
@@ -321,16 +339,27 @@ public function testBillingPhone()
321339
$this->assertSame('12345', $this->card->getPhone());
322340
}
323341

342+
public function testShippingName()
343+
{
344+
$this->card->setShippingFirstName('Bob');
345+
$this->card->setShippingLastName('Smith');
346+
$this->assertEquals('Bob Smith', $this->card->getShippingName());
347+
348+
$this->card->setShippingName('John Foo');
349+
$this->assertEquals('John', $this->card->getShippingFirstName());
350+
$this->assertEquals('Foo', $this->card->getShippingLastName());
351+
}
352+
324353
public function testShippingFirstName()
325354
{
326-
$this->card->setShippingFirstName('James Bond');
327-
$this->assertEquals('James Bond', $this->card->getShippingFirstName());
355+
$this->card->setShippingFirstName('James');
356+
$this->assertEquals('James', $this->card->getShippingFirstName());
328357
}
329358

330359
public function testShippingLastName()
331360
{
332-
$this->card->setShippingLastName('Doctor No');
333-
$this->assertEquals('Doctor No', $this->card->getShippingLastName());
361+
$this->card->setShippingLastName('Doctor');
362+
$this->assertEquals('Doctor', $this->card->getShippingLastName());
334363
}
335364

336365
public function testShippingCompany()
@@ -437,6 +466,12 @@ public function testPhone()
437466
$this->assertEquals('12345', $this->card->getShippingPhone());
438467
}
439468

469+
public function testCompany()
470+
{
471+
$this->card->setCompany('FooBar');
472+
$this->assertEquals('FooBar', $this->card->getCompany());
473+
}
474+
440475
public function testEmail()
441476
{
442477
$this->card->setEmail('[email protected]');

0 commit comments

Comments
 (0)