Skip to content

Commit d380791

Browse files
author
Maksim Rafalko
committed
removed set/get CreditType, added translator method
1 parent b976e30 commit d380791

File tree

3 files changed

+49
-26
lines changed

3 files changed

+49
-26
lines changed

src/Omnipay/NetBanx/Message/AbstractRequest.php

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Omnipay\NetBanx\Message;
1313

14+
use Omnipay\Common\CreditCard;
15+
1416
/**
1517
* NetBanx Abstract Request
1618
*/
@@ -114,27 +116,6 @@ public function setCustomerId($value)
114116
return $this->setParameter('customerId', $value);
115117
}
116118

117-
/**
118-
* Setter for Card Type
119-
*
120-
* @param string $value
121-
* @return $this
122-
*/
123-
public function setCardType($value)
124-
{
125-
return $this->setParameter('cardType', $value);
126-
}
127-
128-
/**
129-
* Getter for Card Type
130-
*
131-
* @return string
132-
*/
133-
public function getCardType()
134-
{
135-
return $this->getParameter('cardType');
136-
}
137-
138119
/**
139120
* Send request
140121
*
@@ -171,4 +152,47 @@ protected function getBaseData()
171152

172153
return $data;
173154
}
155+
156+
/**
157+
* Translate card type to internal NetBanx format
158+
*
159+
* @param string $brand
160+
* @return string
161+
*/
162+
protected function translateCardType($brand)
163+
{
164+
switch ($brand) {
165+
case CreditCard::BRAND_VISA:
166+
$cardType = 'VI';
167+
break;
168+
case CreditCard::BRAND_AMEX:
169+
$cardType = 'AM';
170+
break;
171+
case CreditCard::BRAND_DISCOVER:
172+
$cardType = 'DI';
173+
break;
174+
case CreditCard::BRAND_MASTERCARD:
175+
$cardType = 'MC';
176+
break;
177+
case CreditCard::BRAND_MAESTRO:
178+
$cardType = 'MD';
179+
break;
180+
case CreditCard::BRAND_LASER:
181+
$cardType = 'LA';
182+
break;
183+
case CreditCard::BRAND_SOLO:
184+
$cardType = 'SO';
185+
break;
186+
case CreditCard::BRAND_JCB:
187+
$cardType = 'JC';
188+
break;
189+
case CreditCard::BRAND_DINERS_CLUB:
190+
$cardType = 'DC';
191+
break;
192+
default:
193+
$cardType = 'VI';
194+
}
195+
196+
return $cardType;
197+
}
174198
}

src/Omnipay/NetBanx/Message/AuthorizeRequest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function getData()
5757
*/
5858
protected function getXmlString()
5959
{
60-
if ($this->getStoredDataMode() == $this->txnMode) {
60+
if ($this->getTransactionReference()) {
6161
$xmlRoot = 'ccStoredDataRequestV1';
6262
} else {
6363
$xmlRoot = 'ccAuthRequestV1';
@@ -79,7 +79,7 @@ protected function getXmlString()
7979

8080
$sxml->addChild('merchantRefNum', $this->getCustomerId() ?: 'ref-num - ' . time());
8181

82-
if ($this->getStoredDataMode() == $this->txnMode) {
82+
if ($this->getTransactionReference()) {
8383
$sxml->addChild('confirmationNumber', $this->getTransactionReference());
8484
$sxml->addChild('amount', $this->getAmountDecimal());
8585
} else {
@@ -96,7 +96,7 @@ protected function getXmlString()
9696
$cardExpiry->addChild('month', $card->getExpiryDate('m'));
9797
$cardExpiry->addChild('year', $card->getExpiryDate('Y'));
9898

99-
$cardChild->addChild('cardType', $this->getCardType() ?: 'VI');
99+
$cardChild->addChild('cardType', $this->translateCardType($card->getBrand()));
100100
$cardChild->addChild('cvdIndicator', '1');
101101
$cardChild->addChild('cvd', $card->getCvv());
102102

tests/Omnipay/NetBanx/GatewayTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public function setUp()
3737
$this->purchaseOptions = array(
3838
'amount' => 9563,
3939
'card' => $card,
40-
'cardType' => 'AM',
4140
'customerId' => '9966441',
4241
);
4342

@@ -76,7 +75,7 @@ public function testAuthorizeSuccess()
7675
$this->assertSame('ccAuthorize', $requestData['txnMode']);
7776

7877
$this->assertSame('93401', (string) $sxml->billingDetails->zip);
79-
$this->assertSame('AM', (string) $sxml->card->cardType);
78+
$this->assertSame('VI', (string) $sxml->card->cardType);
8079

8180
$this->assertTrue(isset($sxml->billingDetails));
8281
$this->assertTrue(isset($sxml->shippingDetails));

0 commit comments

Comments
 (0)