1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* |
5
|
|
|
* |
6
|
|
|
* @see: https://www.paymentexpress.com/Technical_Resources/Ecommerce_NonHosted/PxPost |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
class DpsPxPost extends EcommercePayment |
|
|
|
|
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* set the required privacy link as you see fit... |
15
|
|
|
* also see: https://www.paymentexpress.com/About/Artwork_Downloads |
16
|
|
|
* also see: https://www.paymentexpress.com/About/About_DPS/Privacy_Policy |
17
|
|
|
* @var String |
18
|
|
|
*/ |
19
|
|
|
private static $dps_logo_and_link = ' |
|
|
|
|
20
|
|
|
<div id="PXPostPrivacy"> |
21
|
|
|
<a href="https://www.paymentexpress.com/About/About_DPS/Privacy_Policy"> |
22
|
|
|
<img src="https://www.paymentexpress.com/DPS/media/theme/pxlogostackedreg.png" alt="Payment Processor" width="50%" height="50%" /> |
23
|
|
|
</a> |
24
|
|
|
<span> |
25
|
|
|
<a href="https://www.paymentexpress.com/About/About_DPS/Privacy_Policy"> |
26
|
|
|
Payment processing provided by DPS (view Privacy Policy) |
27
|
|
|
</a> |
28
|
|
|
</span> |
29
|
|
|
</div> |
30
|
|
|
'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* we use yes / no as this is more reliable than a boolean value |
34
|
|
|
* for configs |
35
|
|
|
* @var String |
36
|
|
|
*/ |
37
|
|
|
private static $is_test = "yes"; |
|
|
|
|
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* we use yes / no as this is more reliable than a boolean value |
41
|
|
|
* for configs |
42
|
|
|
* @var boolean |
43
|
|
|
*/ |
44
|
|
|
private static $is_live = "no"; |
|
|
|
|
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* |
48
|
|
|
* @var string |
49
|
|
|
*/ |
50
|
|
|
private static $username = ""; |
|
|
|
|
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* |
54
|
|
|
* @var string |
55
|
|
|
*/ |
56
|
|
|
private static $password = ""; |
|
|
|
|
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* type: purchase / Authorisation / refund ... |
60
|
|
|
* @var string |
61
|
|
|
*/ |
62
|
|
|
private static $type = "Purchase"; |
|
|
|
|
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Incomplete (default): Payment created but nothing confirmed as successful |
66
|
|
|
* Success: Payment successful |
67
|
|
|
* Failure: Payment failed during process |
68
|
|
|
* Pending: Payment awaiting receipt/bank transfer etc |
69
|
|
|
*/ |
70
|
|
|
private static $db = array( |
|
|
|
|
71
|
|
|
"CardNumber" => "Varchar(64)", |
72
|
|
|
"NameOnCard" => "Varchar(40)", |
73
|
|
|
"ExpiryDate" => "Varchar(4)", |
74
|
|
|
"CVVNumber" => "Varchar(3)", |
75
|
|
|
"Request" => "Text", |
76
|
|
|
"Response" => "Text" |
77
|
|
|
); |
78
|
|
|
|
79
|
|
|
private static $casting = array( |
|
|
|
|
80
|
|
|
"RequestDetails" => "HTMLText", |
81
|
|
|
"ResponseDetails" => "HTMLText" |
82
|
|
|
); |
83
|
|
|
|
84
|
|
|
public function getCMSFields() |
85
|
|
|
{ |
86
|
|
|
$fields = parent::getCMSFields(); |
87
|
|
|
$fields->addFieldToTab("Root.Details", new LiteralField("Request", $this->getRequestDetails())); |
88
|
|
|
$fields->addFieldToTab("Root.Details", new LiteralField("Response", $this->getResponseDetails())); |
89
|
|
|
return $fields; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Return the payment form fields that should |
94
|
|
|
* be shown on the checkout order form for the |
95
|
|
|
* payment type. Example: for {@link DPSPayment}, |
96
|
|
|
* this would be a set of fields to enter your |
97
|
|
|
* credit card details. |
98
|
|
|
* |
99
|
|
|
* @return FieldList |
100
|
|
|
*/ |
101
|
|
|
public function getPaymentFormFields() |
102
|
|
|
{ |
103
|
|
|
$formHelper = $this->ecommercePaymentFormSetupAndValidationObject(); |
104
|
|
|
$fieldList = $formHelper->getCreditCardPaymentFormFields($this); |
105
|
|
|
$fieldList->insertBefore( |
106
|
|
|
new LiteralField("DpsPxPost_Logo", $this->Config()->get("dps_logo_and_link")), |
107
|
|
|
"DpsPxPost_CreditCard" |
|
|
|
|
108
|
|
|
); |
109
|
|
|
return $fieldList; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Define what fields defined in {@link Order->getPaymentFormFields()} |
114
|
|
|
* should be required. |
115
|
|
|
* |
116
|
|
|
* @see DPSPayment->getPaymentFormRequirements() for an example on how |
117
|
|
|
* this is implemented. |
118
|
|
|
* |
119
|
|
|
* @return array |
|
|
|
|
120
|
|
|
*/ |
121
|
|
|
public function getPaymentFormRequirements() |
122
|
|
|
{ |
123
|
|
|
$formHelper = $this->ecommercePaymentFormSetupAndValidationObject(); |
124
|
|
|
return $formHelper->getCreditCardPaymentFormFields($this); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* returns true if all the data is correct. |
129
|
|
|
* |
130
|
|
|
* @param array $data The form request data - see OrderForm |
131
|
|
|
* @param OrderForm $form The form object submitted on |
132
|
|
|
* |
133
|
|
|
* @return Boolean |
134
|
|
|
*/ |
135
|
|
|
public function validatePayment($data, $form) |
136
|
|
|
{ |
137
|
|
|
$formHelper = $this->ecommercePaymentFormSetupAndValidationObject(); |
138
|
|
|
return $formHelper->validateAndSaveCreditCardInformation($data, $form, $this); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Perform payment processing for the type of |
143
|
|
|
* payment. For example, if this was a credit card |
144
|
|
|
* payment type, you would perform the data send |
145
|
|
|
* off to the payment gateway on this function for |
146
|
|
|
* your payment subclass. |
147
|
|
|
* |
148
|
|
|
* This is used by {@link OrderForm} when it is |
149
|
|
|
* submitted. |
150
|
|
|
* |
151
|
|
|
* @param array $data The form request data - see OrderForm |
152
|
|
|
* @param OrderForm $form The form object submitted on |
153
|
|
|
* |
154
|
|
|
* @return EcommercePayment_Result |
155
|
|
|
*/ |
156
|
|
|
public function processPayment($data, $form) |
157
|
|
|
{ |
158
|
|
|
//save data |
159
|
|
|
$this->write(); |
160
|
|
|
|
161
|
|
|
//get variables |
162
|
|
|
$isTest = $this->isTest(); |
|
|
|
|
163
|
|
|
$order = $this->Order(); |
|
|
|
|
164
|
|
|
//if currency has been pre-set use this |
165
|
|
|
$currency = strtoupper($this->Amount->Currency); |
|
|
|
|
166
|
|
|
//if amout has been pre-set, use this |
167
|
|
|
$amount = $this->Amount->Amount; |
|
|
|
|
168
|
|
|
$username = $this->Config()->get("username"); |
169
|
|
|
$password = $this->Config()->get("password"); |
170
|
|
|
if (!$username || !$password) { |
171
|
|
|
user_error("Make sure to set a username and password."); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
$xml = "<Txn>"; |
175
|
|
|
$xml .= "<PostUsername>".$username."</PostUsername>"; |
176
|
|
|
$xml .= "<PostPassword>".$password."</PostPassword>"; |
177
|
|
|
$xml .= "<CardHolderName>".Convert::raw2xml($this->NameOnCard)."</CardHolderName>"; |
|
|
|
|
178
|
|
|
$xml .= "<CardNumber>".$this->CardNumber."</CardNumber>"; |
|
|
|
|
179
|
|
|
$xml .= "<Amount>".round($amount, 2)."</Amount>"; |
180
|
|
|
$xml .= "<DateExpiry>".$this->ExpiryDate."</DateExpiry>"; |
|
|
|
|
181
|
|
|
$xml .= "<Cvc2>".$this->CVVNumber."</Cvc2>"; |
|
|
|
|
182
|
|
|
$xml .= "<Cvc2Presence>1</Cvc2Presence>"; |
183
|
|
|
$xml .= "<InputCurrency>".Convert::raw2xml(strtoupper($currency))."</InputCurrency>"; |
184
|
|
|
$xml .= "<TxnType>".Convert::raw2xml($this->Config()->get("type"))."</TxnType>"; |
185
|
|
|
$xml .= "<TxnId>".$this->ID."</TxnId>"; |
186
|
|
|
$xml .= "<MerchantReference>".$this->OrderID."</MerchantReference>"; |
|
|
|
|
187
|
|
|
$xml .= "</Txn>"; |
188
|
|
|
$URL = "sec.paymentexpress.com/pxpost.aspx"; |
189
|
|
|
//echo "\n\n\n\nSENT:\n$cmdDoTxnTransaction\n\n\n\n\n$"; |
190
|
|
|
|
191
|
|
|
$ch = curl_init(); |
192
|
|
|
curl_setopt($ch, CURLOPT_URL, "https://".$URL); |
193
|
|
|
curl_setopt($ch, CURLOPT_POST, 1); |
194
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); |
195
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
196
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); //Needs to be included if no *.crt is available to verify SSL certificates |
197
|
|
|
|
198
|
|
|
$result = curl_exec($ch); |
199
|
|
|
curl_close($ch); |
200
|
|
|
|
201
|
|
|
$params = new SimpleXMLElement($result); |
202
|
|
|
$txn = $params->Transaction; |
|
|
|
|
203
|
|
|
|
204
|
|
|
//save basic info |
205
|
|
|
//$this->Request = Convert::raw2sql($xml); |
|
|
|
|
206
|
|
|
$this->Response = str_replace('\n', "\n", Convert::raw2sql(print_r($params, 1))); |
|
|
|
|
207
|
|
|
$this->Message = Convert::raw2sql($txn->CardHolderResponseText." ".$txn->CardHolderResponseDescription); |
|
|
|
|
208
|
|
|
$this->CardNumber = Convert::raw2sql($txn->CardNumber); |
|
|
|
|
209
|
|
|
if ( |
210
|
|
|
$params->Success == 1 && |
211
|
|
|
$amount == $txn->Amount && |
212
|
|
|
$currency == $txn->CurrencyName && |
213
|
|
|
trim($this->OrderID) == trim($txn->MerchantReference) |
|
|
|
|
214
|
|
|
) { |
215
|
|
|
$this->Status = "Success"; |
|
|
|
|
216
|
|
|
$returnObject = EcommercePayment_Success::create(); |
217
|
|
|
} else { |
218
|
|
|
$this->Status = "Failure"; |
|
|
|
|
219
|
|
|
$returnObject = EcommercePayment_Failure::create(); |
220
|
|
|
} |
221
|
|
|
$this->write(); |
222
|
|
|
return $returnObject; |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* are you running in test mode? |
228
|
|
|
* |
229
|
|
|
* @return Boolean |
|
|
|
|
230
|
|
|
*/ |
231
|
|
|
protected function isTest() |
232
|
|
|
{ |
233
|
|
|
if ($this->Config()->get("is_test") == "yes" && $this->Config()->get("is_live") == "no") { |
234
|
|
|
return true; |
235
|
|
|
} elseif ($this->Config()->get("is_test") == "no" && $this->Config()->get("is_live") == "yes") { |
236
|
|
|
return false; |
237
|
|
|
} else { |
238
|
|
|
user_error("Class not set to live or test correctly."); |
239
|
|
|
} |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
public function getRequestDetails() |
243
|
|
|
{ |
244
|
|
|
return "<pre>".$this->Request."</pre>"; |
|
|
|
|
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
public function getResponseDetails() |
248
|
|
|
{ |
249
|
|
|
return "<pre>".$this->Response."</pre>"; |
|
|
|
|
250
|
|
|
} |
251
|
|
|
} |
252
|
|
|
|
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.