Skip to content

Commit 3d93910

Browse files
authored
Merge pull request #173 from craftcms/master
Update Server and Direct gateways to support protocol version 4.0
2 parents 2f47789 + 64e9904 commit 3d93910

12 files changed

+414
-6
lines changed

src/Message/AbstractRequest.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,34 @@ abstract class AbstractRequest extends OmnipayAbstractRequest implements Constan
1717
{
1818
use GatewayParamsTrait;
1919

20+
/**
21+
* Flag whether customer's browser can run javascript.
22+
*/
23+
const BROWSER_JAVASCRIPT_YES = 1;
24+
const BROWSER_JAVASCRIPT_NO = 0;
25+
26+
/**
27+
* Fallback browser language
28+
*/
29+
const BROWSER_LANGUAGE = 'en-GB';
30+
31+
/**
32+
* Dimensions of the challenge window to be displayed to the cardholder.
33+
*
34+
* 01 = 250 x 400
35+
* 02 = 390 x 400
36+
* 03 = 500 x 600
37+
* 04 = 600 x 400
38+
* 05 = Full screen
39+
*
40+
* @var string
41+
*/
42+
const CHALLENGE_WINDOW_SIZE_01 = '01';
43+
const CHALLENGE_WINDOW_SIZE_02 = '02';
44+
const CHALLENGE_WINDOW_SIZE_03 = '03';
45+
const CHALLENGE_WINDOW_SIZE_04 = '04';
46+
const CHALLENGE_WINDOW_SIZE_05 = '05';
47+
2048
/**
2149
* @var string The service name, used in the endpoint URL.
2250
*/
@@ -25,7 +53,7 @@ abstract class AbstractRequest extends OmnipayAbstractRequest implements Constan
2553
/**
2654
* @var string The protocol version number.
2755
*/
28-
protected $VPSProtocol = '3.00';
56+
protected $VPSProtocol = '4.00';
2957

3058
/**
3159
* @var string Endpoint base URLs.

src/Message/DirectAuthorizeRequest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,30 @@ protected function getBaseAuthorizeData()
5656
$data['VendorTxCode'] = $this->getTransactionId();
5757
$data['ClientIPAddress'] = $this->getClientIp();
5858

59+
$data['BrowserJavascriptEnabled'] = $this->getBrowserJavascriptEnabled() ?: static::BROWSER_JAVASCRIPT_NO;
60+
$data['BrowserLanguage'] = $this->getBrowserLanguage() ?: static::BROWSER_LANGUAGE;
61+
$data['ThreeDSNotificationURL'] = $this->getThreeDSNotificationURL();
62+
$data['BrowserAcceptHeader'] = $_SERVER['HTTP_ACCEPT'] ?? null;
63+
$data['BrowserUserAgent'] = $_SERVER['HTTP_USER_AGENT'] ?? null;
64+
$data['ChallengeWindowSize'] = $this->getChallengeWindowSize() ?: static::CHALLENGE_WINDOW_SIZE_05;
65+
66+
// Proctocol v4.00 - if BrowserJavascriptEnabled
67+
$data['BrowserJavaEnabled'] = $this->getBrowserJavaEnabled();
68+
$data['BrowserColorDepth'] = $this->getBrowserColorDepth();
69+
$data['BrowserScreenHeight'] = $this->getBrowserScreenHeight();
70+
$data['BrowserScreenWidth'] = $this->getBrowserScreenWidth();
71+
$data['BrowserTZ'] = $this->getBrowserTZ();
72+
73+
// repeat payments required fields
74+
$data['MITType'] = $this->getMITType();
75+
$data['COFUsage'] = $this->getCOFUsage();
76+
$data['InitiatedType'] = $this->getInitiatedType();
77+
$data['SchemeTraceID'] = $this->getSchemeTraceID();
78+
$data['RecurringExpiry'] = $this->getRecurringExpiry();
79+
$data['RecurringFrequency'] = $this->getRecurringFrequency();
80+
$data['ACSTransID'] = $this->getACSTransID();
81+
$data['DSTransID'] = $this->getDSTransID();
82+
5983
$data['ApplyAVSCV2'] = $this->getApplyAVSCV2() ?: static::APPLY_AVSCV2_DEFAULT;
6084
$data['Apply3DSecure'] = $this->getApply3DSecure() ?: static::APPLY_3DSECURE_APPLY;
6185

src/Message/DirectCompleteAuthorizeRequest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,32 @@ public function getService()
1414
return static::SERVICE_DIRECT3D;
1515
}
1616

17+
/**
18+
* @return array|mixed|string[]
19+
* @throws InvalidResponseException
20+
*/
1721
public function getData()
1822
{
1923
// Inconsistent letter case is intentional.
2024
// The issuing bank will return PaRes, but the merchant
2125
// site must send this result as PARes to Sage Pay.
2226

27+
// New 3D secure logic
28+
if ($this->httpRequest->request->has('cres')) {
29+
$CRes = $this->httpRequest->request->get('cres');
30+
$VPSTxId = $this->httpRequest->request->get('threeDSSessionData');
31+
32+
if (!$VPSTxId) {
33+
throw new InvalidResponseException('3DSecure: Missing VPSTxId');
34+
}
35+
36+
if (!$CRes) {
37+
throw new InvalidResponseException('3DSecure: Missing CRes');
38+
}
39+
40+
return compact('CRes', 'VPSTxId');
41+
}
42+
2343
$data = array(
2444
'MD' => $this->getMd() ?: $this->httpRequest->request->get('MD'),
2545
'PARes' => $this->getPaRes() ?: $this->httpRequest->request->get('PaRes'),

src/Message/Response.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ public function getRedirectMethod()
9696
public function getRedirectData()
9797
{
9898
if ($this->isRedirect()) {
99+
if ($creq = $this->getDataItem('CReq')) {
100+
return [
101+
'creq' => $creq,
102+
'threeDSSessionData' => $this->getVPSTxId(),
103+
];
104+
}
105+
99106
return array(
100107
'PaReq' => $this->getDataItem('PAReq'),
101108
'TermUrl' => $this->getRequest()->getReturnUrl(),

src/Message/SharedRepeatAuthorizeRequest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ public function getData()
9090
$data['BasketXML'] = $basketXML;
9191
}
9292

93+
// Protocol v4.00 support
94+
$data['MITType'] = $this->getMITType();
95+
$data['COFUsage'] = $this->getCOFUsage();
96+
$data['InitiatedType'] = $this->getInitiatedType();
97+
$data['SchemeTraceID'] = $this->getSchemeTraceID();
98+
$data['RecurringExpiry'] = $this->getRecurringExpiry();
99+
$data['RecurringFrequency'] = $this->getRecurringFrequency();
100+
$data['ACSTransID'] = $this->getACSTransID();
101+
$data['DSTransID'] = $this->getDSTransID();
102+
93103
return $data;
94104
}
95105

0 commit comments

Comments
 (0)