Skip to content

Commit cf93087

Browse files
committed
Customer Vault (tested)
1 parent 77a3ca9 commit cf93087

10 files changed

+118
-6
lines changed

src/Message/AbstractRequest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ protected function getShippingData()
156156
public function sendData($data)
157157
{
158158
$httpResponse = $this->httpClient->post($this->getEndpoint(), null, $data)->send();
159-
echo $httpResponse;
159+
160160
return $this->response = new DirectPostResponse($this, $httpResponse->getBody());
161161
}
162162

src/Message/DirectPostCreateCardRequest.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ public function getData()
2020
$data['ccexp'] = $this->getCard()->getExpiryDate('my');
2121
$data['payment'] = 'creditcard';
2222

23-
return $data;
23+
if ('update_customer' === $this->customer_vault) {
24+
$data['customer_vault_id'] = $this->getCardReference();
25+
}
26+
27+
return array_merge(
28+
$data,
29+
$this->getBillingData(),
30+
$this->getShippingData()
31+
);
2432
}
2533
}

src/Message/DirectPostResponse.php

+9
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,13 @@ public function getTransactionReference()
6060
{
6161
return $this->data['transactionid'];
6262
}
63+
64+
public function getCardReference()
65+
{
66+
if (isset($this->data['customer_vault_id'])) {
67+
return trim($this->data['customer_vault_id']);
68+
}
69+
70+
return null;
71+
}
6372
}

tests/DirectPostGatewayTest.php

+57-4
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,71 @@ public function testCreditFailure()
161161
$this->assertSame('Invalid amount REFID:143498834', $response->getMessage());
162162
}
163163

164-
public function testCreateCard()
164+
public function testCreateCardSuccess()
165165
{
166+
$this->setMockHttpResponse('DirectPostCreateCardSuccess.txt');
166167

168+
$response = $this->gateway->createCard($this->purchaseOptions)->send();
169+
$this->assertTrue($response->isSuccessful());
170+
$this->assertSame('452894459', $response->getCardReference());
171+
$this->assertSame('Customer Added', $response->getMessage());
167172
}
168173

169-
public function testUpdateCard()
174+
public function testCreateCardFailure()
170175
{
176+
$this->setMockHttpResponse('DirectPostCreateCardFailure.txt');
171177

178+
$response = $this->gateway->createCard($this->purchaseOptions)->send();
179+
$this->assertFalse($response->isSuccessful());
180+
$this->assertSame(null, $response->getCardReference());
181+
$this->assertSame('Invalid Credit Card Number REFID:3150032552', $response->getMessage());
172182
}
173183

174-
public function testDeleteCard()
184+
public function testUpdateCardSuccess()
175185
{
176-
186+
$this->setMockHttpResponse('DirectPostUpdateCardSuccess.txt');
187+
188+
$this->purchaseOptions['cardReference'] = '452894459';
189+
190+
$response = $this->gateway->updateCard($this->purchaseOptions)->send();
191+
$this->assertTrue($response->isSuccessful());
192+
$this->assertSame('452894459', $response->getCardReference());
193+
$this->assertSame('Customer Update Successful', $response->getMessage());
194+
}
195+
196+
public function testUpdateCardFailure()
197+
{
198+
$this->setMockHttpResponse('DirectPostUpdateCardFailure.txt');
199+
200+
$this->purchaseOptions['cardReference'] = '000000000';
201+
202+
$response = $this->gateway->updateCard($this->purchaseOptions)->send();
203+
$this->assertFalse($response->isSuccessful());
204+
$this->assertSame('000000000', $response->getCardReference());
205+
$this->assertSame('Invalid Customer Vault Id REFID:3150033161', $response->getMessage());
206+
}
207+
208+
public function testDeleteCardSuccess()
209+
{
210+
$this->setMockHttpResponse('DirectPostDeleteCardSuccess.txt');
211+
212+
$response = $this->gateway->deleteCard(array(
213+
'cardReference' => '452894459'
214+
))->send();
215+
$this->assertTrue($response->isSuccessful());
216+
$this->assertSame(null, $response->getCardReference());
217+
$this->assertSame('Customer Deleted', $response->getMessage());
218+
}
219+
220+
public function testDeleteCardFailure()
221+
{
222+
$this->setMockHttpResponse('DirectPostDeleteCardFailure.txt');
223+
224+
$response = $this->gateway->deleteCard(array(
225+
'cardReference' => '000000000'
226+
))->send();
227+
$this->assertFalse($response->isSuccessful());
228+
$this->assertSame('000000000', $response->getCardReference());
229+
$this->assertSame('Invalid Customer Vault Id REFID:3150033421', $response->getMessage());
177230
}
178231
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
HTTP/1.1 200 OK
2+
Date: Wed, 11 Feb 2015 17:32:18 GMT
3+
Server: Apache
4+
Content-Length: 151
5+
Content-Type: text/html; charset=UTF-8
6+
7+
response=3&responsetext=Invalid Credit Card Number REFID:3150032552&authcode=&transactionid=&avsresponse=&cvvresponse=&orderid=&type=&response_code=300
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
HTTP/1.1 200 OK
2+
Date: Wed, 11 Feb 2015 17:03:20 GMT
3+
Server: Apache
4+
Content-Length: 150
5+
Content-Type: text/html; charset=UTF-8
6+
7+
response=1&responsetext=Customer Added&authcode=&transactionid=&avsresponse=&cvvresponse=&orderid=&type=&response_code=100&customer_vault_id=452894459
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
HTTP/1.1 200 OK
2+
Date: Wed, 11 Feb 2015 17:47:06 GMT
3+
Server: Apache
4+
Content-Length: 178
5+
Content-Type: text/html; charset=UTF-8
6+
7+
response=3&responsetext=Invalid Customer Vault Id REFID:3150033421&authcode=&transactionid=&avsresponse=&cvvresponse=&orderid=&type=&response_code=300&customer_vault_id=000000000
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
HTTP/1.1 200 OK
2+
Date: Wed, 11 Feb 2015 17:47:37 GMT
3+
Server: Apache
4+
Content-Length: 124
5+
Content-Type: text/html; charset=UTF-8
6+
7+
response=1&responsetext=Customer Deleted&authcode=&transactionid=&avsresponse=&cvvresponse=&orderid=&type=&response_code=100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
HTTP/1.1 200 OK
2+
Date: Wed, 11 Feb 2015 17:42:42 GMT
3+
Server: Apache
4+
Content-Length: 178
5+
Content-Type: text/html; charset=UTF-8
6+
7+
response=3&responsetext=Invalid Customer Vault Id REFID:3150033161&authcode=&transactionid=&avsresponse=&cvvresponse=&orderid=&type=&response_code=300&customer_vault_id=000000000
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
HTTP/1.1 200 OK
2+
Date: Wed, 11 Feb 2015 17:41:07 GMT
3+
Server: Apache
4+
Content-Length: 162
5+
Content-Type: text/html; charset=UTF-8
6+
7+
response=1&responsetext=Customer Update Successful&authcode=&transactionid=&avsresponse=&cvvresponse=&orderid=&type=&response_code=100&customer_vault_id=452894459

0 commit comments

Comments
 (0)