Skip to content

Commit 39a17ef

Browse files
committed
Issue #112 Tests for Sage Pay Form - encrypting and decrypting
1 parent b90b693 commit 39a17ef

File tree

3 files changed

+152
-224
lines changed

3 files changed

+152
-224
lines changed

src/Message/Form/AuthorizeRequest.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,25 @@ class AuthorizeRequest extends DirectAuthorizeRequest
6464
'FIRecipientDoB' => false,
6565
];
6666

67+
/**
68+
* Add the Form-specific details to the base data.
69+
* @reurn array
70+
*/
71+
public function getData()
72+
{
73+
$this->validate('currency', 'description', 'encryptionKey');
74+
75+
// The test mode is included to determine the redirect URL.
76+
77+
return [
78+
'VPSProtocol' => $this->VPSProtocol,
79+
'TxType' => $this->getTxType(),
80+
'Vendor' => $this->getVendor(),
81+
'Crypt' => $this->generateCrypt($this->getCryptData()),
82+
'TestMode' => $this->getTestMode(),
83+
];
84+
}
85+
6786
/**
6887
* @return array the data required to be encoded into the form crypt field.
6988
*/
@@ -107,8 +126,8 @@ public function getCryptData()
107126
// Two conditional checks on the "state" fields.
108127
// We don't check if it is a valid two-character state code.
109128

110-
if ($data['BillingCountry'] === 'US' && empty ($data['BillingState'])
111-
|| $data['DeliveryCountry'] === 'US' && empty ($data['DeliveryState'])
129+
if ($data['BillingCountry'] === 'US' && empty($data['BillingState'])
130+
|| $data['DeliveryCountry'] === 'US' && empty($data['DeliveryState'])
112131
) {
113132
throw new InvalidRequestException(
114133
'Missing state code for billing or shipping address'
@@ -118,25 +137,6 @@ public function getCryptData()
118137
return $data;
119138
}
120139

121-
/**
122-
* Add the Form-specific details to the base data.
123-
* @reurn array
124-
*/
125-
public function getData()
126-
{
127-
$this->validate('currency', 'description');
128-
129-
// The test mode is included to determine the redirect URL.
130-
131-
return [
132-
'VPSProtocol' => $this->VPSProtocol,
133-
'TxType' => $this->getTxType(),
134-
'Vendor' => $this->getVendor(),
135-
'Crypt' => $this->generateCrypt($this->getCryptData()),
136-
'TestMode' => $this->getTestMode(),
137-
];
138-
}
139-
140140
/**
141141
* Generate the crypt field from the source data.
142142
* @param array $data the name/value pairs to be encrypted

src/Message/Form/CompleteAuthorizeRequest.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function getTxType()
2828
*/
2929
public function getData()
3030
{
31-
$crypt = $this->httpRequest->query->get('crypt');
31+
$crypt = $this->getCrypt() ?: $this->httpRequest->query->get('crypt');
3232

3333
// Remove the leading '@' and decrypt.
3434

@@ -46,10 +46,20 @@ public function getData()
4646
}
4747

4848
/**
49-
* Nothing to send - we have the result data in the server request.
49+
* Nothing to send to gateway - we have the result data in the server request.
5050
*/
5151
public function sendData($data)
5252
{
5353
return $this->response = new Response($this, $data);
5454
}
55+
56+
public function getCrypt()
57+
{
58+
return $this->getParameter('cryptx');
59+
}
60+
61+
public function setCrypt($value)
62+
{
63+
return $this->setParameter('cryptx', $value);
64+
}
5565
}

0 commit comments

Comments
 (0)