Skip to content

Commit c902e94

Browse files
Bradley Westonamacneil
authored andcommitted
Add AcountType, ApplyAVSCV2, and Apply3DSecure parameters. Closes #6
1 parent 157a886 commit c902e94

File tree

3 files changed

+96
-2
lines changed

3 files changed

+96
-2
lines changed

src/Omnipay/SagePay/Message/AbstractRequest.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,76 @@ public function getService()
3636
return $this->action;
3737
}
3838

39+
public function getAccountType()
40+
{
41+
return $this->getParameter('accountType');
42+
}
43+
44+
/**
45+
* Set account type.
46+
*
47+
* This is ignored for all PAYPAL transactions.
48+
*
49+
* @param string $value E: Use the e-commerce merchant account. (default)
50+
* M: Use the mail/telephone order account. (if present)
51+
* C: Use the continuous authority merchant account. (if present)
52+
*/
53+
public function setAccountType($value)
54+
{
55+
return $this->setParameter('accountType', $value);
56+
}
57+
58+
public function getApplyAVSCV2()
59+
{
60+
return $this->getParameter('applyAVSCV2');
61+
}
62+
63+
/**
64+
* Set the apply AVSCV2 checks.
65+
*
66+
* @param int $value 0: If AVS/CV2 enabled then check them. If rules apply, use rules. (default)
67+
* 1: Force AVS/CV2 checks even if not enabled for the account. If rules apply
68+
* use rules.
69+
* 2: Force NO AVS/CV2 checks even if enabled on account.
70+
* 3: Force AVS/CV2 checks even if not enabled for account but DON'T apply any
71+
* rules.
72+
*/
73+
public function setApplyAVSCV2($value)
74+
{
75+
return $this->setParameter('applyAVSCV2', $value);
76+
}
77+
78+
public function getApply3DSecure()
79+
{
80+
return $this->getParameter('apply3DSecure');
81+
}
82+
83+
/**
84+
* Whether or not to apply 3D secure authentication.
85+
*
86+
* This is ignored for PAYPAL, EUROPEAN PAYMENT transactions.
87+
*
88+
* @param int $value 0: If 3D-Secure checks are possible and rules allow, perform the
89+
* checks and apply the authorisation rules. (default)
90+
* 1: Force 3D-Secure checks for this transaction if possible and
91+
* apply rules for authorisation.
92+
* 2: Do not perform 3D-Secure checks for this transactios and always
93+
* authorise.
94+
* 3: Force 3D-Secure checks for this transaction if possible but ALWAYS
95+
* obtain an auth code, irrespective of rule base.
96+
*/
97+
public function setApply3DSecure($value)
98+
{
99+
return $this->setParameter('apply3DSecure', $value);
100+
}
101+
39102
protected function getBaseData()
40103
{
41104
$data = array();
42105
$data['VPSProtocol'] = '2.23';
43106
$data['TxType'] = $this->action;
44107
$data['Vendor'] = $this->getVendor();
108+
$data['AccountType'] = $this->getAccountType() ?: 'E';
45109

46110
return $data;
47111
}

src/Omnipay/SagePay/Message/DirectAuthorizeRequest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ protected function getBaseAuthorizeData()
2424
$data['Currency'] = $this->getCurrency();
2525
$data['VendorTxCode'] = $this->getTransactionId();
2626
$data['ClientIPAddress'] = $this->getClientIp();
27-
$data['ApplyAVSCV2'] = 0; // use account setting
28-
$data['Apply3DSecure'] = 0; // use account setting
27+
$data['ApplyAVSCV2'] = $this->getApplyAVSCV2() ?: 0;
28+
$data['Apply3DSecure'] = $this->getApply3DSecure() ?: 0;
2929

3030
// billing details
3131
$data['BillingFirstnames'] = $card->getFirstName();

tests/Omnipay/SagePay/Message/DirectAuthorizeRequestTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,42 @@ public function setUp()
1414
$this->request->initialize(
1515
array(
1616
'amount' => '12.00',
17+
'currency' => 'GBP',
1718
'transactionId' => '123',
1819
'card' => $this->getValidCard(),
1920
)
2021
);
2122
}
2223

24+
public function testGetDataDefaults()
25+
{
26+
$data = $this->request->getData();
27+
28+
$this->assertSame('E', $data['AccountType']);
29+
$this->assertSame(0, $data['ApplyAVSCV2']);
30+
$this->assertSame(0, $data['Apply3DSecure']);
31+
}
32+
33+
public function testGetData()
34+
{
35+
$this->request->setAccountType('M');
36+
$this->request->setApplyAVSCV2(2);
37+
$this->request->setApply3DSecure(3);
38+
$this->request->setDescription('food');
39+
$this->request->setClientIp('127.0.0.1');
40+
41+
$data = $this->request->getData();
42+
43+
$this->assertSame('M', $data['AccountType']);
44+
$this->assertSame('food', $data['Description']);
45+
$this->assertSame('12.00', $data['Amount']);
46+
$this->assertSame('GBP', $data['Currency']);
47+
$this->assertSame('123', $data['VendorTxCode']);
48+
$this->assertSame('127.0.0.1', $data['ClientIPAddress']);
49+
$this->assertSame(2, $data['ApplyAVSCV2']);
50+
$this->assertSame(3, $data['Apply3DSecure']);
51+
}
52+
2353
public function testGetDataCustomerDetails()
2454
{
2555
$card = $this->request->getCard();

0 commit comments

Comments
 (0)