PluginProbe
Welcart e-Commerce / 1.3.16
Welcart e-Commerce v1.3.16
2.12.4 2.12.3 2.11.35 2.12.2 2.12.1 2.11.34 2.11.33 2.11.32 2.11.31 2.11.30 1.3.16 1.3.17 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 All 292 releases
usc-e-shop / settlement / paypal_sample_ja.php

paypal_sample_ja.php in Welcart e-Commerce 1.3.16, at settlement/paypal_sample_ja.php

211 lines 7.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 PayPal決済モジュール
4
5 【手順1】PayPalマイアカウントの設定
6
7 マイアカウント→個人設定→ウェブペイメントの設定
8
9 ・自動復帰:オン
10 ・復帰URL:ショップトップページのURL/index.php?page_id=カートページのID&acting=paypal&acting_return=1
11  SSLを利用している場合はhttp//をhttps://にする。また�
12 �用SSLの場合はそのURLを指定。
13  カートページのIDはWelcart 管理画面のHome で確認できます。
14 ・支払いデータ転送:オン
15
16
17 マイアカウント→個人設定→即時支払い通知の設定
18
19 ・通知URL:ショップトップページのURL
20  ショップトップページのURLは上記と同じ
21 ・IPNメッセージ:有効
22  推奨は「有効」です。
23
24
25 マイアカウント→個人設定→言語のエンコード
26
27 ・言語のエンコード:日本語
28 ・エンコード方式:UTF-8(詳細オプション)
29 ・いいえ。次のエンコード方式を使用します。:UTF-8(詳細オプション)
30  
31
32
33
34 【手順2】このファイルを編集
35 ・$usces_paypal_business :登録メールアドレス
36 ・$usces_paypal_url :本稼動の場合は"www.paypal.com"。sandboxの場合は"www.sandbox.paypal.com"。
37 ・$auth_token : ウェブペイメントの設定で発行されたID トークン。
38 ・編集後はpaypal.php のファイル名で任意の場所(※)に保存
39
40 ※テストの時はepsilon_sample.php が有った場所に保存して構いません。そのまま使用できます。
41  しかし、この場所はプラグインのアップグレードの際に削除されてしまいます。
42  実際の設置場所はplugins フォルダの外にすることをお勧めします。
43  また、その際はWelcart管理画面・システム設定ページにてモジュールの設置場所を指定してください。
44
45
46 【手順3】Welcart 管理画面の基本設定ページにて新しい支払方法を追加
47 ・支払方法名:ショップに表示される支払方法名(�
48 須)
49 ・説明:ショップに表示される支払方法の説明
50 ・決済種別:「代行業�
51 決済」を選択
52 ・決済モジュール:「paypal.php」と記�
53
54 ・「新しい支払方法を追加」ボタンを押して追加を確定
55
56 */
57 global $usces;
58 $usces->log_flg = 0;//0:ログを取らない、1:ログを取る
59 /*********************************************************************************/
60 //登録メールアドレス
61 $usces_paypal_business = "*********@********.***";
62 //PayPal URL
63 $usces_paypal_url = "www.paypal.com";
64 /*********************************************************************************/
65
66 function paypal_check($usces_paypal_url) {
67 /*********************************************************************************/
68 //ID トークン
69 $auth_token = "**********************************************************";
70 /*********************************************************************************/
71 settlement_log('PDT開始');
72
73 // read the post from PayPal system and add 'cmd'
74 $req = 'cmd=_notify-synch';
75
76 $tx_token = $_GET['tx'];
77 $req .= '&tx=' . $tx_token . '&at=' . $auth_token;
78
79 // post back to PayPal system to validate
80 $header .= "POST /cgi-bin/webscr HTTP/1.1\r\n";
81 $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
82 $header .= "Host: " . $usces_paypal_url . "\r\n";
83 $header .= "Content-Length: " . strlen($req) . "\r\n";
84 $header .= "Connection: close\r\n\r\n";
85 $fp = fsockopen ('ssl://'.$usces_paypal_url, 443, $errno, $errstr, 30);
86 $results = array();
87 if (!$fp) {
88 $results[0] = false;
89 settlement_log('PDT接続エラー');
90 } else {
91 fputs ($fp, $header . $req);
92 // read the body data
93 $res = '';
94 $headerdone = false;
95 while (!feof($fp)) {
96 $line = fgets ($fp, 1024);
97 if (strcmp($line, "\r\n") == 0) {
98 // read the header
99 $headerdone = true;
100 }else if ($headerdone){
101 // header has been read. now read the contents
102 $res .= $line;
103 }
104 }
105
106 // parse the data
107 $lines = explode("\n", $res);
108 $keyarray = array();
109 if (strcmp ($lines[0], "SUCCESS") == 0) {
110 $results[0] = true;
111 for ($i=1; $i<count($lines);$i++){
112 list($key,$val) = explode("=", $lines[$i]);
113 $results[urldecode($key)] = urldecode($val);
114 }
115 $ret = true;
116 settlement_log('PDT[SUCCESS]');
117 }else if (strcmp ($lines[0], "FAIL") == 0) {
118 $results[0] = false;
119 settlement_log(__('PDT Refusal', 'usces') . "\n\t\t\t" . __("PayPal gives back 'FAIL'. Please confirm setting.", 'usces'));
120 }
121
122 fclose ($fp);
123 }
124 return $results;
125 }
126
127 function paypal_ipn_check($usces_paypal_url) {
128 settlement_log(__('IPN Start', 'usces'));
129 // read the post from PayPal system and add 'cmd'
130 $req = 'cmd=_notify-validate';
131
132 foreach ($_POST as $key => $value) {
133 $value = urlencode(stripslashes($value));
134 $req .= '&' . $key . '=' . $value;
135 }
136 // post back to PayPal system to validate
137 $header .= "POST /cgi-bin/webscr HTTP/1.1\r\n";
138 $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
139 $header .= "Host: " . $usces_paypal_url . "\r\n";
140 $header .= "Content-Length: " . strlen($req) . "\r\n";
141 $header .= "Connection: close\r\n\r\n";
142 $fp = fsockopen ('ssl://'.$usces_paypal_url, 443, $errno, $errstr, 30);
143
144 $item_name = $_POST['item_name'];
145 $item_number = $_POST['item_number'];
146 $payment_status = $_POST['payment_status'];
147 $payment_amount = $_POST['mc_gross'];
148 $payment_currency = $_POST['mc_currency'];
149 $txn_id = $_POST['txn_id'];
150 $receiver_email = $_POST['receiver_email'];
151 $payer_email = $_POST['payer_email'];
152
153 $results = array();
154 if (!$fp) {
155 $results[0] = false;
156 settlement_log(__('IPN Connection Error', 'usces'));
157 } else {
158 fputs ($fp, $header . $req);
159 // read the body data
160 $res = '';
161 $headerdone = false;
162 while (!feof($fp)) {
163 $line = fgets ($fp, 1024);
164 if (strcmp($line, "\r\n") == 0) {
165 // read the header
166 $headerdone = true;
167 }else if ($headerdone){
168 // header has been read. now read the contents
169 $res .= $line;
170 }
171 }
172
173 // parse the data
174 if (preg_match("/VERIFIED/mi", $res) == 1){
175 $results[0] = true;
176 $results['payment_status'] = $payment_status;
177 $ret = true;
178 settlement_log('IPN[SUCCESS]');
179 }else{
180 $results[0] = false;
181 settlement_log(__('IPN Refusal', 'usces') . "\n\t\t\t" . __("PayPal gives back 'FAIL'. Please confirm setting.", 'usces'));
182 }
183 // $lines = explode("\n", $res);
184 // $keyarray = array();
185 // if (strcmp ($lines[0], "VERIFIED") == 0) {
186 // $results[0] = true;
187 // $results['payment_status'] = $payment_status;
188 // $ret = true;
189 // settlement_log('IPN[SUCCESS]');
190 // }else if (strcmp ($lines[0], "FAIL") == 0) {
191 // $results[0] = false;
192 // settlement_log(__('IPN Refusal', 'usces') . "\n\t\t\t" . __("PayPal gives back 'FAIL'. Please confirm setting.", 'usces'));
193 // }
194
195 fclose ($fp);
196 }
197 return $results;
198 }
199
200 function settlement_log($log){
201 global $usces;
202 if(!$usces->log_flg) return;
203
204 $log = date('[Y-m-d H:i:s]', current_time('timestamp')) . "\t" . $log . "\n";
205 $file = $usces->options['settlement_path'].'/paypal.log';
206 $fp = fopen($file, 'a');
207 fwrite($fp, $log);
208 fclose($fp);
209 }
210 ?>
211