Skip to content

Commit b976e30

Browse files
author
Maksim Rafalko
committed
removed stored data requests classes; added stored data API calls to authorize/purchase methodsm; updated tests
1 parent 939c928 commit b976e30

File tree

7 files changed

+117
-195
lines changed

7 files changed

+117
-195
lines changed

src/Omnipay/NetBanx/Gateway.php

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,6 @@ 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-
7160
/**
7261
* Capture authorized amount
7362
*
@@ -90,17 +79,6 @@ public function purchase(array $parameters = array())
9079
return $this->createRequest('\Omnipay\NetBanx\Message\PurchaseRequest', $parameters);
9180
}
9281

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-
10482
/**
10583
* Void transaction
10684
*

src/Omnipay/NetBanx/Message/AbstractRequest.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -114,27 +114,6 @@ 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-
138117
/**
139118
* Setter for Card Type
140119
*

src/Omnipay/NetBanx/Message/AuthorizeRequest.php

Lines changed: 92 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@
1818
*/
1919
class AuthorizeRequest extends AbstractRequest
2020
{
21+
const MODE_AUTH = 'ccAuthorize';
22+
const MODE_STORED_DATA_AUTH = 'ccStoredDataAuthorize';
23+
2124
/**
2225
* Method
2326
*
2427
* @var string
2528
*/
26-
protected $txnMode = 'ccAuthorize';
29+
protected $txnMode;
2730

2831
/**
2932
* Get data
@@ -32,8 +35,14 @@ class AuthorizeRequest extends AbstractRequest
3235
*/
3336
public function getData()
3437
{
35-
$this->validate('amount', 'card');
36-
$this->getCard()->validate();
38+
if ($this->getTransactionReference()) {
39+
$this->txnMode = $this->getStoredDataMode();
40+
$this->validate('amount', 'transactionReference');
41+
} else {
42+
$this->txnMode = $this->getBasicMode();
43+
$this->validate('amount', 'card');
44+
$this->getCard()->validate();
45+
}
3746

3847
$data = $this->getBaseData();
3948
$data['txnRequest'] = $this->getXmlString();
@@ -48,14 +57,17 @@ public function getData()
4857
*/
4958
protected function getXmlString()
5059
{
51-
/** @var $card CreditCard */
52-
$card = $this->getCard();
53-
54-
$xml = '<?xml version="1.0" encoding="UTF-8"?>
55-
<ccAuthRequestV1
56-
xmlns="http://www.optimalpayments.com/creditcard/xmlschema/v1"
57-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
58-
xsi:schemaLocation="http://www.optimalpayments.com/creditcard/xmlschema/v1" />';
60+
if ($this->getStoredDataMode() == $this->txnMode) {
61+
$xmlRoot = 'ccStoredDataRequestV1';
62+
} else {
63+
$xmlRoot = 'ccAuthRequestV1';
64+
}
65+
66+
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
67+
<{$xmlRoot}
68+
xmlns=\"http://www.optimalpayments.com/creditcard/xmlschema/v1\"
69+
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
70+
xsi:schemaLocation=\"http://www.optimalpayments.com/creditcard/xmlschema/v1\" />";
5971

6072
$sxml = new \SimpleXMLElement($xml);
6173

@@ -66,47 +78,76 @@ protected function getXmlString()
6678
$merchantAccount->addChild('storePwd', $this->getStorePassword());
6779

6880
$sxml->addChild('merchantRefNum', $this->getCustomerId() ?: 'ref-num - ' . time());
69-
$sxml->addChild('amount', $this->getAmountDecimal());
70-
71-
$cardChild = $sxml->addChild('card');
72-
73-
$cardChild->addChild('cardNum', $card->getNumber());
74-
75-
$cardExpiry = $cardChild->addChild('cardExpiry');
76-
$cardExpiry->addChild('month', $card->getExpiryDate('m'));
77-
$cardExpiry->addChild('year', $card->getExpiryDate('Y'));
78-
79-
$cardChild->addChild('cardType', $this->getCardType() ?: 'VI');
80-
$cardChild->addChild('cvdIndicator', '1');
81-
$cardChild->addChild('cvd', $card->getCvv());
82-
83-
$billingDetails = $sxml->addChild('billingDetails');
84-
85-
$billingDetails->addChild('cardPayMethod', 'WEB');
86-
$billingDetails->addChild('firstName', $card->getBillingFirstName());
87-
$billingDetails->addChild('lastName', $card->getBillingLastName());
88-
$billingDetails->addChild('street', $card->getBillingAddress1());
89-
$billingDetails->addChild('street2', $card->getBillingAddress2());
90-
$billingDetails->addChild('city', $card->getBillingCity());
91-
$billingDetails->addChild('state', $card->getBillingState());
92-
$billingDetails->addChild('country', $card->getBillingCountry());
93-
$billingDetails->addChild('zip', $card->getBillingPostcode());
94-
$billingDetails->addChild('phone', $card->getBillingPhone());
95-
$billingDetails->addChild('email', $card->getEmail());
96-
97-
$shippingDetails = $sxml->addChild('shippingDetails');
98-
99-
$shippingDetails->addChild('firstName', $card->getShippingFirstName());
100-
$shippingDetails->addChild('lastName', $card->getShippingLastName());
101-
$shippingDetails->addChild('street', $card->getShippingAddress1());
102-
$shippingDetails->addChild('street2', $card->getShippingAddress2());
103-
$shippingDetails->addChild('city', $card->getShippingCity());
104-
$shippingDetails->addChild('state', $card->getShippingState());
105-
$shippingDetails->addChild('country', $card->getShippingCountry());
106-
$shippingDetails->addChild('zip', $card->getShippingPostcode());
107-
$shippingDetails->addChild('phone', $card->getShippingPhone());
108-
$shippingDetails->addChild('email', $card->getEmail());
81+
82+
if ($this->getStoredDataMode() == $this->txnMode) {
83+
$sxml->addChild('confirmationNumber', $this->getTransactionReference());
84+
$sxml->addChild('amount', $this->getAmountDecimal());
85+
} else {
86+
/** @var $card CreditCard */
87+
$card = $this->getCard();
88+
89+
$sxml->addChild('amount', $this->getAmountDecimal());
90+
91+
$cardChild = $sxml->addChild('card');
92+
93+
$cardChild->addChild('cardNum', $card->getNumber());
94+
95+
$cardExpiry = $cardChild->addChild('cardExpiry');
96+
$cardExpiry->addChild('month', $card->getExpiryDate('m'));
97+
$cardExpiry->addChild('year', $card->getExpiryDate('Y'));
98+
99+
$cardChild->addChild('cardType', $this->getCardType() ?: 'VI');
100+
$cardChild->addChild('cvdIndicator', '1');
101+
$cardChild->addChild('cvd', $card->getCvv());
102+
103+
$billingDetails = $sxml->addChild('billingDetails');
104+
105+
$billingDetails->addChild('cardPayMethod', 'WEB');
106+
$billingDetails->addChild('firstName', $card->getBillingFirstName());
107+
$billingDetails->addChild('lastName', $card->getBillingLastName());
108+
$billingDetails->addChild('street', $card->getBillingAddress1());
109+
$billingDetails->addChild('street2', $card->getBillingAddress2());
110+
$billingDetails->addChild('city', $card->getBillingCity());
111+
$billingDetails->addChild('state', $card->getBillingState());
112+
$billingDetails->addChild('country', $card->getBillingCountry());
113+
$billingDetails->addChild('zip', $card->getBillingPostcode());
114+
$billingDetails->addChild('phone', $card->getBillingPhone());
115+
$billingDetails->addChild('email', $card->getEmail());
116+
117+
$shippingDetails = $sxml->addChild('shippingDetails');
118+
119+
$shippingDetails->addChild('firstName', $card->getShippingFirstName());
120+
$shippingDetails->addChild('lastName', $card->getShippingLastName());
121+
$shippingDetails->addChild('street', $card->getShippingAddress1());
122+
$shippingDetails->addChild('street2', $card->getShippingAddress2());
123+
$shippingDetails->addChild('city', $card->getShippingCity());
124+
$shippingDetails->addChild('state', $card->getShippingState());
125+
$shippingDetails->addChild('country', $card->getShippingCountry());
126+
$shippingDetails->addChild('zip', $card->getShippingPostcode());
127+
$shippingDetails->addChild('phone', $card->getShippingPhone());
128+
$shippingDetails->addChild('email', $card->getEmail());
129+
}
109130

110131
return $sxml->asXML();
111132
}
133+
134+
/**
135+
* Get Stored Data Mode
136+
*
137+
* @return string
138+
*/
139+
protected function getStoredDataMode()
140+
{
141+
return self::MODE_STORED_DATA_AUTH;
142+
}
143+
144+
/**
145+
* Get Stored Data Mode
146+
*
147+
* @return string
148+
*/
149+
protected function getBasicMode()
150+
{
151+
return self::MODE_AUTH;
152+
}
112153
}

src/Omnipay/NetBanx/Message/PurchaseRequest.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,22 @@
1616
*/
1717
class PurchaseRequest extends AuthorizeRequest
1818
{
19+
const MODE_PURCHASE = 'ccPurchase';
20+
const MODE_STORED_DATA_PURCHASE = 'ccStoredDataPurchase';
21+
22+
/**
23+
* @inheritdoc
24+
*/
25+
protected function getStoredDataMode()
26+
{
27+
return self::MODE_STORED_DATA_PURCHASE;
28+
}
29+
1930
/**
20-
* Method
21-
*
22-
* @var string
31+
* @inheritdoc
2332
*/
24-
protected $txnMode = 'ccPurchase';
33+
protected function getBasicMode()
34+
{
35+
return self::MODE_PURCHASE;
36+
}
2537
}

src/Omnipay/NetBanx/Message/StoredDataAuthorizeRequest.php

Lines changed: 0 additions & 68 deletions
This file was deleted.

src/Omnipay/NetBanx/Message/StoredDataPurchaseRequest.php

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)