-
Notifications
You must be signed in to change notification settings - Fork 18
/
PurchaseRequest.php
201 lines (169 loc) · 5.43 KB
/
PurchaseRequest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php
namespace Omnipay\WorldPay\Message;
use Omnipay\Common\Message\AbstractRequest;
/**
* WorldPay Purchase Request
*/
class PurchaseRequest extends AbstractRequest
{
protected $liveEndpoint = 'https://secure.worldpay.com/wcc/purchase';
protected $testEndpoint = 'https://secure-test.worldpay.com/wcc/purchase';
public function setSignatureFields($value)
{
return $this->setParameter('signatureFields', $value);
}
public function getSignatureFields()
{
return $this->getParameter('signatureFields');
}
public function getInstallationId()
{
return $this->getParameter('installationId');
}
public function setInstallationId($value)
{
return $this->setParameter('installationId', $value);
}
public function getAccountId()
{
return $this->getParameter('accountId');
}
public function setAccountId($value)
{
return $this->setParameter('accountId', $value);
}
public function getSecretWord()
{
return $this->getParameter('secretWord');
}
public function setSecretWord($value)
{
return $this->setParameter('secretWord', $value);
}
public function getCallbackPassword()
{
return $this->getParameter('callbackPassword');
}
public function setCallbackPassword($value)
{
return $this->setParameter('callbackPassword', $value);
}
/**
* Pre-selects the card type being used and bypasses the card type selection screen.
* Must match one of: https://support.worldpay.com/support/kb/bg/customisingadvanced/custa9102.html
*
* @param string
*/
public function getPaymentType()
{
return $this->getParameter('paymentType');
}
public function setPaymentType($value)
{
return $this->setParameter('paymentType', $value);
}
/**
* If true, hides WorldPay's language selection menu.
*
* @param boolean
*/
public function getNoLanguageMenu()
{
return $this->getParameter('noLanguageMenu');
}
public function setNoLanguageMenu($value)
{
return $this->setParameter('noLanguageMenu', $value);
}
/**
* If true, prevents editing of address details by user.
*
* @param boolean
*/
public function getFixContact()
{
return $this->getParameter('fixContact');
}
public function setFixContact($value)
{
return $this->setParameter('fixContact', $value);
}
/**
* If true, hides address details from user.
*
* @param boolean
*/
public function getHideContact()
{
return $this->getParameter('hideContact');
}
public function setHideContact($value)
{
return $this->setParameter('hideContact', $value);
}
/**
* If true, hides currency options from user.
*
* @param boolean
*/
public function getHideCurrency()
{
return $this->getParameter('hideCurrency');
}
public function setHideCurrency($value)
{
return $this->setParameter('hideCurrency', $value);
}
public function getData()
{
$this->validate('amount');
// Either the nodifyUrl or the returnUrl can be provided.
// The returnUrl is deprecated, as strictly this is a notifyUrl.
if (!$this->getNotifyUrl()) {
$this->validate('returnUrl');
}
$data = array();
$data['instId'] = $this->getInstallationId();
$data['accId1'] = $this->getAccountId();
$data['cartId'] = $this->getTransactionId();
$data['desc'] = $this->getDescription();
$data['amount'] = $this->getAmount();
$data['currency'] = $this->getCurrency();
$data['testMode'] = $this->getTestMode() ? 100 : 0;
$data['MC_callback'] = $this->getNotifyUrl() ?: $this->getReturnUrl();
$data['MC_returnurl'] = $this->getReturnUrl();
$data['paymentType'] = $this -> getPaymentType();
$data['noLanguageMenu'] = $this -> getNoLanguageMenu();
$data['fixContact'] = $this -> getFixContact();
$data['hideContact'] = $this -> getHideContact();
$data['hideCurrency'] = $this -> getHideCurrency();
if ($this->getCard()) {
$data['name'] = $this->getCard()->getName();
$data['address1'] = $this->getCard()->getAddress1();
$data['address2'] = $this->getCard()->getAddress2();
$data['town'] = $this->getCard()->getCity();
$data['region'] = $this->getCard()->getState();
$data['postcode'] = $this->getCard()->getPostcode();
$data['country'] = $this->getCard()->getCountry();
$data['tel'] = $this->getCard()->getPhone();
$data['email'] = $this->getCard()->getEmail();
}
if ($this->getSecretWord()) {
$data['signatureFields'] = $this->getSignatureFields();
$signature_data = array($this->getSecretWord());
foreach (explode(':', $data['signatureFields']) as $parameterName) {
$signature_data[] = $data[$parameterName];
}
$data['signature'] = md5(implode(':', $signature_data));
}
return $data;
}
public function sendData($data)
{
return $this->response = new PurchaseResponse($this, $data);
}
public function getEndpoint()
{
return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint;
}
}