Skip to content

Commit 50f8969

Browse files
committed
Some refactoring (defining baseData for an API type).
1 parent e14977a commit 50f8969

File tree

4 files changed

+47
-46
lines changed

4 files changed

+47
-46
lines changed

src/Message/AbstractRequest.php

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -217,36 +217,6 @@ protected function hashString($string)
217217
throw new InvalidRequestException('Unknown hashing method.');
218218
}
219219

220-
/**
221-
* Base data required for all Sewrver transactions.
222-
*/
223-
protected function getBaseData()
224-
{
225-
$data = array();
226-
227-
$data['request'] = $this->request_code;
228-
229-
$data['mid'] = $this->getMerchantId();
230-
$data['portalid'] = $this->getPortalId();
231-
232-
// Only md5 is used to encode the key for the Server API (no hashing is
233-
// needed over the secure server-to-serever connection).
234-
$data['key'] = md5($this->getPortalKey());
235-
236-
$data['api_version'] = AbstractShopGateway::API_VERSION;
237-
238-
$data['mode'] = (bool)$this->getTestMode() ? AbstractShopGateway::MODE_TEST : AbstractShopGateway::MODE_LIVE;
239-
240-
$data['encoding'] = $this->getEncoding();
241-
$data['language'] = $this->getLanguage();
242-
243-
if ($this->getClearingType()) {
244-
$data['clearingtype'] = $this->getClearingType();
245-
}
246-
247-
return $data;
248-
}
249-
250220
/**
251221
* Collect the personal data to send to the Gateway.
252222
*/

src/Message/ShopFrontendAuthorizeRequest.php

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,15 @@ class ShopFrontendAuthorizeRequest extends ShopServerAuthorizeRequest
4848
protected $defaultItemId = '000000';
4949

5050
/**
51-
* The data is used to generate the POST form to send the user
52-
* off to the PAYONE credit card form.
51+
* Base data required for all Front End transactions.
5352
*/
54-
public function getData()
53+
protected function getBaseData()
5554
{
56-
// The base data.
57-
$data = [
55+
$data = array(
5856
'portalid' => $this->getPortalId(),
59-
'aid' => $this->getSubAccountId(),
6057
'api_version' => AbstractShopGateway::API_VERSION,
61-
'mode' => $this->getTestMode()
58+
'aid' => $this->getSubAccountId(),
59+
'mode' => (bool)$this->getTestMode()
6260
? AbstractShopGateway::MODE_TEST
6361
: AbstractShopGateway::MODE_LIVE,
6462
'request' => $this->getRequestCode(),
@@ -67,7 +65,19 @@ public function getData()
6765
'amount' => $this->getAmountInteger(),
6866
'currency' => $this->getCurrency(),
6967
'encoding' => $this->getEncoding(),
70-
];
68+
);
69+
70+
return $data;
71+
}
72+
73+
/**
74+
* The data is used to generate the POST form to send the user
75+
* off to the PAYONE credit card form.
76+
*/
77+
public function getData()
78+
{
79+
// The base data.
80+
$data = $this->getBaseData();
7181

7282
// Add basket contents next.
7383
// It seems that we MUST have at least one item in
@@ -111,7 +121,7 @@ public function getData()
111121
$data['invoiceid'] = $this->getInvoiceId();
112122
}
113123

114-
// The errorurl does NOT appear in the Frontend documentation, but does
124+
// The errorurl does not appear in the Frontend documentation, but does
115125
// work and is implemented in other platform gateways.
116126

117127
$data += $this->getDataUrl();
@@ -129,7 +139,6 @@ public function getData()
129139
}
130140

131141
// Create the hash.
132-
// All data collected so far must be "protected" by the hash.
133142
$data['hash'] = $this->hashArray($data);
134143

135144
$data += $this->getDataPersonal();

src/Message/ShopServerAuthorizeRequest.php

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,50 @@
66
* PAYONE Shop Authorize Request
77
*/
88

9+
use Omnipay\Payone\AbstractShopGateway;
10+
911
class ShopServerAuthorizeRequest extends AbstractRequest
1012
{
1113
/**
1214
* The "request" parameter.
1315
*/
1416
protected $request_code = 'preauthorization';
1517

18+
/**
19+
* Base data required for all Server transactions.
20+
*/
21+
protected function getBaseData()
22+
{
23+
$data = array(
24+
'request' => $this->request_code,
25+
'mid' => $this->getMerchantId(),
26+
'portalid' => $this->getPortalId(),
27+
'api_version' => AbstractShopGateway::API_VERSION,
28+
// Only md5 is used to encode the key for the Server API (no hashing is
29+
// needed over the secure server-to-server connection).
30+
'key' => md5($this->getPortalKey()),
31+
'mode' => (bool)$this->getTestMode()
32+
? AbstractShopGateway::MODE_TEST
33+
: AbstractShopGateway::MODE_LIVE,
34+
'encoding' => $this->getEncoding(),
35+
'language' => $this->getLanguage(),
36+
);
37+
38+
return $data;
39+
}
40+
1641
/**
1742
* Collect the data together to send to the Gateway.
1843
*/
1944
public function getData()
2045
{
2146
$data = $this->getBaseData();
2247

48+
$data['clearingtype'] = $this->getClearingType();
49+
2350
$data['aid'] = $this->getSubAccountId();
2451

2552
// CC details
26-
2753
$data += $this->getDataCard();
2854

2955
// Merchant site reference.
@@ -36,7 +62,6 @@ public function getData()
3662
$data['currency'] = $this->getCurrency();
3763

3864
// Personal data.
39-
4065
$data += $this->getDataPersonal();
4166

4267
if ($this->getParam() !== null) {
@@ -52,15 +77,12 @@ public function getData()
5277
}
5378

5479
// URL orverrides.
55-
5680
$data += $this->getDataUrl();
5781

5882
// Shipping details.
59-
6083
$data += $this->getDataShipping();
6184

6285
// Items/Cart details
63-
6486
$data += $this->getDataItems();
6587

6688
return $data;

src/Message/ShopServerCardCheckRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* PAYONE Shop Server Credit Card Check Request
77
*/
88

9-
class ShopServerCardCheckRequest extends AbstractRequest
9+
class ShopServerCardCheckRequest extends ShopServerAuthorizeRequest
1010
{
1111
/**
1212
* The "request" parameter.

0 commit comments

Comments
 (0)