Skip to content

Commit 4dc3487

Browse files
author
Maksim Rafalko
committed
added 'StoredDataAuthorize' and 'StoredDataPurchase' methods with tests
1 parent ac4fc23 commit 4dc3487

12 files changed

+371
-5
lines changed

src/Omnipay/NetBanx/Gateway.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ public function authorize(array $parameters = array())
5757
return $this->createRequest('\Omnipay\NetBanx\Message\AuthorizeRequest', $parameters);
5858
}
5959

60+
/**
61+
* Authorize a new amount using Confirmation Number
62+
*
63+
* @param array $parameters
64+
* @return mixed
65+
*/
66+
public function storedDataAuthorize(array $parameters = array())
67+
{
68+
return $this->createRequest('\Omnipay\NetBanx\Message\StoredDataAuthorizeRequest', $parameters);
69+
}
70+
6071
/**
6172
* Capture authorized amount
6273
*
@@ -79,6 +90,17 @@ public function purchase(array $parameters = array())
7990
return $this->createRequest('\Omnipay\NetBanx\Message\PurchaseRequest', $parameters);
8091
}
8192

93+
/**
94+
* Create a new charge (combined authorize + capture) using Confirmation Number
95+
*
96+
* @param array An array of options
97+
* @return \Omnipay\ResponseInterface
98+
*/
99+
public function storedDataPurchase(array $parameters = array())
100+
{
101+
return $this->createRequest('\Omnipay\NetBanx\Message\StoredDataPurchaseRequest', $parameters);
102+
}
103+
82104
/**
83105
* Void transaction
84106
*

src/Omnipay/NetBanx/Message/AbstractRequest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,48 @@ public function setCustomerId($value)
114114
return $this->setParameter('customerId', $value);
115115
}
116116

117+
/**
118+
* Getter for Confirmation Number
119+
*
120+
* @return string
121+
*/
122+
public function getConfirmationNumber()
123+
{
124+
return $this->getParameter('confirmationNumber');
125+
}
126+
127+
/**
128+
* Setter for Confirmation Number
129+
*
130+
* @param string $value
131+
* @return $this
132+
*/
133+
public function setConfirmationNumber($value)
134+
{
135+
return $this->setParameter('confirmationNumber', $value);
136+
}
137+
138+
/**
139+
* Setter for Card Type
140+
*
141+
* @param string $value
142+
* @return $this
143+
*/
144+
public function setCardType($value)
145+
{
146+
return $this->setParameter('cardType', $value);
147+
}
148+
149+
/**
150+
* Getter for Card Type
151+
*
152+
* @return string
153+
*/
154+
public function getCardType()
155+
{
156+
return $this->getParameter('cardType');
157+
}
158+
117159
/**
118160
* Send request
119161
*

src/Omnipay/NetBanx/Message/AuthorizeRequest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function getData()
4242
}
4343

4444
/**
45-
* Get XML string (without header)
45+
* Get XML string
4646
*
4747
* @return string
4848
*/
@@ -76,8 +76,8 @@ protected function getXmlString()
7676
$cardExpiry->addChild('month', $card->getExpiryDate('m'));
7777
$cardExpiry->addChild('year', $card->getExpiryDate('Y'));
7878

79-
$cardChild->addChild('cardType', 'VI');
80-
$cardChild->addChild('cvdIndicator', '0');
79+
$cardChild->addChild('cardType', $this->getCardType() ?: 'VI');
80+
$cardChild->addChild('cvdIndicator', '1');
8181
$cardChild->addChild('cvd', $card->getCvv());
8282

8383
$billingDetails = $sxml->addChild('billingDetails');

src/Omnipay/NetBanx/Message/CaptureRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function getData()
3939
}
4040

4141
/**
42-
* Get XML string (without header)
42+
* Get XML string
4343
*
4444
* @return string
4545
*/
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Omnipay package.
5+
*
6+
* (c) Adrian Macneil <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Omnipay\NetBanx\Message;
13+
14+
/**
15+
* NetBanx 'StoredData' Authorize Request
16+
*/
17+
class StoredDataAuthorizeRequest extends AbstractRequest
18+
{
19+
/**
20+
* Method
21+
*
22+
* @var string
23+
*/
24+
protected $txnMode = 'ccStoredDataAuthorize';
25+
26+
/**
27+
* Get data
28+
*
29+
* @return array
30+
*/
31+
public function getData()
32+
{
33+
$this->validate('amount', 'confirmationNumber');
34+
35+
$data = $this->getBaseData();
36+
$data['txnRequest'] = $this->getXmlString();
37+
38+
return $data;
39+
}
40+
41+
/**
42+
* Get XML string
43+
*
44+
* @return string
45+
*/
46+
protected function getXmlString()
47+
{
48+
$xml = '<?xml version="1.0" encoding="UTF-8"?>
49+
<ccStoredDataRequestV1
50+
xmlns="http://www.optimalpayments.com/creditcard/xmlschema/v1"
51+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
52+
xsi:schemaLocation="http://www.optimalpayments.com/creditcard/xmlschema/v1" />';
53+
54+
$sxml = new \SimpleXMLElement($xml);
55+
56+
$merchantAccount = $sxml->addChild('merchantAccount');
57+
58+
$merchantAccount->addChild('accountNum', $this->getAccountNumber());
59+
$merchantAccount->addChild('storeID', $this->getStoreId());
60+
$merchantAccount->addChild('storePwd', $this->getStorePassword());
61+
62+
$sxml->addChild('merchantRefNum', $this->getCustomerId() ?: 'ref-num - ' . time());
63+
$sxml->addChild('confirmationNumber', $this->getConfirmationNumber());
64+
$sxml->addChild('amount', $this->getAmountDecimal());
65+
66+
return $sxml->asXML();
67+
}
68+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/*
3+
* This file is part of the Omnipay package.
4+
*
5+
* (c) Adrian Macneil <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
namespace Omnipay\NetBanx\Message;
12+
13+
/**
14+
* NetBanx 'StoredData' Purchase Request
15+
*/
16+
class StoredDataPurchaseRequest extends StoredDataAuthorizeRequest
17+
{
18+
/**
19+
* Method
20+
*
21+
* @var string
22+
*/
23+
protected $txnMode = 'ccStoredDataPurchase';
24+
}

src/Omnipay/NetBanx/Message/VoidRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function getData()
3939
}
4040

4141
/**
42-
* Get XML string (without header)
42+
* Get XML string
4343
*
4444
* @return string
4545
*/

tests/Omnipay/NetBanx/GatewayTest.php

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public function setUp()
3737
$this->purchaseOptions = array(
3838
'amount' => 9563,
3939
'card' => $card,
40+
'cardType' => 'AM',
4041
'customerId' => '9966441',
4142
);
4243

@@ -51,6 +52,12 @@ public function setUp()
5152
'storePassword' => 'test',
5253
'transactionReference' => '115147689',
5354
);
55+
56+
$this->storedDataOptions = array(
57+
'amount' => 9563,
58+
'customerId' => '9966441',
59+
'confirmationNumber' => '244530120',
60+
);
5461
}
5562

5663
public function testAuthorizeSuccess()
@@ -69,6 +76,7 @@ public function testAuthorizeSuccess()
6976
$this->assertSame('ccAuthorize', $requestData['txnMode']);
7077

7178
$this->assertSame('93401', (string) $sxml->billingDetails->zip);
79+
$this->assertSame('AM', (string) $sxml->card->cardType);
7280

7381
$this->assertTrue(isset($sxml->billingDetails));
7482
$this->assertTrue(isset($sxml->shippingDetails));
@@ -94,6 +102,42 @@ public function testAuthorizeFailure()
94102
$this->assertSame('Invalid txnMode: ccccAuthorize', $response->getMessage());
95103
}
96104

105+
public function testStoredDataAuthorizeSuccess()
106+
{
107+
$this->setMockHttpResponse('StoredDataAuthorizeSuccess.txt');
108+
109+
$request = $this->gateway->storedDataAuthorize($this->storedDataOptions);
110+
$requestData = $request->getData();
111+
112+
$response = $request->send();
113+
114+
$sxml = new \SimpleXMLElement($requestData['txnRequest']);
115+
116+
$this->assertSame('ccStoredDataAuthorize', $requestData['txnMode']);
117+
118+
$this->assertSame('244530120', (string) $sxml->confirmationNumber);
119+
120+
$this->assertSame('95.63', (string) $sxml->amount);
121+
$this->assertSame('9966441', (string) $sxml->merchantRefNum);
122+
123+
$this->assertTrue($response->isSuccessful());
124+
$this->assertSame('244530120', $response->getTransactionReference());
125+
$this->assertSame('No Error', $response->getMessage());
126+
}
127+
128+
public function testStoredDataAuthorizeFailure()
129+
{
130+
$this->setMockHttpResponse('StoredDataAuthorizeFailure.txt');
131+
132+
$response = $this->gateway->storedDataAuthorize($this->storedDataOptions)->send();
133+
134+
$this->assertFalse($response->isSuccessful());
135+
$this->assertSame(
136+
'You submitted an invalid XML request. Please verify your request and retry the transaction.',
137+
$response->getMessage()
138+
);
139+
}
140+
97141
public function testCaptureSuccess()
98142
{
99143
$this->setMockHttpResponse('CaptureSuccess.txt');
@@ -180,6 +224,39 @@ public function testPurchaseFailure()
180224
$this->assertSame('You submitted an unsupported card type with your request.', $response->getMessage());
181225
}
182226

227+
public function testStoredDataPurchaseSuccess()
228+
{
229+
$this->setMockHttpResponse('StoredDataPurchaseSuccess.txt');
230+
231+
$request = $this->gateway->storedDataPurchase($this->storedDataOptions);
232+
$requestData = $request->getData();
233+
234+
$response = $request->send();
235+
236+
$sxml = new \SimpleXMLElement($requestData['txnRequest']);
237+
238+
$this->assertSame('ccStoredDataPurchase', $requestData['txnMode']);
239+
240+
$this->assertSame('244530120', (string) $sxml->confirmationNumber);
241+
242+
$this->assertTrue($response->isSuccessful());
243+
$this->assertSame('244679250', $response->getTransactionReference());
244+
$this->assertSame('No Error', $response->getMessage());
245+
}
246+
247+
public function testStoredDataPurchaseFailure()
248+
{
249+
$this->setMockHttpResponse('StoredDataPurchaseFailure.txt');
250+
251+
$response = $this->gateway->storedDataPurchase($this->storedDataOptions)->send();
252+
253+
$this->assertFalse($response->isSuccessful());
254+
$this->assertSame(
255+
'You submitted an invalid XML request. Please verify your request and retry the transaction.',
256+
$response->getMessage()
257+
);
258+
}
259+
183260
public function testVoidSuccess()
184261
{
185262
$this->setMockHttpResponse('VoidSuccess.txt');
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
HTTP/1.1 200 OK
2+
Connection: close
3+
Date: Sat, 16 Feb 2013 04:22:58 GMT
4+
Server: Microsoft-IIS/6.0
5+
X-Powered-By: ASP.NET
6+
Content-Type: text/html
7+
Content-Length: 1618
8+
Cache-Control: private, must-revalidate, max-age=0
9+
Expires: Tue, 01 Jan 1980 00:00:00 GMT
10+
11+
<ccTxnResponseV1 xmlns="http://www.optimalpayments.com/creditcard/xmlschema/v1">
12+
<confirmationNumber>244678250</confirmationNumber>
13+
<decision>ERROR</decision>
14+
<code>5023</code>
15+
<actionCode>M</actionCode>
16+
<description>You submitted an invalid XML request. Please verify your request and retry the transaction.</description>
17+
<detail>
18+
<tag>InternalResponseCode</tag>
19+
<value>24</value>
20+
</detail>
21+
<detail>
22+
<tag>SubErrorCode</tag>
23+
<value>0</value>
24+
</detail>
25+
<detail>
26+
<tag>InternalResponseDescription</tag>
27+
<value>xml error</value>
28+
</detail>
29+
<detail>
30+
<tag>ErrorDetail</tag>
31+
<value>Errors:
32+
Node: confirmationNumber, Detail: Expected element \'merchantRefNum@http://www.optimalpayments.com/creditcard/xmlschema/v1\' instead of \'confirmationNumber@http://www.optimalpayments.com/creditcard/xmlschema/v1\' here in element ccStoredDataRequestV1@http://www.optimalpayments.com/creditcard/xmlschema/v1
33+
Node: amount, Detail: Expected element \'confirmationNumber@http://www.optimalpayments.com/creditcard/xmlschema/v1\' instead of \'amount@http://www.optimalpayments.com/creditcard/xmlschema/v1\' here in element ccStoredDataRequestV1@http://www.optimalpayments.com/creditcard/xmlschema/v1
34+
Node: ccStoredDataRequestV1, Detail: Expected element \'confirmationNumber@http://www.optimalpayments.com/creditcard/xmlschema/v1\' before the end of the content in element ccStoredDataRequestV1@http://www.optimalpayments.com/creditcard/xmlschema/v1</value>
35+
</detail>
36+
<txnTime>2013-04-25T06:11:51.284-04:00</txnTime>
37+
<duplicateFound>false</duplicateFound>
38+
</ccTxnResponseV1>

0 commit comments

Comments
 (0)