Skip to content

Commit a5f95f4

Browse files
Do not pass expiry details for procesing a token payment.
These are not required & have already been passed, so leave out if not available.
1 parent 25e7568 commit a5f95f4

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

src/Message/RapidDirectAbstractRequest.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,12 @@ protected function getBaseData()
6262
if ($this->getCard()) {
6363
$data['Customer']['CardDetails'] = array();
6464
$data['Customer']['CardDetails']['Name'] = $this->getCard()->getName();
65-
$data['Customer']['CardDetails']['ExpiryMonth'] = $this->getCard()->getExpiryDate('m');
66-
$data['Customer']['CardDetails']['ExpiryYear'] = $this->getCard()->getExpiryDate('y');
65+
66+
if ($this->getCard()->getExpiryDate('y')) {
67+
// Expiry date not required if token present
68+
$data['Customer']['CardDetails']['ExpiryMonth'] = $this->getCard()->getExpiryDate('m');
69+
$data['Customer']['CardDetails']['ExpiryYear'] = $this->getCard()->getExpiryDate('y');
70+
}
6771
$data['Customer']['CardDetails']['CVN'] = $this->getCard()->getCvv();
6872

6973
if ($this->getEncryptedCardNumber()) {

tests/Message/RapidDirectCreateCardRequestTest.php

+32-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,38 @@ public function testGetData()
6969
$this->assertSame('4111111111111111', $data['Customer']['CardDetails']['Number']);
7070
$this->assertSame('12', $data['Customer']['CardDetails']['ExpiryMonth']);
7171
}
72-
72+
73+
/**
74+
* Test that expiry is optional and not mis-set if token is present.
75+
*/
76+
public function testGetDataNoExpiryTokenPresent()
77+
{
78+
$this->request->initialize(array(
79+
'apiKey' => 'my api key',
80+
'password' => 'secret',
81+
'transactionId' => '999',
82+
'description' => 'new car',
83+
'currency' => 'AUD',
84+
'invoiceReference' => 'INV-123',
85+
'card' => array(
86+
'title' => 'Mr.',
87+
'firstName' => 'John',
88+
'lastName' => 'Smith',
89+
'shippingFirstName' => 'Bob',
90+
'shippingLastName' => 'Mann',
91+
'shippingAddress1' => 'Level 1',
92+
'shippingAddress2' => '123 Test Lane',
93+
'shippingState' => 'NSW',
94+
'shippingCountry' => 'AU',
95+
'cardReference' => 'myRef',
96+
),
97+
));
98+
99+
$data = $this->request->getData();
100+
$this->assertTrue(!isset($data['Customer']['CardDetails']['ExpiryMonth']));
101+
$this->assertTrue(!isset($data['Customer']['CardDetails']['ExpiryYear']));
102+
}
103+
73104
public function testSendSuccess()
74105
{
75106
$this->setMockHttpResponse('RapidDirectCreateCardRequestSuccess.txt');

0 commit comments

Comments
 (0)