1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
*@author nicolaas [at] sunnysideup.co.nz |
4
|
|
|
**/ |
5
|
|
|
|
6
|
|
|
class DpsPxPayComs extends Object |
|
|
|
|
7
|
|
|
{ |
8
|
|
|
private static $pxpay_url = 'https://sec.paymentexpress.com/pxaccess/pxpay.aspx'; |
|
|
|
|
9
|
|
|
|
10
|
|
|
private static $pxpay_userid = ""; |
|
|
|
|
11
|
|
|
|
12
|
|
|
private static $pxpay_encryption_key = ""; |
|
|
|
|
13
|
|
|
|
14
|
|
|
private static $alternative_thirdparty_folder = ""; |
15
|
|
|
|
16
|
|
|
private static $overriding_txn_type = ""; //e.g. AUTH |
|
|
|
|
17
|
|
|
|
18
|
|
|
public static function get_txn_type() |
19
|
|
|
{ |
20
|
|
|
$overridingTxnType = Config::inst()->get("DpsPxPayComs", "overriding_txn_type"); |
21
|
|
|
return $overridingTxnType ? $overridingTxnType : "Purchase"; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* customer details |
27
|
|
|
**/ |
28
|
|
|
|
29
|
|
|
protected $TxnData1 = ""; |
30
|
|
|
public function setTxnData1($v) |
31
|
|
|
{ |
32
|
|
|
$this->TxnData1 = $v; |
33
|
|
|
} |
34
|
|
|
protected $TxnData2 = ""; |
35
|
|
|
public function setTxnData2($v) |
36
|
|
|
{ |
37
|
|
|
$this->TxnData2 = $v; |
38
|
|
|
} |
39
|
|
|
protected $TxnData3 = ""; |
40
|
|
|
public function setTxnData3($v) |
41
|
|
|
{ |
42
|
|
|
$this->TxnData3 = $v; |
43
|
|
|
} |
44
|
|
|
protected $EmailAddress = ""; |
45
|
|
|
public function setEmailAddress($v) |
46
|
|
|
{ |
47
|
|
|
$this->EmailAddress = $v; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* order details |
52
|
|
|
**/ |
53
|
|
|
protected $AmountInput = 0; |
54
|
|
|
public function setAmountInput($v) |
55
|
|
|
{ |
56
|
|
|
$this->AmountInput = $v; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
protected $MerchantReference = ""; |
60
|
|
|
public function setMerchantReference($v) |
61
|
|
|
{ |
62
|
|
|
$this->MerchantReference = $v; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
protected $CurrencyInput = "NZD"; |
66
|
|
|
public function setCurrencyInput($v) |
67
|
|
|
{ |
68
|
|
|
$this->CurrencyInput = $v; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
protected $TxnType = "Purchase"; |
72
|
|
|
public function setTxnType($v) |
73
|
|
|
{ |
74
|
|
|
$this->TxnType = $v; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
protected $TxnId = ""; |
78
|
|
|
public function setTxnId($v) |
79
|
|
|
{ |
80
|
|
|
$this->TxnId = $v; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* details of the redirection |
85
|
|
|
**/ |
86
|
|
|
protected $UrlFail = ""; |
87
|
|
|
public function setUrlFail($v) |
88
|
|
|
{ |
89
|
|
|
$this->UrlFail = $v; |
90
|
|
|
} |
91
|
|
|
protected $UrlSuccess = ""; |
92
|
|
|
public function setUrlSuccess($v) |
93
|
|
|
{ |
94
|
|
|
$this->UrlSuccess = $v; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Details to use stored cards |
99
|
|
|
*/ |
100
|
|
|
protected $EnableAddBillCard = 0; |
101
|
|
|
public function setEnableAddBillCard($v) |
102
|
|
|
{ |
103
|
|
|
$this->EnableAddBillCard = $v; |
104
|
|
|
} |
105
|
|
|
protected $BillingId = 0; |
106
|
|
|
public function setBillingId($v) |
107
|
|
|
{ |
108
|
|
|
$this->BillingId = $v; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* external object |
113
|
|
|
**/ |
114
|
|
|
protected $PxPayObject = null; |
115
|
|
|
protected $response = null; |
116
|
|
|
|
117
|
|
|
public function __construct() |
118
|
|
|
{ |
119
|
|
|
if (!self::$alternative_thirdparty_folder) { |
120
|
|
|
self::$alternative_thirdparty_folder = Director::baseFolder().'/payment_dps/code/thirdparty'; |
121
|
|
|
} |
122
|
|
|
require_once(self::$alternative_thirdparty_folder."/PxPay_Curl.inc.php"); |
123
|
|
|
if (!Config::inst()->get("DpsPxPayComs", "pxpay_url")) { |
124
|
|
|
user_error("error in DpsPxPayComs::__construct, self::$pxpay_url not set. ", E_USER_WARNING); |
|
|
|
|
125
|
|
|
} |
126
|
|
|
if (!Config::inst()->get("DpsPxPayComs", "pxpay_userid")) { |
127
|
|
|
user_error("error in DpsPxPayComs::__construct, self::$pxpay_userid not set. ", E_USER_WARNING); |
|
|
|
|
128
|
|
|
} |
129
|
|
|
if (!Config::inst()->get("DpsPxPayComs", "pxpay_encryption_key")) { |
130
|
|
|
user_error("error in DpsPxPayComs::__construct, self::$pxpay_encryption_key not set. ", E_USER_WARNING); |
|
|
|
|
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
$this->PxPayObject = new PxPay_Curl( |
134
|
|
|
Config::inst()->get("DpsPxPayComs", "pxpay_url"), |
135
|
|
|
Config::inst()->get("DpsPxPayComs", "pxpay_userid"), |
136
|
|
|
Config::inst()->get("DpsPxPayComs", "pxpay_encryption_key") |
137
|
|
|
); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/* |
141
|
|
|
* This function formats data into a request and returns redirection URL |
142
|
|
|
* NOTE: you will need to set all the variables prior to running this. |
143
|
|
|
* e.g. $myDPSPxPayComsObject->setMerchantReference("myreferenceHere"); |
144
|
|
|
**/ |
145
|
|
|
public function startPaymentProcess() |
|
|
|
|
146
|
|
|
{ |
147
|
|
|
if (!$this->TxnId) { |
148
|
|
|
$this->TxnId = uniqid("ID"); |
149
|
|
|
} |
150
|
|
|
$request = new PxPayRequest(); |
151
|
|
|
|
152
|
|
|
#Set PxPay properties |
153
|
|
|
if ($this->MerchantReference) { |
154
|
|
|
$request->setMerchantReference($this->MerchantReference); |
155
|
|
|
} else { |
156
|
|
|
user_error("error in DpsPxPayComs::startPaymentProcess, MerchantReference not set. ", E_USER_WARNING); |
157
|
|
|
} |
158
|
|
|
if ($this->AmountInput) { |
159
|
|
|
$request->setAmountInput($this->AmountInput); |
160
|
|
|
} else { |
161
|
|
|
user_error("error in DpsPxPayComs::startPaymentProcess, AmountInput not set. ", E_USER_WARNING); |
162
|
|
|
} |
163
|
|
|
if ($this->TxnData1) { |
164
|
|
|
$request->setTxnData1($this->TxnData1); |
165
|
|
|
} |
166
|
|
|
if ($this->TxnData2) { |
167
|
|
|
$request->setTxnData2($this->TxnData2); |
168
|
|
|
} |
169
|
|
|
if ($this->TxnData3) { |
170
|
|
|
$request->setTxnData3($this->TxnData3); |
171
|
|
|
} |
172
|
|
|
if ($this->TxnType) { |
173
|
|
|
$request->setTxnType($this->TxnType); |
174
|
|
|
} else { |
175
|
|
|
user_error("error in DpsPxPayComs::startPaymentProcess, TxnType not set. ", E_USER_WARNING); |
176
|
|
|
} |
177
|
|
|
if ($this->CurrencyInput) { |
178
|
|
|
$request->setCurrencyInput($this->CurrencyInput); |
179
|
|
|
} else { |
180
|
|
|
user_error("error in DpsPxPayComs::startPaymentProcess, CurrencyInput not set. ", E_USER_WARNING); |
181
|
|
|
} |
182
|
|
|
if ($this->EmailAddress) { |
183
|
|
|
$request->setEmailAddress($this->EmailAddress); |
184
|
|
|
} |
185
|
|
|
if ($this->UrlFail) { |
186
|
|
|
$request->setUrlFail($this->UrlFail); |
187
|
|
|
} else { |
188
|
|
|
user_error("error in DpsPxPayComs::startPaymentProcess, UrlFail not set. ", E_USER_WARNING); |
189
|
|
|
} |
190
|
|
|
if ($this->UrlSuccess) { |
191
|
|
|
$request->setUrlSuccess($this->UrlSuccess); |
192
|
|
|
} else { |
193
|
|
|
user_error("error in DpsPxPayComs::startPaymentProcess, UrlSuccess not set. ", E_USER_WARNING); |
194
|
|
|
} |
195
|
|
|
if ($this->TxnId) { |
196
|
|
|
$request->setTxnId($this->TxnId); |
197
|
|
|
} |
198
|
|
|
if ($this->EnableAddBillCard) { |
199
|
|
|
$request->setEnableAddBillCard($this->EnableAddBillCard); |
200
|
|
|
} |
201
|
|
|
if ($this->BillingId) { |
202
|
|
|
$request->setBillingId($this->BillingId); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/* TODO: |
|
|
|
|
206
|
|
|
$request->setEnableAddBillCard($EnableAddBillCard); |
207
|
|
|
$request->setBillingId($BillingId); |
208
|
|
|
$request->setOpt($Opt); |
209
|
|
|
*/ |
210
|
|
|
|
211
|
|
|
#Call makeRequest function to obtain input XML |
212
|
|
|
$request_string = $this->PxPayObject->makeRequest($request); |
213
|
|
|
|
214
|
|
|
#Obtain output XML |
215
|
|
|
$this->response = new MifMessage($request_string); |
216
|
|
|
#Parse output XML |
217
|
|
|
$url = $this->response->get_element_text("URI"); |
218
|
|
|
//$valid = $this->response->get_attribute("valid"); |
|
|
|
|
219
|
|
|
|
220
|
|
|
#Redirect to payment page |
221
|
|
|
return $url; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
|
225
|
|
|
/* |
|
|
|
|
226
|
|
|
* This function receives information back from the payments page as a response object |
227
|
|
|
* --------------------- RESPONSE DATA --------------------- |
228
|
|
|
* $Success = $responseObject->getSuccess(); # =1 when request succeeds |
229
|
|
|
* $AmountSettlement = $responseObject->getAmountSettlement(); |
230
|
|
|
* $AuthCode = $responseObject->getAuthCode(); # from bank |
231
|
|
|
* $CardName = $responseObject->getCardName(); # e.g. "Visa" |
232
|
|
|
* $CardNumber = $responseObject->getCardNumber(); # Truncated card number |
233
|
|
|
* $DateExpiry = $responseObject->getDateExpiry(); # in mmyy format |
234
|
|
|
* $DpsBillingId = $responseObject->getDpsBillingId(); |
235
|
|
|
* $BillingId = $responseObject->getBillingId(); |
236
|
|
|
* $CardHolderName = $responseObject->getCardHolderName(); |
237
|
|
|
* $DpsTxnRef = $responseObject->getDpsTxnRef(); |
238
|
|
|
* $TxnType = $responseObject->getTxnType(); |
239
|
|
|
* $TxnData1 = $responseObject->getTxnData1(); |
240
|
|
|
* $TxnData2 = $responseObject->getTxnData2(); |
241
|
|
|
* $TxnData3 = $responseObject->getTxnData3(); |
242
|
|
|
* $CurrencySettlement= $responseObject->getCurrencySettlement(); |
243
|
|
|
* $ClientInfo = $responseObject->getClientInfo(); # The IP address of the user who submitted the transaction |
244
|
|
|
* $TxnId = $responseObject->getTxnId(); |
245
|
|
|
* $CurrencyInput = $responseObject->getCurrencyInput(); |
246
|
|
|
* $EmailAddress = $responseObject->getEmailAddress(); |
247
|
|
|
* $MerchantReference = $responseObject->getMerchantReference(); |
248
|
|
|
* $ResponseText = $responseObject->getResponseText(); |
249
|
|
|
* $TxnMac = $responseObject->getTxnMac(); # An indication as to the uniqueness of a card used in relation to others |
250
|
|
|
* |
251
|
|
|
* also see: https://www.paymentexpress.com/technical_resources/ecommerce_hosted/error_codes.html |
252
|
|
|
**/ |
253
|
|
|
|
254
|
|
|
public function processRequestAndReturnResultsAsObject() |
|
|
|
|
255
|
|
|
{ |
256
|
|
|
#getResponse method in PxPay object returns PxPayResponse object |
257
|
|
|
#which encapsulates all the response data |
258
|
|
|
return $this->PxPayObject->getResponse($_REQUEST["result"]); |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
public function getDebugMessage() |
262
|
|
|
{ |
263
|
|
|
$string = "<pre>"; |
264
|
|
|
$string .= print_r($this->PxPayObject, true); |
265
|
|
|
$string .= print_r($this->response, true); |
266
|
|
|
$string .= "</pre>"; |
267
|
|
|
return $string; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
public function debug() |
271
|
|
|
{ |
272
|
|
|
debug::show("debugging DpsPxPayComs"); |
273
|
|
|
echo $this->getDebugMessage(); |
274
|
|
|
} |
275
|
|
|
} |
276
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.