-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCreditCardPayFlowPro.php
More file actions
executable file
·297 lines (273 loc) · 12.3 KB
/
Copy pathCreditCardPayFlowPro.php
File metadata and controls
executable file
·297 lines (273 loc) · 12.3 KB
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
<?php
/*Credit Card ssl form for collection of credit card details and submission to bank */
if($_SERVER['SERVER_PORT'] != 443) {
header('HTTP/1.1 301 Moved Permanently');
header('Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
exit();
}
include('includes/DefineCartItemClass.php'); //must be before header.php
include('includes/config.php');
include('includes/session.php');
include('includes/Functions.php');
$Title = _('Secure Credit Card Payment Using Pay Flow Pro');
$Errors= array();
//validation
if (isset($_POST['PayByCreditCard'])){
$InputError = 0;
if(!validate_credit_card_number($_POST['CardNumber'])){
message_log(_('The credit card number does not validate as a mastercard, visa or american express card number'),'error');
$Errors[] = 'CardNumber';
$InputError = 1;
}
if (mktime(1,1,1,intval($_POST['ExpiryMonth']),1,intval($_POST['ExpiryYear'])) < time()){
message_log(_('The credit card appears to have expired, please check the expiry month and year'),'error');
$Errors[] = 'ExpiryMonth';
$Errors[] = 'ExpiryYear';
$InputError = 1;
}
if (!is_numeric($_POST['Cvv'])){
message_log(_('The credit verification value must be numeric'),'error');
$Errors[] = 'Cvv';
$InputError = 1;
}
if ($InputError==0) { //no input errors reported so get on with the payment
if ($_POST['ExpiryMonth'] < 10){
$FormattedExpiryDate = '0' . $_POST['ExpiryMonth'] . $_POST['ExpiryYear'];
} else {
$FormattedExpiryDate = $_POST['ExpiryMonth'] . $_POST['ExpiryYear'];
}
$CharsToReplace = array('-', ' ', '/', '\\', '"', "'", '=','&');
$PayFlowString = 'HOSTPORT=443' .
'&USER=' . $_SESSION['ShopPayFlowUser'] .
'&VENDOR=' . $_SESSION['ShopPayFlowVendor'] .
'&PARTNER=' . $_SESSION['ShopPayFlowMerchant'] .
'&PWD=' . $_SESSION['ShopPayFlowPassword'] .
'&TRXTYPE=S' .
'&TENDER=C' .
'&COMMENT1=' . $_SESSION['ShopDebtorNo'] .
'&COMMENT2=' . str_replace($CharsToReplace,'_',$_SESSION['CustomerDetails']['orderreference']) .
'&ACCT=' . $_POST['CardNumber'] .
'&EXPDATE=' . $FormattedExpiryDate .
'&CVV2=' . $_POST['Cvv'] .
'&AMT=' . number_format($_SESSION['TotalDue'],2,'.','') .
'&TIMEOUT=60' .
'&CLIENTIP=' . $_SERVER['REMOTE_ADDR'] .
'&CURRENCY=' . $_SESSION['CustomerDetails']['currcode'] .
'&VERBOSITY=HIGH';
if($_SESSION['ShopMode']=='test'){
$API_Endpoint = 'https://pilot-payflowpro.paypal.com';
} else {
$API_Endpoint = 'https://payflowpro.paypal.com';
}
$Headers = array();
$Headers[] = "Content-Type: text/namevalue"; //or maybe text/xml
$Headers[] = "X-VPS-Timeout: 30";
$Headers[] = "X-VPS-VIT-OS-Name: Linux"; // Name of your OS
//$Headers[] = "X-VPS-VIT-OS-Version: RHEL 4"; // OS Version
$Headers[] = "X-VPS-VIT-Client-Type: PHP/cURL"; // What you are using
$Headers[] = "X-VPS-VIT-Client-Version: 0.01"; // For your info
$Headers[] = "X-VPS-VIT-Client-Architecture: x86"; // For your info
//$Headers[] = "X-VPS-VIT-Client-Certification-Id: " . $this->ClientCertificationId . ""; // get this from payflowintegrator@paypal.com
$Headers[] = "X-VPS-VIT-Integration-Product: webERP Shop By Logic Works Ltd"; // For your info, would populate with application name
$Headers[] = "X-VPS-VIT-Integration-Version: 0.01"; // Application version
//$Headers[] = "X-VPS-Request-ID: " . $request_id;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
curl_setopt($ch, CURLOPT_HTTPHEADER, $Headers);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");// play as Mozilla
curl_setopt($ch, CURLOPT_HEADER, 1); // tells curl to include headers in response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 45); // times out after 45 secs
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // this line makes it work under https
curl_setopt($ch, CURLOPT_POSTFIELDS, $PayFlowString); //adding POST data
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); //verifies ssl certificate
curl_setopt($ch, CURLOPT_FORBID_REUSE, TRUE); //forces closure of connection when done
curl_setopt($ch, CURLOPT_POST, 1); //data sent as POST
$result = curl_exec($ch);
$Headers = curl_getinfo($ch);
curl_close($ch);
$ResponseArray = array(); //result arrray
if (empty($result)){
message_log(_('Pay Flow payment failed'),'error');
};
$result = strstr($result, 'RESULT');
$ValuesArray = explode('&', $result);
foreach($ValuesArray as $ResultValue) {
$ValueArray2 = explode('=', $ResultValue);
$ResponseArray[$ValueArray2[0]] = $ValueArray2[1];
}
if ($debug==1) {
message_log(_('Sent the Pay Flow Pro Request') . '<br />' . $PayFlowString,'info');
}
if ($debug==1) {
$Message ='';
foreach ($ResponseArray as $Key=>$Response) {
$Message .= '<br />' . $Key . ' = ' . urldecode($Response);
}
message_log($Message,'error');
}
if(sizeof($ResponseArray) == 0 OR $ResponseArray['RESULT']!=0) {
message_log(_('Invalid Pay Flow response. Unable to pay using Pay Flow Credit Card Processing'),'error');
if ($debug==1) {
$Message ='';
foreach ($ResponseArray as $Key=>$Response) {
$Message .= '<br />' . $Key . ' = ' . urldecode($Response);
}
message_log($Message,'error');
}
} else { //transaction successful
$_SESSION['Paid'] = true;
$TransactionID = $ResponseArray['PNREF'];
include('includes/PlaceOrder.php');
message_log(_('Thanks for your order. Please quote your order number') . ': ' . $OrderNo . ' ' . _('in all correspondence') . '<br />' . _('Credit card payment has been successfully completed with the transaction ID') . ': ' . $TransactionID, 'success');
InsertCustomerReceipt($_SESSION['ShopCreditCardBankAccount'], $TransactionID, $OrderNo);
if ($debug==1){
$Message ='';
foreach ($CreditCardResponseArray as $Key=>$Response) {
$Message .= '<br />' . $Key . ' = ' . urldecode($Response);
}
message_log($Message,'info');
}
header('Location: http://' . $_SERVER['HTTP_HOST'] . $RootPath . '/Checkout.php');
exit();
}
}
}
include('includes/header.php');
?>
<script>
jQuery(document).ready(function() {
/* Focus on user name input field*/
jQuery('#CreditCardForm').validate({
rules: {
Cvv:{
minlength: 3
}
},
messages: {
CardNumber: {
creditcard: "<?php echo _('A valid credit card number must be entered') ?>"
},
Cvv: {
digits: "<?php echo _('3 or 4 (for AMEX) digits are expected') ?>",
minlength: "<?php echo _('3 or 4 (for AMEX) digits are expected') ?>"
}
},
errorPlacement: function(error, element) {
error.insertAfter(element);
error.wrap('<p>');
} // end errorPlacement
});
jQuery('#CardNumber').keyup(function(){
var CardNumber = jQuery('#CardNumber').val();
if (CardNumber.substring(0,2) == '51' || CardNumber.substring(0,2) == '52' || CardNumber.substring(0,2) == '53' || CardNumber.substring(0,2) == '54' || CardNumber.substring(0,2) == '55'){
jQuery('#CardImage').attr('src','css/mastercard.jpg');
}
if (CardNumber.substring(0,1) == '4'){
jQuery('#CardImage').attr('src','css/visa.jpg');
}
if (CardNumber.substring(0,2) == '37'){
jQuery('#CardImage').attr('src','css/amex.jpg');
}
if (CardNumber.length==0){
jQuery('#CardImage').attr('src','');
}
});
jQuery('#CreditCardForm :text:first').focus();
jQuery('#CardNumber, #Cvv').bind('input', function() {
jQuery(this).val($(this).val().replace(/[^0-9]/gi, ''));
});
jQuery('#TermsAndConditions').click(function() {
jQuery('#content_block').html('<?php echo '<h1>' . _('Terms and Conditions') . '</h1>' . html_entity_decode($_SESSION['ShopTermsConditions']) ?>');
return false;
});
jQuery('#AboutUs').click(function(){
jQuery('#content_block').html('<?php echo '<h1>' . _('About Us') . '</h1>' . html_entity_decode($_SESSION['ShopAboutUs']) ?>');
return false;
});
jQuery('#PrivacyPolicy').click(function(){
jQuery('#content_block').html('<?php echo '<h1>' . _('Privacy Policy') . '</h1>' . html_entity_decode($_SESSION['ShopPrivacyStatement']) ?>');
return false;
});
jQuery('#ContactUs').click(function(){
jQuery('#content_block').html('<?php echo '<h1>' . _('Contact Details') . '</h1>' . html_entity_decode($_SESSION['ShopContactUs']) ?>');
return false;
});
jQuery('#cart_summary').click(function(){
jQuery('#content_block').load('index.php?Page=ShoppingCart' + ' #content_block');
return false;
});
}
);
</script>
<?php
$MenuLinksHtml = display_sub_categories('','');//recursive function to display through all levels of categories defined
//menu_block - showing category link buttons
echo '<div id="menu_block">' . $MenuLinksHtml . '</div>
<div id="content_block">';
include('includes/InfoLinks.php'); //at the bottom
echo '<div id="credit_card_info">
<form id="CreditCardForm" method="post" action="'. htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '" >
<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />
<table width="100%">
<tr>
<th id="column_heading" colspan="5"><image src="css/secure.png" alt="" /> ' . _('Secure Credit Card Payment') . ' <image src="css/secure.png" alt="" /></th>
</tr>
<tr>
<td><label for="CardNumber" ' . (in_array('CardNumber',$Errors) ? 'class="error"' : '' ) . '>' . _('Card Number') . ':</label></td>
<td><input type="text" name="CardNumber" id="CardNumber" class="required creditcard' . (in_array('CardNumber',$Errors) ? ' error' : '' ) . '" autocomplete="off" maxlength="16" size="17" title="' . _('Enter the credit card number with no spaces or hyphens') . '" value="' . (isset($_POST['CardNumber']) ? $_POST['CardNumber'] : '' ) . '" /></td>
<td class="center"><img id="CardImage" src=""></td>
</tr>
<tr>
<td><label for="ExpiryYear"' . (in_array('ExpiryYear',$Errors) ? 'class="error"' : '' ) . '>' . _('Expiry Date') . ':</label></td>
<td><select name="ExpiryYear" id="ExpiryYear" class="required' . (in_array('ExpiryMonth',$Errors) ? ' error' : '' ) . '" title="' . _('Select the year of your credit card\'s expiry date') . '" >';
$i=0;
$Year = intval(Date('Y'));
while ($i<10){
if (!isset($_POST['Year'])) {
echo '<option value="' . ($Year + $i) . '">' . ($Year + $i) . '</option>';
} else {
echo '<option ' . ($_POST['ExpiryYear']==$i+1 ? 'selected="selected"' : '' ) . ' value="' . ($Year + $i) . '">' . ($Year + $i) . '</option>';
}
$i++;
}
echo '</select>
/ <select name="ExpiryMonth" id="ExpiryMonth" class="required' . (in_array('ExpiryMonth',$Errors) ? ' error' : '' ) . '" title="' . _('Select the month of your credit card\'s expiry date') . '" >';
$i=1;
while ($i<13){
if (!isset($_POST['ExpiryMonth'])) {
echo '<option ' . (Date('m')==$i ? 'selected="selected"' : '' ) . ' value="' . $i . '">' . $i . '</option>';
} else {
echo '<option ' . ($_POST['ExpiryMonth']==$i ? 'selected="selected"' : '' ) . ' value="' . $i . '">' . $i . '</option>';
}
$i++;
}
echo '</select></td>
<td rowspan="2" class="center"><img src="css/cvv.jpg"></td>
</tr>
<tr>
<td><label for="Cvv" ' . (in_array('Cvv',$Errors) ? 'class="error"' : '' ) . '">' . _('Verification Code') . ':</label></td>
<td><input type="text" name="Cvv" id="Cvv" title="' . _('Enter the 3 digit verification code or CVV - note that on AMEX cards this is a 4 digit code') . '" autocomplete="off" class="required digits' . (in_array('Cvv',$Errors) ? 'error' : '' ) . '" value="' . (isset($_POST['Cvv']) ? $_POST['Cvv'] : '' ) . '" maxlength="4" size="5" /></td>
</tr>
<tr>
<td>' . _('Amount') . ' ' . $_SESSION['CustomerDetails']['currcode'] . ':</td>
<td>' . locale_number_format($_SESSION['TotalDue'],$_SESSION['CustomerDetails']['currdecimalplaces']) . '</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td colspan="2"></td>
<td class="center"><input class="button" type="submit" name="PayByCreditCard" title="' . _('Pay By Credit Card') . '" value="' . _('Submit Details and Process Payment') . '"></td>
</tr>
</table>
</div><!-- end credit_card_info --!>
<br />';
if ($_SESSION['ShopMode']=='test'){
message_log(_('The shop is in TEST MODE - no payments will be processed'),'error');
}
display_messages();
echo '</div>'; //end content_block
include ('includes/footer.php');
?>