| 1 |
<?php |
| 2 |
/* |
| 3 |
PayPal Payment Module |
| 4 |
|
| 5 |
[Procedure 1] Setting Up My Account with PayPal |
| 6 |
My Account - Profile - Website Payment Preferences |
| 7 |
|
| 8 |
* Auto Return: On |
| 9 |
* Return URL : 'The URL of the shop top page'/index.php?page_id='The ID of the cart page'&acting=paypal&acting_return=1 |
| 10 |
When You use SSL, please change 'http://' in 'https://'. In the case of common-use SSL, please make entry of common use SSL. |
| 11 |
You can confirm the ID of the cart page in Home of the Welcart admin panel. |
| 12 |
* Payment Data Transfer: On |
| 13 |
|
| 14 |
|
| 15 |
My Account - Profile - Instant Payment Notification (IPN) |
| 16 |
|
| 17 |
* Notification URL |
| 18 |
'The URL of the shop top page' |
| 19 |
* IPN messages: Enabled |
| 20 |
I recommend "Enabled". |
| 21 |
|
| 22 |
|
| 23 |
[Procedure 2] The editing of this file |
| 24 |
* $usces_paypal_business: Log-in Email |
| 25 |
* $usces_paypal_url: "www.paypal.com" or "www.sandbox.paypal.com" |
| 26 |
* $auth_token: The Identity Token that was published in a page of the Website Payment Preferences. |
| 27 |
* After editing, please save it by a file name of 'paypal.php' in the arbitrary place (note). |
| 28 |
|
| 29 |
Note - At the time of testing, you may save it in the place where there was "epsilon_sample.php". You can just use it. However, this place is deleted in the case of the upgrading of the plug-in. Actually, you must do a setting place outside a "plugins" folder. On this occasion, please appoint the setting place of the module in "Welcart admin panel / a system setting page". |
| 30 |
|
| 31 |
|
| 32 |
[Procedure 3] Add a new payment method in "Welcart admin panel / a General Setting page" |
| 33 |
* A payment method name: A payment method name displayed by a shop.(essential) |
| 34 |
* explanation : The explanation of a payment method displayed by a shop. |
| 35 |
* Type of payment: Choose "the representation supplier settlement". |
| 36 |
* Payment module: Fill it out with "paypal.php". |
| 37 |
* Push the button 'Add a new method for payment'. |
| 38 |
|
| 39 |
*/ |
| 40 |
global $usces; |
| 41 |
$usces->log_flg = 0;//0 : Not take log, 1 : take log |
| 42 |
/*********************************************************************************/ |
| 43 |
// Log-in Email |
| 44 |
$usces_paypal_business = "*********@********.***"; |
| 45 |
//PayPal URL |
| 46 |
$usces_paypal_url = "www.paypal.com"; |
| 47 |
/*********************************************************************************/ |
| 48 |
|
| 49 |
function paypal_check($usces_paypal_url) { |
| 50 |
/*********************************************************************************/ |
| 51 |
//Identity Token |
| 52 |
$auth_token = "**********************************************************"; |
| 53 |
/*********************************************************************************/ |
| 54 |
settlement_log('Start PDT'); |
| 55 |
|
| 56 |
// read the post from PayPal system and add 'cmd' |
| 57 |
$req = 'cmd=_notify-synch'; |
| 58 |
|
| 59 |
$tx_token = $_GET['tx']; |
| 60 |
$req .= '&tx=' . $tx_token . '&at=' . $auth_token; |
| 61 |
|
| 62 |
// post back to PayPal system to validate |
| 63 |
$header .= "POST /cgi-bin/webscr HTTP/1.1\r\n"; |
| 64 |
$header .= "Content-Type: application/x-www-form-urlencoded\r\n"; |
| 65 |
$header .= "Host: " . $usces_paypal_url . "\r\n"; |
| 66 |
$header .= "Content-Length: " . strlen($req) . "\r\n"; |
| 67 |
$header .= "Connection: close\r\n\r\n"; |
| 68 |
$fp = fsockopen ('ssl://'.$usces_paypal_url, 443, $errno, $errstr, 30); |
| 69 |
$results = array(); |
| 70 |
if (!$fp) { |
| 71 |
$results[0] = false; |
| 72 |
settlement_log('connection error PDT'); |
| 73 |
} else { |
| 74 |
fputs ($fp, $header . $req); |
| 75 |
// read the body data |
| 76 |
$res = ''; |
| 77 |
$headerdone = false; |
| 78 |
while (!feof($fp)) { |
| 79 |
$line = fgets ($fp, 1024); |
| 80 |
if (strcmp($line, "\r\n") == 0) { |
| 81 |
// read the header |
| 82 |
$headerdone = true; |
| 83 |
}else if ($headerdone){ |
| 84 |
// header has been read. now read the contents |
| 85 |
$res .= $line; |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
// parse the data |
| 90 |
$lines = explode("\n", $res); |
| 91 |
$keyarray = array(); |
| 92 |
if (strcmp ($lines[0], "SUCCESS") == 0) { |
| 93 |
$results[0] = true; |
| 94 |
for ($i=1; $i<count($lines);$i++){ |
| 95 |
list($key,$val) = explode("=", $lines[$i]); |
| 96 |
$results[urldecode($key)] = urldecode($val); |
| 97 |
} |
| 98 |
$ret = true; |
| 99 |
settlement_log('PDT[SUCCESS]'); |
| 100 |
}else if (strcmp ($lines[0], "FAIL") == 0) { |
| 101 |
$results[0] = false; |
| 102 |
settlement_log(__('PDT Refusal', 'usces') . "\n\t\t\t" . __("PayPal gives back 'FAIL'. Please confirm setting.", 'usces')); |
| 103 |
} |
| 104 |
|
| 105 |
fclose ($fp); |
| 106 |
} |
| 107 |
return $results; |
| 108 |
} |
| 109 |
|
| 110 |
function paypal_ipn_check($usces_paypal_url) { |
| 111 |
settlement_log(__('IPN Start', 'usces')); |
| 112 |
// read the post from PayPal system and add 'cmd' |
| 113 |
$req = 'cmd=_notify-validate'; |
| 114 |
|
| 115 |
foreach ($_POST as $key => $value) { |
| 116 |
$value = urlencode(stripslashes($value)); |
| 117 |
$req .= '&' . $key . '=' . $value; |
| 118 |
} |
| 119 |
// post back to PayPal system to validate |
| 120 |
$header .= "POST /cgi-bin/webscr HTTP/1.1\r\n"; |
| 121 |
$header .= "Content-Type: application/x-www-form-urlencoded\r\n"; |
| 122 |
$header .= "Host: " . $usces_paypal_url . "\r\n"; |
| 123 |
$header .= "Content-Length: " . strlen($req) . "\r\n"; |
| 124 |
$header .= "Connection: close\r\n\r\n"; |
| 125 |
$fp = fsockopen ('ssl://'.$usces_paypal_url, 443, $errno, $errstr, 30); |
| 126 |
|
| 127 |
$item_name = $_POST['item_name']; |
| 128 |
$item_number = $_POST['item_number']; |
| 129 |
$payment_status = $_POST['payment_status']; |
| 130 |
$payment_amount = $_POST['mc_gross']; |
| 131 |
$payment_currency = $_POST['mc_currency']; |
| 132 |
$txn_id = $_POST['txn_id']; |
| 133 |
$receiver_email = $_POST['receiver_email']; |
| 134 |
$payer_email = $_POST['payer_email']; |
| 135 |
|
| 136 |
$results = array(); |
| 137 |
if (!$fp) { |
| 138 |
$results[0] = false; |
| 139 |
settlement_log(__('IPN Connection Error', 'usces')); |
| 140 |
} else { |
| 141 |
fputs ($fp, $header . $req); |
| 142 |
// read the body data |
| 143 |
$res = ''; |
| 144 |
$headerdone = false; |
| 145 |
while (!feof($fp)) { |
| 146 |
$line = fgets ($fp, 1024); |
| 147 |
if (strcmp($line, "\r\n") == 0) { |
| 148 |
// read the header |
| 149 |
$headerdone = true; |
| 150 |
}else if ($headerdone){ |
| 151 |
// header has been read. now read the contents |
| 152 |
$res .= $line; |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
// parse the data |
| 157 |
if (preg_match("/VERIFIED/mi", $res) == 1){ |
| 158 |
$results[0] = true; |
| 159 |
$results['payment_status'] = $payment_status; |
| 160 |
$ret = true; |
| 161 |
settlement_log('IPN[SUCCESS]'); |
| 162 |
}else{ |
| 163 |
$results[0] = false; |
| 164 |
settlement_log(__('IPN Refusal', 'usces') . "\n\t\t\t" . __("PayPal gives back 'FAIL'. Please confirm setting.", 'usces')); |
| 165 |
} |
| 166 |
// $lines = explode("\n", $res); |
| 167 |
// $keyarray = array(); |
| 168 |
// if (strcmp ($lines[0], "VERIFIED") == 0) { |
| 169 |
// $results[0] = true; |
| 170 |
// $results['payment_status'] = $payment_status; |
| 171 |
// $ret = true; |
| 172 |
// settlement_log('IPN[SUCCESS]'); |
| 173 |
// }else if (strcmp ($lines[0], "FAIL") == 0) { |
| 174 |
// $results[0] = false; |
| 175 |
// settlement_log(__('IPN Refusal', 'usces') . "\n\t\t\t" . __("PayPal gives back 'FAIL'. Please confirm setting.", 'usces')); |
| 176 |
// } |
| 177 |
|
| 178 |
fclose ($fp); |
| 179 |
} |
| 180 |
return $results; |
| 181 |
} |
| 182 |
|
| 183 |
function settlement_log($log){ |
| 184 |
global $usces; |
| 185 |
if(!$usces->log_flg) return; |
| 186 |
|
| 187 |
$log = date('[Y-m-d H:i:s]', current_time('timestamp')) . "\t" . $log . "\n"; |
| 188 |
$file = $usces->options['settlement_path'].'/paypal.log'; |
| 189 |
$fp = fopen($file, 'a'); |
| 190 |
fwrite($fp, $log); |
| 191 |
fclose($fp); |
| 192 |
} |
| 193 |
?> |
| 194 |
|