source: branches/beta/data/downloads/module/mdl_paygent/mdl_paygent.inc @ 17012

Revision 17012, 31.7 KB checked in by satou, 15 years ago (diff)

[ペイジェント決済モジュール]3Dセキュア対応

Line 
1<?php
2/**
3 *
4 * @copyright   2000-2006 LOCKON CO.,LTD. All Rights Reserved.
5 * @version CVS: $Id: mdl_epsilon.inc 7162 2006-11-18 09:53:33Z kakinaka $
6 * @link        http://www.lockon.co.jp/
7 *
8 */
9$paygent_credit_php_dir = realpath(dirname( __FILE__));
10// include_path¤Ëmdl_paygent¤Î¥Ñ¥¹¤ò´Þ¤á¤ë
11ini_set('include_path', $paygent_credit_php_dir . PATH_SEPARATOR . ini_get('include_path'));
12
13$paygent_module_dir = "jp/co/ks/merchanttool/connectmodule/";
14
15// ¥â¥¸¥å¡¼¥ë¥Õ¥¡¥¤¥ë¤Î¸ºß¥Á¥§¥Ã¥¯
16if(!file_exists($paygent_credit_php_dir . "/" . $paygent_module_dir)) {
17    sfErrorHeader(">> ¥Ú¥¤¥¸¥§¥ó¥ÈÄ󶡥⥸¥å¡¼¥ë¤òÀßÃÖ¤·¤Æ¤¯¤À¤µ¤¤¡£");
18} else {
19    // paygent¥â¥¸¥å¡¼¥ë¤ÎÆɹþ
20    include_once($paygent_module_dir . "entity/ResponseDataFactory.php");
21    include_once($paygent_module_dir . "system/PaygentB2BModule.php");
22    include_once($paygent_module_dir . "exception/PaygentB2BModuleConnectException.php");
23    include_once($paygent_module_dir . "exception/PaygentB2BModuleException.php");
24}
25
26// ¥Ú¥¤¥¸¥§¥ó¥È·èºÑ¤Î¥â¥¸¥å¡¼¥ëID¡Êdtb_module¤È¹ç¤ï¤»¤ë¡Ë
27define("MDL_PAYGENT_ID", 9);
28
29// ¥Ú¥¤¥¸¥§¥ó¥È¤Î³Æʧ¹þ¤ÎÂбþÈÖ¹æ
30/*
31    ÅÅʸ¼ïÊ̤òɽ¤¹¶èʬ
32    010¡§ATM·èºÑ¿½¹þ
33    020¡§Ž¶Ž°ŽÄŽÞ·èºÑŽµŽ°Ž¿ŽØ
34    021¡§Ž¶Ž°ŽÄŽÞ·èºÑŽµŽ°Ž¿ŽØŽ·Ž¬ŽÝŽ¾ŽÙ
35    022¡§Ž¶Ž°ŽÄŽÞ·èºÑÇä¾å
36    023¡§Ž¶Ž°ŽÄŽÞ·èºÑÇä¾åŽ·Ž¬ŽÝŽ¾ŽÙ
37    024¡§Ž¶Ž°ŽÄŽÞ·èºÑ3DŽµŽ°Ž¿ŽØ
38    030¡§ŽºŽÝŽËŽÞŽÆ·èºÑ(ÈÖ¹æÊý¼°)¿½¹þ
39    040¡§ŽºŽÝŽËŽÞŽÆ·èºÑ(ʧ¹þɼÊý¼°)¿½¹þ
40    050¡§¶ä¹ÔŽÈŽ¯ŽÄ·èºÑ¿½¹þ
41    060¡§¶ä¹Ô¥Í¥Ã¥È·èºÑASP
42    090¡§·èºÑ¾ðÊó¾È²ñ
43    091¡§º¹Ê¬¾È²ñ
44*/
45define("PAYGENT_ATM", '010');
46define("PAYGENT_CREDIT", '020');
47define("PAYGENT_AUTH_CANCEL", '021');
48define("PAYGENT_CARD_COMMIT", '022');
49define("PAYGENT_CARD_COMMIT_CANCEL", '023');
50define("PAYGENT_CARD_3D", '024');
51define("PAYGENT_CONVENI", '030');
52define("PAYGENT_BANK", '060');
53// ¥Ð¥Ã¥Á¤Ç»ÈÍѤ¹¤ë¡£
54define("PAYGENT_REF", '091');
55
56// ̵¸Â¥ë¡¼¥×¤òÈò¤±¤ë
57define("PAYGENT_REF_LOOP", 1000);
58
59$arrDispKind = array(
60    PAYGENT_AUTH_CANCEL => '¥ª¡¼¥½¥ê¥­¥ã¥ó¥»¥ë',
61    PAYGENT_CARD_COMMIT => 'Çä¾å',
62    PAYGENT_CARD_COMMIT_CANCEL => 'Çä¾å¥­¥ã¥ó¥»¥ë'
63);
64
65// ¼õÃí»þ¤Î½é´ü¥¹¥Æ¡¼¥¿¥¹
66$arrInitStatus = array(
67    PAYGENT_CREDIT => ORDER_NEW,        // ¥¯¥ì¥¸¥Ã¥È¤Ï¿·µ¬¼õÉÕ
68    PAYGENT_ATM => ORDER_PAY_WAIT,      // ATM·èºÑ¤ÏÆþ¶âÂÔ¤Á
69    PAYGENT_CONVENI => ORDER_PAY_WAIT,  // ¥³¥ó¥Ó¥Ë¤ÏÆþ¶âÂÔ¤Á
70    PAYGENT_BANK => ORDER_PAY_WAIT      // ¶ä¹Ô¤ÏÆþ¶âÂÔ¤Á
71);
72
73define ("CHARGE_MAX", 500000);
74define ("SEVEN_CHARGE_MAX", 300000);
75
76// ÅÅʸ¥Ð¡¼¥¸¥ç¥ó
77define ("TELEGRAM_VERSION", '1.0');
78
79// ¥³¥ó¥Ó¥Ë¥³¡¼¥É
80define ("CODE_SEVENELEVEN", "00C001");  // ¥»¥Ö¥ó¥¤¥ì¥Ö¥ó
81define ("CODE_LOWSON", "00C002");       // ¥í¡¼¥½¥ó
82define ("CODE_MINISTOP", "00C004");     // ¥ß¥Ë¥¹¥È¥Ã¥×
83define ("CODE_FAMILYMART", "00C005");   // ¥Õ¥¡¥ß¥ê¡¼¥Þ¡¼¥È
84define ("CODE_SUNKUS", "00C006");       // ¥µ¥ó¥¯¥¹
85define ("CODE_CIRCLEK", "00C007");      // ¥µ¡¼¥¯¥ëK
86define ("CODE_YAMAZAKI", "00C014");     // ¥Ç¥¤¥ê¡¼¥ä¥Þ¥¶¥­
87define ("CODE_SEICOMART", "00C016");    // ¥»¥¤¥³¡¼¥Þ¡¼¥È
88
89//¥³¥ó¥Ó¥Ë¤Î¼ïÎà
90$arrConvenience = array(
91    CODE_SEICOMART => '¥»¥¤¥³¡¼¥Þ¡¼¥È',
92    CODE_LOWSON => '¥í¡¼¥½¥ó',
93    CODE_MINISTOP => '¥ß¥Ë¥¹¥È¥Ã¥×',
94    CODE_FAMILYMART => '¥Õ¥¡¥ß¥ê¡¼¥Þ¡¼¥È',
95    CODE_SUNKUS => '¥µ¥ó¥¯¥¹',
96    CODE_CIRCLEK => '¥µ¡¼¥¯¥ëK',
97    CODE_YAMAZAKI => '¥Ç¥¤¥ê¡¼¥ä¥Þ¥¶¥­',
98    CODE_SEVENELEVEN => '¥»¥Ö¥ó¥¤¥ì¥Ö¥ó'
99);
100   
101// ¥Í¥Ã¥È¥Ð¥ó¥¯¤Î¼ïÎà
102$arrNetBank = array(
103    'D005' => 'e-payment',
104    'D008' => '¥Í¥Ã¥È¿¶¹þEDI',
105    'D009' => 'One\'s ¥À¥¤¥ì¥¯¥È',
106    'D033' => '¥¸¥ã¥Ñ¥ó¥Í¥Ã¥È¶ä¹Ô',
107    'D036' => '¥¤¡¼¥Ð¥ó¥¯' 
108);
109   
110// ¥¯¥ì¥¸¥Ã¥Èʬ³ä²ó¿ô
111$arrPaymentClass = array(
112    '10' => '°ì³çʧ¤¤',
113    '61-2' => 'ʬ³ä2²óʧ¤¤',
114    '61-3' => 'ʬ³ä3²óʧ¤¤',
115    '61-6' => 'ʬ³ä6²óʧ¤¤',
116    '61-10' => 'ʬ³ä10²óʧ¤¤',
117    '61-15' => 'ʬ³ä15²óʧ¤¤',
118    '61-20' => 'ʬ³ä20²óʧ¤¤',
119    '80' => '¥ê¥Üʧ¤¤'
120);
121
122// ʸ»úÆþÎÏÀ©¸Â¡Êbyte¡Ë
123define ("PAYGENT_BANK_STEXT_LEN", "12");    // ATM¡¤¶ä¹Ô¥Í¥Ã¥È¤ÎÍøÍѼÔ̾¡Ê´Á»ú¡¤¥«¥Ê¡Ë
124define ("PAYGENT_CONVENI_STEXT_LEN", "14"); // ¥³¥ó¥Ó¥Ë¤ÎÍøÍѼÔ̾¡Ê¥«¥Ê¡Ë
125define ("PAYGENT_CONVENI_MTEXT_LEN", "20"); // ¥³¥ó¥Ó¥Ë¤ÎÍøÍѼÔ̾¡Ê´Á»ú¡Ë
126
127//====================================================================================
128
129/**************************************************************************************************************
130 * ´Ø¿ô̾   ¡§sfGetPaygentShare
131 * ½èÍýÆâÍÆ ¡§¥Ú¥¤¥¸¥§¥ó¥È¾ðÊóÁ÷¿®¤Î¶¦Ä̽èÍý
132 * °ú¿ô1    ¡§
133 * °ú¿ô2    ¡§
134 * °ú¿ô3    ¡§
135 * Ìá¤êÃÍ   ¡§¼èÆÀ·ë²Ì
136 **************************************************************************************************************/
137function sfGetPaygentShare($telegram_kind, $order_id, $arrParam, $payment_id = "") {
138   
139    /** ¶¦ÄÌÅÅʸ **/   
140    // ¥Þ¡¼¥Á¥ã¥ó¥ÈID
141    $arrSend['merchant_id'] = $arrParam['merchant_id'];
142    // ÀܳID
143    $arrSend['connect_id'] = $arrParam['connect_id'];
144    // Àܳ¥Ñ¥¹¥ï¡¼¥É
145    $arrSend['connect_password'] = $arrParam['connect_password'];
146    // ÅÅʸ¼ïÊÌID
147    $arrSend['telegram_kind'] = $telegram_kind;
148    // ÅÅʸ¥Ð¡¼¥¸¥ç¥ó
149    $arrSend['telegram_version'] = TELEGRAM_VERSION;
150    // ¥Þ¡¼¥Á¥ã¥ó¥È¼è°úID
151    $arrSend['trading_id'] = $order_id;
152    // ·èºÑID
153    if (strlen($payment_id) > 0) $arrSend['payment_id'] = $payment_id;
154    // EC-CUBE¤«¤é¤ÎÅÅʸ¤Ç¤¢¤ë¤³¤È¤ò¼¨¤¹¡£
155    $arrSend['partner'] = 'lockon';
156   
157    return $arrSend;
158}
159
160/**************************************************************************************************************
161 * ´Ø¿ô̾   ¡§sfSendPaygentCredit
162 * ½èÍýÆâÍÆ ¡§¥¯¥ì¥¸¥Ã¥È¾ðÊó¤ÎÁ÷¿®
163 * °ú¿ô1    ¡§
164 * °ú¿ô2    ¡§
165 * °ú¿ô3    ¡§
166 * Ìá¤êÃÍ   ¡§¼èÆÀ·ë²Ì
167 **************************************************************************************************************/
168function sfSendPaygentCredit($arrData, $arrInput, $uniqid) {
169    // Àܳ¥â¥¸¥å¡¼¥ë¤Î¥¤¥ó¥¹¥¿¥ó¥¹¼èÆÀ (¥³¥ó¥¹¥È¥é¥¯¥¿)¤È½é´ü²½
170    $p = new PaygentB2BModule();
171    $p->init();
172   
173    // ¥¯¥ì¥¸¥Ã¥ÈÍѥѥé¥á¡¼¥¿¤Î¼èÆÀ
174    $arrPaymentDB = sfGetPaymentDB(MDL_PAYGENT_ID, "AND memo03 = 1");
175    $arrOtherParam = unserialize($arrPaymentDB[0]['other_param']);
176   
177    // ¶¦Ḁ̈ǡ¼¥¿¤Î¼èÆÀ
178    $arrSend = sfGetPaygentShare(PAYGENT_CREDIT, $arrData['order_id'], $arrPaymentDB[0]);
179   
180    /** ¸ÄÊÌÅÅʸ **/
181    // ·èºÑ¶â³Û
182    $arrSend['payment_amount'] = $arrData['payment_total'];
183    // ¥«¡¼¥ÉÈÖ¹æ
184    $arrSend['card_number'] = $arrInput['card_no01'].$arrInput['card_no02'].$arrInput['card_no03'].$arrInput['card_no04'];
185    // ¥«¡¼¥ÉÍ­¸ú´ü¸Â(MMYY)
186    $arrSend['card_valid_term'] = $arrInput['card_month'].$arrInput['card_year'];
187    // »Ùʧ¤¤¶èʬ¡¢Ê¬³ä²ó¿ô¤Î¼èÆÀ
188    list($payment_class, $split_count) = split("-", $arrInput['payment_class']);
189    // »Ùʧ¤¤¶èʬ
190    /*
191     * 10:1²ó
192     * 23:¥Ü¡¼¥Ê¥¹1²ó
193     * 61:ʬ³ä
194     * 80:¥ê¥Ü¥ë¥Ó¥ó¥°
195     */
196    $arrSend['payment_class'] = $payment_class;
197    // ʬ³ä²ó¿ô
198    $arrSend['split_count'] = $split_count;
199    /** 3D¥»¥­¥å¥¢´ØÏ¢ **/
200    if ($arrOtherParam['credit_3d'] != 1 || GC_MobileUserAgent::isMobile()) {
201        // 3D¥»¥­¥å¥¢ÉÔÍ׶èʬ
202        $arrSend['3dsecure_ryaku'] = '1';
203    } else {
204        // HttpAccept
205        $arrSend['http_accept'] = $_SERVER['HTTP_ACCEPT'];
206        // HttpUserAgent
207        $arrSend['http_user_agent'] = $_SERVER['HTTP_USER_AGENT'];
208        // 3D¥»¥­¥å¥¢Ìá¤êURL
209        $arrSend['term_url'] = SSL_URL. "shopping/load_payment_module.php?mode=credit_3d&uniqid=". $uniqid;
210    }
211   
212    // ÅÅʸ¤ÎÁ÷ÉÕ
213    foreach($arrSend as $key => $val) {
214        $p->reqPut($key, $val);
215    }
216    // ÅÅʸ¤ÎÁ÷¿®
217    $p->post();
218    // ±þÅú¤ò½èÍý
219    $arrRet = sfPaygentResponse(PAYGENT_CREDIT, $p, $uniqid, $arrInput);
220   
221    return $arrRet;
222}
223
224/**************************************************************************************************************
225 * ´Ø¿ô̾   ¡§sfSendPaygentCredit3d
226 * ½èÍýÆâÍÆ ¡§3D¥»¥­¥å¥¢¾ðÊó¤ÎÁ÷¿®
227 * °ú¿ô1    ¡§
228 * °ú¿ô2    ¡§
229 * °ú¿ô3    ¡§
230 * Ìá¤êÃÍ   ¡§¼èÆÀ·ë²Ì
231 **************************************************************************************************************/
232function sfSendPaygetnCredit3d($arrData, $arrInput, $uniqid) {
233    // Àܳ¥â¥¸¥å¡¼¥ë¤Î¥¤¥ó¥¹¥¿¥ó¥¹¼èÆÀ (¥³¥ó¥¹¥È¥é¥¯¥¿)¤È½é´ü²½
234    $p = new PaygentB2BModule();
235    $p->init();
236   
237    // ¥¯¥ì¥¸¥Ã¥ÈÍѥѥé¥á¡¼¥¿¤Î¼èÆÀ
238    $arrPaymentDB = sfGetPaymentDB(MDL_PAYGENT_ID, "AND memo03 = 1");
239    $arrOtherParam = unserialize($arrPaymentDB[0]['other_param']);
240   
241    // ¶¦Ḁ̈ǡ¼¥¿¤Î¼èÆÀ
242    $arrSend = sfGetPaygentShare(PAYGENT_CARD_3D, $arrData['order_id'], $arrPaymentDB[0], $arrData['memo06']);
243   
244    /** ¸ÄÊÌÅÅʸ **/
245    // ACS±þÅú
246    $arrSend['PaRes'] = $arrInput['PaRes'];
247    // ¥Þ¡¼¥Á¥ã¥ó¥È¥Ç¡¼¥¿
248    $arrSend['MD'] = $arrInput['MD'];
249   
250    // ÅÅʸ¤ÎÁ÷ÉÕ
251    foreach($arrSend as $key => $val) {
252        $p->reqPut($key, $val);
253    }
254    // ÅÅʸ¤ÎÁ÷¿®
255    $p->post();
256    // ±þÅú¤ò½èÍý
257    $arrRet = sfPaygentResponse(PAYGENT_CREDIT, $p, $uniqid, $arrInput);
258   
259    return $arrRet;
260}
261
262/**************************************************************************************************************
263 * ´Ø¿ô̾   ¡§sfSendPaygentConveni
264 * ½èÍýÆâÍÆ ¡§¥³¥ó¥Ó¥Ë¾ðÊó¤ÎÁ÷¿®
265 * °ú¿ô1    ¡§
266 * °ú¿ô2    ¡§
267 * °ú¿ô3    ¡§
268 * Ìá¤êÃÍ   ¡§¼èÆÀ·ë²Ì
269 **************************************************************************************************************/
270function sfSendPaygentConveni($arrData, $arrInput, $uniqid) {
271// Àܳ¥â¥¸¥å¡¼¥ë¤Î¥¤¥ó¥¹¥¿¥ó¥¹¼èÆÀ (¥³¥ó¥¹¥È¥é¥¯¥¿)¤È½é´ü²½
272    $p = new PaygentB2BModule();
273    $p->init();
274   
275    // ¥³¥ó¥Ó¥ËÍѥѥé¥á¡¼¥¿¤Î¼èÆÀ
276    $arrPaymentDB = sfGetPaymentDB(MDL_PAYGENT_ID, "AND memo03 = 2");
277    $arrOtherParam = unserialize($arrPaymentDB[0]['other_param']);
278   
279    // ¶¦Ḁ̈ǡ¼¥¿¤Î¼èÆÀ
280    $arrSend = sfGetPaygentShare(PAYGENT_CONVENI, $arrData['order_id'], $arrPaymentDB[0]);
281   
282    /** ¸ÄÊÌÅÅʸ **/
283    // ·èºÑ¶â³Û
284    $arrSend['payment_amount'] = $arrData['payment_total'];
285    // ÍøÍѼÔÀ«
286    $arrSend['customer_family_name'] = $arrInput['customer_family_name'];
287    // ÍøÍѼÔ̾
288    $arrSend['customer_name'] = $arrInput['customer_name'];
289    // ÍøÍѼÔÀ«È¾³Ñ¥«¥Ê
290    $arrSend['customer_family_name_kana'] = mb_convert_kana($arrInput['customer_family_name_kana'],'k');
291    $arrSend['customer_family_name_kana'] = preg_replace("/ŽÞ|Žß/", "", $arrSend['customer_family_name_kana']);
292    // ÍøÍѼÔ̾Ⱦ³Ñ¥«¥Ê
293    $arrSend['customer_name_kana'] = mb_convert_kana($arrInput['customer_name_kana'],'k');
294    $arrSend['customer_name_kana'] = preg_replace("/ŽÞ|Žß/", "", $arrSend['customer_name_kana']);
295    // ÍøÍѼÔÅÅÏÃÈÖ¹æ
296    $arrSend['customer_tel'] = $arrInput['customer_tel'];
297    // »Ùʧ´ü¸ÂÆü
298    $arrSend['payment_limit_date'] = $arrOtherParam['payment_limit_date'];
299    // ¥³¥ó¥Ó¥Ë´ë¶È¥³¡¼¥É
300    $arrSend['cvs_company_id'] = $arrInput['cvs_company_id'];
301    // »Ùʧ¼ïÊÌ
302    $arrSend['sales_type'] = '1';
303   
304    // ÅÅʸ¤ÎÁ÷ÉÕ
305    foreach($arrSend as $key => $val) {
306        // Shift-JIS¤Ë¥¨¥ó¥³¡¼¥É¤¹¤ëɬÍפ¢¤ê
307        $enc_val = mb_convert_encoding($val, "Shift-JIS", CHAR_CODE);
308        $p->reqPut($key, $enc_val);
309    }
310    // ÅÅʸ¤ÎÁ÷¿®
311    $p->post();
312    // ±þÅú¤ò½èÍý
313    $arrRet = sfPaygentResponse(PAYGENT_CONVENI, $p, $uniqid, $arrInput);
314       
315    return $arrRet;
316}
317
318/**************************************************************************************************************
319 * ´Ø¿ô̾   ¡§sfSendPaygentATM
320 * ½èÍýÆâÍÆ ¡§ATM·èºÑ¾ðÊó¤ÎÁ÷¿®
321 * °ú¿ô1    ¡§
322 * °ú¿ô2    ¡§
323 * °ú¿ô3    ¡§
324 * Ìá¤êÃÍ   ¡§¼èÆÀ·ë²Ì
325 **************************************************************************************************************/
326function sfSendPaygentATM($arrData, $arrInput, $uniqid) {
327// Àܳ¥â¥¸¥å¡¼¥ë¤Î¥¤¥ó¥¹¥¿¥ó¥¹¼èÆÀ (¥³¥ó¥¹¥È¥é¥¯¥¿)¤È½é´ü²½
328    $p = new PaygentB2BModule();
329    $p->init();
330   
331    // ATM·èºÑÍѥѥé¥á¡¼¥¿¤Î¼èÆÀ
332    $arrPaymentDB = sfGetPaymentDB(MDL_PAYGENT_ID, "AND memo03 = 3");
333    $arrOtherParam = unserialize($arrPaymentDB[0]['other_param']);
334   
335    // ¶¦Ḁ̈ǡ¼¥¿¤Î¼èÆÀ
336    $arrSend = sfGetPaygentShare(PAYGENT_ATM, $arrData['order_id'], $arrPaymentDB[0]);
337   
338    /** ¸ÄÊÌÅÅʸ **/
339    // ·èºÑ¶â³Û
340    $arrSend['payment_amount'] = $arrData['payment_total'];
341    // ÍøÍѼÔÀ«
342    $arrSend['customer_family_name'] = $arrInput['customer_family_name'];
343    // ÍøÍѼÔ̾
344    $arrSend['customer_name'] = $arrInput['customer_name'];
345    // ÍøÍѼÔÀ«È¾³Ñ¥«¥Ê
346    $arrSend['customer_family_name_kana'] = mb_convert_kana($arrInput['customer_family_name_kana'],'k');
347    $arrSend['customer_family_name_kana'] = preg_replace("/Ž°/", "-", $arrSend['customer_family_name_kana']);
348    $arrSend['customer_family_name_kana'] = preg_replace("/ŽÞ|Žß/", "", $arrSend['customer_family_name_kana']);
349    // ÍøÍѼÔ̾Ⱦ³Ñ¥«¥Ê
350    $arrSend['customer_name_kana'] = mb_convert_kana($arrInput['customer_name_kana'],'k');
351    $arrSend['customer_name_kana'] = preg_replace("/Ž°/", "-", $arrSend['customer_name_kana']);
352    $arrSend['customer_name_kana'] = preg_replace("/ŽÞ|Žß/", "", $arrSend['customer_name_kana']);
353    // ·èºÑÆâÍÆ
354    $arrSend['payment_detail'] = $arrOtherParam['payment_detail'];
355    // ·èºÑÆâÍÆȾ³Ñ¥«¥Ê
356    $arrSend['payment_detail_kana'] = mb_convert_kana($arrOtherParam['payment_detail'],'k');
357    $arrSend['payment_detail_kana'] = preg_replace("/Ž°/", "-", $arrSend['payment_detail_kana']);
358    // »Ùʧ´ü¸ÂÆü
359    $arrSend['payment_limit_date'] = $arrOtherParam['payment_limit_date'];
360   
361    // ÅÅʸ¤ÎÁ÷ÉÕ
362    foreach($arrSend as $key => $val) {
363        // Shift-JIS¤Ë¥¨¥ó¥³¡¼¥É¤¹¤ëɬÍפ¢¤ê
364        $enc_val = mb_convert_encoding($val, "Shift-JIS", CHAR_CODE);       
365        $p->reqPut($key, $enc_val);
366    }
367    // ÅÅʸ¤ÎÁ÷¿®
368    $p->post();
369    // ±þÅú¤ò½èÍý
370    $arrRet = sfPaygentResponse(PAYGENT_ATM, $p, $uniqid, $arrInput);
371   
372    return $arrRet;
373}
374
375/**************************************************************************************************************
376 * ´Ø¿ô̾   ¡§sfSendPaygentBANK
377 * ½èÍýÆâÍÆ ¡§¶ä¹ÔNET·èºÑ¾ðÊó¤ÎÁ÷¿®
378 * °ú¿ô1    ¡§
379 * °ú¿ô2    ¡§
380 * °ú¿ô3    ¡§
381 * Ìá¤êÃÍ   ¡§¼èÆÀ·ë²Ì
382 **************************************************************************************************************/
383function sfSendPaygentBANK($arrData, $arrInput, $uniqid) {
384// Àܳ¥â¥¸¥å¡¼¥ë¤Î¥¤¥ó¥¹¥¿¥ó¥¹¼èÆÀ (¥³¥ó¥¹¥È¥é¥¯¥¿)¤È½é´ü²½
385    $p = new PaygentB2BModule();
386    $p->init();
387   
388    // ¶ä¹ÔNETÍѥѥé¥á¡¼¥¿¤Î¼èÆÀ
389    $arrPaymentDB = sfGetPaymentDB(MDL_PAYGENT_ID, "AND memo03 = 4");
390    $arrOtherParam = unserialize($arrPaymentDB[0]['other_param']);
391   
392    // ¶¦Ḁ̈ǡ¼¥¿¤Î¼èÆÀ
393    $arrSend = sfGetPaygentShare(PAYGENT_BANK, $arrData['order_id'], $arrPaymentDB[0]);
394   
395    /** ¸ÄÊÌÅÅʸ **/
396    //$arrSend['bank_code'] = $arrInput['bank_code'];   
397    // ·èºÑ¶â³Û
398    $arrSend['amount'] = $arrData['payment_total'];
399    // ÀÁµáÆâÍÆ¥«¥Ê
400    $arrSend['claim_kana'] = mb_convert_kana($arrOtherParam['claim_kana'],'k');
401    $arrSend['claim_kana'] = preg_replace("/Ž°/", "-", $arrSend['claim_kana']);
402    // ÀÁµáÆâÍÆ´Á»ú
403    $arrSend['claim_kanji'] = $arrOtherParam['claim_kanji'];   
404    // ÍøÍѼÔÀ«
405    $arrSend['customer_family_name'] = $arrInput['customer_family_name'];
406    // ÍøÍѼÔ̾
407    $arrSend['customer_name'] = $arrInput['customer_name'];
408    // ÍøÍѼÔÀ«È¾³Ñ¥«¥Ê
409    $arrSend['customer_family_name_kana'] = mb_convert_kana($arrInput['customer_family_name_kana'],'k');
410    $arrSend['customer_family_name_kana'] = preg_replace("/Ž°/", "-", $arrSend['customer_family_name_kana']);
411    $arrSend['customer_family_name_kana'] = preg_replace("/ŽÞ|Žß/", "", $arrSend['customer_family_name_kana']);
412    // ÍøÍѼÔ̾Ⱦ³Ñ¥«¥Ê
413    $arrSend['customer_name_kana'] = mb_convert_kana($arrInput['customer_name_kana'],'k');
414    $arrSend['customer_name_kana'] = preg_replace("/Ž°/", "-", $arrSend['customer_name_kana']);
415    $arrSend['customer_name_kana'] = preg_replace("/ŽÞ|Žß/", "", $arrSend['customer_name_kana']);
416    // PC-Mobile¶èʬ
417    /*
418     * 0:PC
419     * 1:docomo
420     * 2:au
421     * 3:softbank
422     */
423    $arrSend['pc_mobile_type'] = '0';
424    // ŹÊÞ̾
425    $arrSend['merchant_name'] = $arrOtherParam['claim_kanji'];
426    // ´°Î»¸å¤ÎÌá¤ê£Õ£Ò£Ì
427    $arrSend['return_url'] = SITE_URL. "index.php";
428    // Ìá¤ê¥Ü¥¿¥ó£Õ£Ò£Ì
429    $arrSend['stop_return_url'] = SSL_URL. "shopping/load_payment_module.php";
430    // ¥³¥Ô¡¼¥é¥¤¥È
431    $arrSend['copy_right'] = $arrOtherParam['copy_right'];
432    // ¼«Í³¥á¥âÍó
433    $arrSend['free_memo'] = $arrOtherParam['free_memo'];
434    // »Ùʧ´ü´Ö(0DDhhmm)
435    $arrSend['asp_payment_term'] = sprintf("0%02d0000", $arrOtherParam['asp_payment_term']);
436   
437    // ÅÅʸ¤ÎÁ÷ÉÕ
438    foreach($arrSend as $key => $val) {
439        // Shift-JIS¤Ë¥¨¥ó¥³¡¼¥É¤¹¤ëɬÍפ¢¤ê
440        $enc_val = mb_convert_encoding($val, "Shift-JIS", CHAR_CODE);
441        $p->reqPut($key, $enc_val);
442    }
443    // ÅÅʸ¤ÎÁ÷¿®
444    $p->post();
445    // ±þÅú¤ò½èÍý
446    $arrRet = sfPaygentResponse(PAYGENT_BANK, $p, $uniqid, $arrInput);
447   
448    return $arrRet;
449}
450
451/**************************************************************************************************************
452 * ´Ø¿ô̾   ¡§sfPaygentResponse
453 * ½èÍýÆâÍÆ ¡§±þÅú¤ò½èÍý¤¹¤ë
454 * °ú¿ô1    ¡§
455 * °ú¿ô2    ¡§
456 * °ú¿ô3    ¡§
457 * Ìá¤êÃÍ   ¡§¼èÆÀ·ë²Ì
458 **************************************************************************************************************/
459function sfPaygentResponse($telegram_kind, $objPaygent, $uniqid, $arrInput) {
460    global $arrConvenience;
461    global $arrInitStatus;
462   
463    // ½èÍý·ë²Ì¼èÆÀ¡Ê¶¦ÄÌ¡Ë
464    $resultStatus = $objPaygent->getResultStatus(); # ½èÍý·ë²Ì 0=Àµ¾ï½ªÎ», 1=°Û¾ï½ªÎ»
465    $responseCode = $objPaygent->getResponseCode(); # °Û¾ï½ªÎ»»þ¡¢¥ì¥¹¥Ý¥ó¥¹¥³¡¼¥É¤¬¼èÆÀ¤Ç¤­¤ë
466    $responseDetail = $objPaygent->getResponseDetail(); # °Û¾ï½ªÎ»»þ¡¢¥ì¥¹¥Ý¥ó¥¹¾ÜºÙ¤¬¼èÆÀ¤Ç¤­¤ë
467
468    // Shift-JIS¤Ç±þÅú¤¬¤¢¤ë¤Î¤Ç¡¢¥¨¥ó¥³¡¼¥É¤¹¤ë¡£
469    $responseDetail = mb_convert_encoding($responseDetail, CHAR_CODE, "Shift-JIS");
470   
471    $arrResOther['result'] = $resultStatus;
472    $arrResOther['code'] = $responseCode;
473    $arrResOther['detail'] = $responseDetail;
474   
475    // ¼èÆÀ¤·¤¿Ãͤò¥í¥°¤ËÊݸ¤¹¤ë¡£
476    foreach($arrResOther as $key => $val) {
477        gfPrintLog($key."->".$val);
478    }
479       
480    // ¥ì¥¹¥Ý¥ó¥¹¤Î¼èÆÀ
481    while($objPaygent->hasResNext()) {
482        # ¥Ç¡¼¥¿¤¬Â¸ºß¤¹¤ë¸Â¤ê¡¢¼èÆÀ
483        $arrRes[] = $objPaygent->resNext(); # Í×µá·ë²Ì¼èÆÀ
484    }
485   
486    $arrRes[0]['result'] = $resultStatus;
487   
488    // ¼èÆÀ¤·¤¿Ãͤò¥í¥°¤ËÊݸ¤¹¤ë¡£
489    foreach($arrRes[0] as $key => $val) {
490        gfPrintLog($key."->".$val);
491    }
492   
493    // ·èºÑËè¤Ë°Û¤Ê¤ë½èÍý
494    switch($telegram_kind) {
495    // ¥¯¥ì¥¸¥Ã¥È·èºÑ¤Î¾ì¹ç
496    case PAYGENT_CREDIT:
497        // ½é´ü¥¹¥Æ¡¼¥¿¥¹¤òÀßÄꤹ¤ë¡£
498        $arrVal["status"] = $arrInitStatus[PAYGENT_CREDIT];
499        // ¶õ¤ÎÇÛÎó¤ò³ÊǼ¤·¤Æ¤ª¤¯
500        $arrVal["memo02"] = serialize(array());     
501        break;
502    // ¥³¥ó¥Ó¥Ë·èºÑ¤Î¾ì¹ç
503    case PAYGENT_CONVENI:
504        // ¥¿¥¤¥È¥ë¤òÀßÄꤹ¤ë
505        $arrMemo['title'] = sfSetConvMSG("¥³¥ó¥Ó¥Ë¤ª»Ùʧ", true);
506        // ·èºÑ¥Ù¥ó¥À¼õÉÕÈÖ¹æ¡Ê¥³¥ó¥Ó¥Ë¤Ë¤è¤Ã¤Æ̾¾Î¤¬°Û¤Ê¤ë¡Ë
507        switch ($arrInput['cvs_company_id']) {
508        // ¥»¥Ö¥ó¥¤¥ì¥Ö¥ó
509        case CODE_SEVENELEVEN:
510            $receipt_num_name = "ʧ¹þɼÈÖ¹æ";
511            break;
512        // ¥í¡¼¥½¥ó¡¤¥Õ¥¡¥ß¥ê¡¼¥Þ¡¼¥È
513        case CODE_LOWSON:
514        case CODE_FAMILYMART:
515            $receipt_num_name = "¤ªµÒÍÍÈÖ¹æ";
516            break;
517        // ¥ß¥Ë¥¹¥È¥Ã¥×¡¤¥µ¥ó¥¯¥¹¡¤¥µ¡¼¥¯¥ëK¡¤¥Ç¥¤¥ê¡¼¥ä¥Þ¥¶¥­
518        case CODE_MINISTOP:
519        case CODE_SUNKUS:
520        case CODE_CIRCLEK:
521        case CODE_YAMAZAKI:
522            $receipt_num_name = "¥±¡¼¥¿¥¤¡¿¥ª¥ó¥é¥¤¥ó·èºÑÈÖ¹æ";
523            break;
524        // ¥»¥¤¥³¡¼¥Þ¡¼¥È
525        case CODE_SEICOMART:
526            $receipt_num_name = "¤ªµÒÍͤμõÉÕÈÖ¹æ";
527            break;
528        default:
529            break;
530        }
531        $arrMemo['receipt_number'] = sfSetConvMSG($receipt_num_name, $arrRes[0]['receipt_number']);
532        // ʧ¹þɼURL(PC) ¡§ ¥»¥Ö¥ó¥¤¥ì¥Ö¥ó¤Î¾ì¹ç¤Î¤ßʧ¹þɼURL¤¬Í­¸ú¤Ê¤Î¤Çɽ¼¨¤¹¤ë¡£
533        if($arrRes[0]['receipt_print_url'] != "" && $arrInput['cvs_company_id'] == CODE_SEVENELEVEN) {
534            $arrMemo['receipt_print_url'] = sfSetConvMSG("ʧ¹þɼURL", $arrRes[0]['receipt_print_url']);
535        }
536        // ³ÎǧÈÖ¹æ ¡§ ¥í¡¼¥½¥ó¡¤¥Õ¥¡¥ß¥ê¡¼¥Þ¡¼¥È¤Î¤ß³ÎǧÈֹ椬ɬÍפʤΤÇɽ¼¨¤¹¤ë¡£
537        if ($arrInput['cvs_company_id'] == CODE_LOWSON || $arrInput['cvs_company_id'] == CODE_FAMILYMART) {
538            $arrMemo['confirm_number'] = sfSetConvMSG("³ÎǧÈÖ¹æ", "400008");
539        }
540        // Âоݥ³¥ó¥Ó¥Ë
541        $arrCVS = split("-", $arrRes[0]['usable_cvs_company_id']);
542        foreach($arrCVS as $val) {
543            if($cvsLine != "") {
544                $cvsLine.= ",".$arrConvenience[$val];
545            } else {
546                $cvsLine = $arrConvenience[$val];
547            }
548        }
549        $arrMemo['usable_cvs_company_id'] = sfSetConvMSG("¤ª»Ùʧ²Äǽ¤Ê¥³¥ó¥Ó¥Ë", $cvsLine);
550        // »Ùʧ´üÆü
551        $arrMemo['payment_limit_date'] = sfSetConvMSG("¤ª»Ùʧ´üÆü", date("Yǯm·îdÆü", strtotime($arrRes[0]['payment_limit_date'])));
552        // ¥Ø¥ë¥×²èÌÌ
553        if (GC_MobileUserAgent::isMobile()) {
554            $arrMemo['help_url'] = sfSetConvMSG("¤ª»ÙʧÊýË¡¤ÎÀâÌÀ", "http://www.paygent.co.jp/mb/pay_help/conv.html");
555        } else {
556            $arrMemo['help_url'] = sfSetConvMSG("¤ª»ÙʧÊýË¡¤ÎÀâÌÀ", "http://www.paygent.co.jp/service/pay_cvs.html");
557        }
558               
559        // ¼õÃí¥Æ¡¼¥Ö¥ë¤ËÊݸ
560        $arrVal["memo02"] = serialize($arrMemo);
561        // ½é´ü¥¹¥Æ¡¼¥¿¥¹¤òÀßÄꤹ¤ë¡£
562        $arrVal["status"] = $arrInitStatus[PAYGENT_CONVENI];       
563        break;
564    // ATM·èºÑ¤Î¾ì¹ç
565    case PAYGENT_ATM:
566        // ¥¿¥¤¥È¥ë¤òÀßÄꤹ¤ë
567        $arrMemo['title'] = sfSetConvMSG("ATM¤ª»Ùʧ", true);   
568        $arrMemo['pay_center_number'] = sfSetConvMSG("¼ýǼµ¡´ØÈÖ¹æ", $arrRes[0]['pay_center_number']);
569        $arrMemo['customer_number'] = sfSetConvMSG("¤ªµÒÍÍÈÖ¹æ", $arrRes[0]['customer_number']);
570        $arrMemo['conf_number'] = sfSetConvMSG("³ÎǧÈÖ¹æ", $arrRes[0]['conf_number']);
571        // »Ùʧ´üÆü
572        $arrMemo['payment_limit_date'] = sfSetConvMSG("¤ª»Ùʧ´üÆü", date("Yǯm·îdÆü", strtotime($arrRes[0]['payment_limit_date'])));
573        // ¥Ø¥ë¥×²èÌÌ
574        if (GC_MobileUserAgent::isMobile()) {
575            $arrMemo['help_url'] = sfSetConvMSG("¤ª»ÙʧÊýË¡¤ÎÀâÌÀ", "http://www.paygent.co.jp/mb/pay_help/atm.html");
576        } else {
577            $arrMemo['help_url'] = sfSetConvMSG("¤ª»ÙʧÊýË¡¤ÎÀâÌÀ", "http://www.paygent.co.jp/service/pay_atm.html");
578        }
579       
580        // ¼õÃí¥Æ¡¼¥Ö¥ë¤ËÊݸ
581        $arrVal["memo02"] = serialize($arrMemo);
582        // ½é´ü¥¹¥Æ¡¼¥¿¥¹¤òÀßÄꤹ¤ë¡£
583        $arrVal["status"] = $arrInitStatus[PAYGENT_ATM];       
584        break;
585    // ¶ä¹Ô¥Í¥Ã¥È¤Î¾ì¹ç
586    case PAYGENT_BANK:
587        // ½é´ü¥¹¥Æ¡¼¥¿¥¹¤òÀßÄꤹ¤ë¡£
588        $arrVal["status"] = $arrInitStatus[PAYGENT_BANK];
589        // ¶õ¤ÎÇÛÎó¤ò³ÊǼ¤·¤Æ¤ª¤¯
590        $arrVal["memo02"] = serialize(array());
591        break;
592    default:
593        break;
594    }
595   
596    // ¼õÃí¥Æ¡¼¥Ö¥ë¤Ëµ­Ï¿¤¹¤ë
597    $arrVal["memo01"] = MDL_PAYGENT_ID;     // ½èÍý·ë²Ì
598       
599    // memo02¤Ï¡¢»Ùʧ¾ðÊó¤ò³ÊǼ¤¹¤ë¡£
600    $arrVal["memo03"] = $resultStatus;      // ½èÍý·ë²Ì
601    $arrVal["memo04"] = $responseCode;      // ¥ì¥¹¥Ý¥ó¥¹¥³¡¼¥É
602    $arrVal["memo05"] = $responseDetail;    // ¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸
603    $arrVal["memo06"] = $arrRes[0]['payment_id'];       // ¾µÇ§ÈÖ¹æ
604    $arrVal["memo07"] = "";                 // ¥¹¥Æ¡¼¥¿¥¹¼èÆÀ¤Ç»ÈÍÑ
605    $arrVal["memo08"] = $telegram_kind;
606    $arrVal["memo09"] = "";                 // ¥«¡¼¥É·èºÑÏ¢·È¤Ç»ÈÍÑ
607    $arrVal["memo10"] = "";                 // ºÆ¼èÆÀÍѤÎnotice_id¤òÊݸ¤·¤Æ¤ª¤¯
608   
609    // ¼õÃí°ì»þ¥Æ¡¼¥Ö¥ë¤Ë¹¹¿·
610    sfRegistTempOrder($uniqid, $arrVal);
611   
612    // ¾µÇ§ÈÖ¹æ¤È¥á¥Ã¥»¡¼¥¸¤òÊÖ¤¹
613    return $arrRes[0];
614}
615
616/**************************************************************************************************************
617 * ´Ø¿ô̾   ¡§sfSetConvMSG
618 * ½èÍýÆâÍÆ ¡§¥³¥ó¥Ó¥Ë¾ðÊóɽ¼¨ÍÑ
619 * °ú¿ô1    ¡§
620 * °ú¿ô2    ¡§
621 * °ú¿ô3    ¡§
622 * Ìá¤êÃÍ   ¡§¼èÆÀ·ë²Ì
623 **************************************************************************************************************/
624function sfSetConvMSG($name, $value){
625    return array("name" => $name, "value" => $value);
626}
627
628/**************************************************************************************************************
629 * ´Ø¿ô̾   ¡§sfPaygentDisp
630 * ½èÍýÆâÍÆ ¡§¶¦Ä̤Îɽ¼¨½èÍý
631 * °ú¿ô1    ¡§
632 * °ú¿ô2    ¡§
633 * °ú¿ô3    ¡§
634 * Ìá¤êÃÍ   ¡§¼èÆÀ·ë²Ì
635 **************************************************************************************************************/
636function sfPaygentDisp($objPage, $payment_id) {
637    $objQuery = new SC_Query();
638    // »Ùʧ¤¤ÊýË¡¤ÎÀâÌÀ²èÁü¤ò¼èÆÀ¤¹¤ë¡£
639    $arrRet = $objQuery->select("payment_method, payment_image", "dtb_payment", "payment_id = ?", array($payment_id));
640    $objPage->tpl_payment_method = $arrRet[0]['payment_method'];
641    $objPage->tpl_payment_image = $arrRet[0]['payment_image'];
642    return $objPage;
643}
644
645/**************************************************************************************************************
646 * ´Ø¿ô̾   ¡§sfGetPaymentDB
647 * ½èÍýÆâÍÆ ¡§É¬Íפʥǡ¼¥¿¤ò¼èÆÀ¤¹¤ë¡£
648 * °ú¿ô1    ¡§
649 * °ú¿ô2    ¡§
650 * °ú¿ô3    ¡§
651 * Ìá¤êÃÍ   ¡§¼èÆÀ·ë²Ì
652 **************************************************************************************************************/
653function sfGetPaymentDB($module_id, $where = "", $arrWhereVal = array()){
654    $objQuery = new SC_Query();
655       
656    $arrVal = array($module_id);
657    $arrVal = array_merge($arrVal, $arrWhereVal);
658   
659    $arrRet = array();
660    $sql = "SELECT
661                module_id,
662                memo01 as merchant_id,
663                memo02 as connect_id,
664                memo03 as payment,
665                memo04 as connect_password,
666                memo05 as other_param
667            FROM dtb_payment WHERE module_id = ? " . $where;
668    $arrRet = $objQuery->getall($sql, $arrVal);
669
670    return $arrRet;
671}
672
673/**************************************************************************************************************
674 * ´Ø¿ô̾   ¡§sfPaygentBatch
675 * ½èÍýÆâÍÆ ¡§Æþ¶â¥¹¥Æ¡¼¥¿¥¹³Îǧ¥Ð¥Ã¥Á
676 * °ú¿ô1    ¡§
677 * °ú¿ô2    ¡§
678 * °ú¿ô3    ¡§
679 * Ìá¤êÃÍ   ¡§¼èÆÀ·ë²Ì
680 **************************************************************************************************************/
681function sfPaygentBatch() {
682    $objQuery = new SC_Query();
683   
684    // Àܳ¥â¥¸¥å¡¼¥ë¤Î¥¤¥ó¥¹¥¿¥ó¥¹¼èÆÀ (¥³¥ó¥¹¥È¥é¥¯¥¿)¤È½é´ü²½
685    $objPaygent = new PaygentB2BModule();
686    $objPaygent->init();
687   
688    //¡¡ÀßÄê¥Ñ¥é¥á¡¼¥¿¤Î¼èÆÀ
689    $arrPaymentDB = sfGetPaymentDB(MDL_PAYGENT_ID);
690   
691    $where = "memo01 = ? AND status = ?";
692    $arrOrder = $objQuery->select("order_id", "dtb_order", $where, array(MDL_PAYGENT_ID, ORDER_PAY_WAIT));
693   
694    // ¶¦Ḁ̈ǡ¼¥¿¤Î¼èÆÀ
695    $arrSend = sfGetPaygentShare(PAYGENT_REF, 0, $arrPaymentDB[0]);
696   
697    if(count($arrOrder) > 0) {
698        sfUpdatePaymentStatus($objPaygent, $arrSend);
699    }   
700}
701
702/**************************************************************************************************************
703 * ´Ø¿ô̾   ¡§sfPaygentTest
704 * ½èÍýÆâÍÆ ¡§Àܳ¥Æ¥¹¥È
705 * °ú¿ô1    ¡§
706 * °ú¿ô2    ¡§
707 * °ú¿ô3    ¡§
708 * Ìá¤êÃÍ   ¡§¼èÆÀ·ë²Ì
709 **************************************************************************************************************/
710function sfPaygentTest($arrParam) {
711    $objQuery = new SC_Query();
712   
713    // Àܳ¥â¥¸¥å¡¼¥ë¤Î¥¤¥ó¥¹¥¿¥ó¥¹¼èÆÀ (¥³¥ó¥¹¥È¥é¥¯¥¿)¤È½é´ü²½
714    $objPaygent = new PaygentB2BModule();
715    $objPaygent->init();
716       
717    // ¶¦Ḁ̈ǡ¼¥¿¤Î¼èÆÀ
718    $arrSend = sfGetPaygentShare(PAYGENT_REF, '0', $arrParam);
719
720    // ÅÅʸ¤ÎÁ÷ÉÕ
721    foreach($arrSend as $key => $val) {
722        $objPaygent->reqPut($key, $val);
723    }
724    // ÅÅʸ¤ÎÁ÷¿®
725    $objPaygent->post();
726   
727    // ½èÍý·ë²Ì¼èÆÀ¡Ê¶¦ÄÌ¡Ë
728    $resultStatus = $objPaygent->getResultStatus(); # ½èÍý·ë²Ì 0=Àµ¾ï½ªÎ», 1=°Û¾ï½ªÎ»
729           
730    if($resultStatus == 0) {
731        return true;
732    } else {
733        return false;
734    }
735}
736
737/**************************************************************************************************************
738 * ´Ø¿ô̾   ¡§sfUpdatePaymentStatus
739 * ½èÍýÆâÍÆ ¡§Æþ¶â¥¹¥Æ¡¼¥¿¥¹º¹Ê¬¾È²ñ¥Ð¥Ã¥Á
740 * °ú¿ô1    ¡§
741 * °ú¿ô2    ¡§
742 * °ú¿ô3    ¡§
743 * Ìá¤êÃÍ   ¡§¼èÆÀ·ë²Ì
744 **************************************************************************************************************/
745function sfUpdatePaymentStatus($objPaygent, $arrSend) {
746    $objQuery = new SC_Query();
747   
748    if (DB_TYPE == "pgsql") $col = "cast(memo10 AS int4)";
749    elseif (DB_TYPE == "mysql") $col = "cast(memo10 AS SIGNED)";
750    $notice_id = $objQuery->max("dtb_order", $col, "memo01 = ?", array(MDL_PAYGENT_ID));
751   
752    $objQuery->begin();
753   
754    // ¥¹¥Æ¡¼¥¿¥¹¤Î¼èÆÀ
755    $i = 0;
756    while($i < 1000) {
757        $arrRet = sfGetPaymentStatus($objPaygent, $arrSend);
758        if ($arrRet['result'] == 0) {
759            // ¼èÆÀÀ®¸ù
760            if($arrRet['success_code'] == '0') {
761                // ̤¼èÆÀ·èºÑÄÌÃÎID¤ÎÊÝ»ý
762                if($arrRet['payment_notice_id'] > $notice_id + 1) {
763                    for($notice_id++; $notice_id < $arrRet['payment_notice_id']; $notice_id++) {
764                        $arrErrId[] = $notice_id;
765                        gfPrintLog("·èºÑÄÌÃÎID=". $notice_id. "¤¬·çÈ֤Ǥ¹¡£");
766                    }
767                }
768                $notice_id = $arrRet['payment_notice_id'];
769                sfUpdatePaygentOrder($objQuery, $arrRet);
770            // ¼èÆÀ´°Î»
771            } elseif($arrRet['success_code'] == '1') {
772                gfPrintLog("º¹Ê¬¤Î¼èÆÀ¤¬½ªÎ»¤·¤Þ¤·¤¿¡£");
773                break;
774            // ¼èÆÀ¼ºÇÔ
775            } elseif($arrRet['payment_notice_id'] == "") {
776                $notice_id++;
777                $arrErrId[] = $notice_id;
778                gfPrintLog("·èºÑÄÌÃÎID=". $notice_id. "¤¬·çÈ֤Ǥ¹¡£");
779            }
780        } else {
781            gfPrintLog("º¹Ê¬¾È²ñ¤¬°Û¾ï½ªÎ»¤·¤Þ¤·¤¿¡£");
782            break;
783        }
784        $i++;
785    }
786   
787    // ¼èÆÀ¼ºÇÔ¥¹¥Æ¡¼¥¿¥¹¤ÎºÆ¼èÆÀ
788    for ($i = 0; $i < count($arrErrId); $i++) {
789        $arrRet = sfGetPaymentStatus($objPaygent, $arrSend, $arrErrId[$i]);
790        if ($arrRet['result'] == 0) {
791            // ºÆ¼èÆÀÀ®¸ù
792            if($arrRet['success_code'] == '0') {
793                sfUpdatePaygentOrder($objQuery, $arrRet);
794            // ºÆ¼èÆÀ¼ºÇÔ
795            } elseif($arrRet['payment_notice_id'] == "") {
796                gfPrintLog("·èºÑÄÌÃÎID=". $arrErrId[$i]. "¤ÎºÆ¼èÆÀ¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£¥Ð¥Ã¥Á¤ò¶¯À©½ªÎ»¤·¤Þ¤¹¡£");
797                $err_flg = false;
798                break;
799            }
800            // ºÆ¼èÆÀ´°Î»
801            if($i == count($arrErrId) - 1) {
802                gfPrintLog("º¹Ê¬¤ÎºÆ¼èÆÀ¤¬½ªÎ»¤·¤Þ¤·¤¿¡£");
803            }
804        } else {
805            gfPrintLog("º¹Ê¬¾È²ñ¡Ê¥ê¥È¥é¥¤¡Ë¤¬°Û¾ï½ªÎ»¤·¤Þ¤·¤¿¡£");
806            $err_flg = false;
807            break;
808        }
809    }
810   
811    // ¥³¥ß¥Ã¥ÈÀ®ÈÝȽÄê
812    if ($err_flg === false) {
813        $objQuery->rollback();
814    } else {
815        $objQuery->commit();
816    }
817}
818
819/**************************************************************************************************************
820 * ´Ø¿ô̾   ¡§sfGetPaymentStatus
821 * ½èÍýÆâÍÆ ¡§Æþ¶â¥¹¥Æ¡¼¥¿¥¹º¹Ê¬¾È²ñ¡Êº¹Ê¬¾È²ñ¤Ç¤ÏÊѹ¹¤Î¤¢¤Ã¤¿¤â¤Î¤À¤±¼èÆÀ¤¹¤ë¤¿¤áorder_id¤ÏÉÔÍסË
822 * °ú¿ô1    ¡§
823 * °ú¿ô2    ¡§
824 * °ú¿ô3    ¡§
825 * Ìá¤êÃÍ   ¡§¼èÆÀ·ë²Ì
826 **************************************************************************************************************/
827function sfGetPaymentStatus($objPaygent, $arrSend, $notice_id = "") {
828    // ´û¤Ë¼èÆÀ¤·¤¿º¹Ê¬¤ò¼èÆÀ
829    if($notice_id !== "") {
830        $arrSend['payment_notice_id'] = $notice_id;
831    }
832   
833    // ÅÅʸ¤ÎÁ÷ÉÕ
834    foreach($arrSend as $key => $val) {
835        $objPaygent->reqPut($key, $val);
836    }
837    // ÅÅʸ¤ÎÁ÷¿®
838    $objPaygent->post();
839   
840    // ¥ì¥¹¥Ý¥ó¥¹¤Î¼èÆÀ
841    while($objPaygent->hasResNext()) {
842        # ¥Ç¡¼¥¿¤¬Â¸ºß¤¹¤ë¸Â¤ê¡¢¼èÆÀ
843        $arrRes[] = $objPaygent->resNext(); # Í×µá·ë²Ì¼èÆÀ
844    }
845   
846    $arrRes[0]['result'] = $objPaygent->getResultStatus(); # ½èÍý·ë²Ì 0=Àµ¾ï½ªÎ», 1=°Û¾ï½ªÎ»
847   
848    foreach($arrRes[0] as $key => $val) {
849        // Shift-JIS¤Ç±þÅú¤¬¤¢¤ë¤Î¤Ç¡¢¥¨¥ó¥³¡¼¥É¤¹¤ë¡£
850        $arrRes[0][$key] = mb_convert_encoding($val, CHAR_CODE, "Shift-JIS");
851        gfPrintLog($key."->".$arrRes[0][$key]);
852    }
853   
854    return $arrRes[0];
855}
856
857/**************************************************************************************************************
858 * ´Ø¿ô̾   ¡§sfUpdatePaygentOrder($objQuery, $arrRet)
859 * ½èÍýÆâÍÆ ¡§»Ùʧ¥¹¥Æ¡¼¥¿¥¹¹¹¿·
860 * °ú¿ô1    ¡§
861 * °ú¿ô2    ¡§
862 * °ú¿ô3    ¡§
863 * Ìá¤êÃÍ   ¡§¼èÆÀ·ë²Ì
864 **************************************************************************************************************/
865function sfUpdatePaygentOrder($objQuery, $arrRet) {
866    /*
867     * 10:¿½¹þºÑ
868     * 12:»Ùʧ´ü¸ÂÀÚ¤ì
869     * 15:¿½¹þÃæÃÇ
870     * 40:¾Ã¹þºÑ
871     * 43:®Êó¸¡ÃκÑ
872     * 61:®Êó¼è¾ÃºÑ
873     * etc
874     */
875    if($arrRet['trading_id'] != "") {
876        // Æþ¶âºÑ¤ß¤ËÊѹ¹
877        if($arrRet['payment_status'] == '40' || $arrRet['payment_status'] == '43') {
878            $arrVal['status'] = ORDER_PRE_END;
879        // ¥­¥ã¥ó¥»¥ë¤ËÊѹ¹
880        } elseif($arrRet['payment_status'] == '12') {
881            $arrVal['status'] = ORDER_CANCEL;
882        }
883       
884        // ¼èÆÀ¥¹¥Æ¡¼¥¿¥¹¤òµ­²±¤¹¤ë¡£
885        $arrVal['memo07'] = $arrRet['payment_status'];
886        // ºÆÅپȲñ¤¹¤ë¾ì¹ç¤Ë»ÈÍѤ¹¤ë¡£
887        $arrVal['memo10'] = $arrRet['payment_notice_id'];
888        $objQuery->update("dtb_order", $arrVal, "order_id = ?", array($arrRet['trading_id']));
889    }
890}
891
892/**************************************************************************************************************
893 * ´Ø¿ô̾   ¡§sfPaygentOrder($paygent_type)
894 * ½èÍýÆâÍÆ ¡§¼õÃíÏ¢·È
895 * °ú¿ô1    ¡§
896 * °ú¿ô2    ¡§
897 * °ú¿ô3    ¡§
898 * Ìá¤êÃÍ   ¡§¼èÆÀ·ë²Ì
899 **************************************************************************************************************/
900function sfPaygentOrder($paygent_type, $order_id) {
901    global $arrDispKind;
902   
903    // Àܳ¥â¥¸¥å¡¼¥ë¤Î¥¤¥ó¥¹¥¿¥ó¥¹¼èÆÀ (¥³¥ó¥¹¥È¥é¥¯¥¿)¤È½é´ü²½
904    $objPaygent = new PaygentB2BModule();
905    $objPaygent->init();
906   
907    // ÀßÄê¥Ñ¥é¥á¡¼¥¿¤Î¼èÆÀ
908    $arrPaymentDB = sfGetPaymentDB(MDL_PAYGENT_ID);
909   
910    // ½èÍýʬ´ô
911    switch($paygent_type) {
912    case 'auth_cancel':
913        $kind = PAYGENT_AUTH_CANCEL;
914        break;
915    case 'card_commit':
916        $kind = PAYGENT_CARD_COMMIT;
917        break;
918    case 'card_commit_cancel':
919        $kind = PAYGENT_CARD_COMMIT_CANCEL;
920        break;
921    }
922   
923    // ·èºÑID¤Î¼èÆÀ
924    $objQuery = new SC_Query();
925    $payment_id = $objQuery->get("dtb_order", "memo06", "order_id = ?", array($order_id));
926   
927    $arrSend = sfGetPaygentShare($kind, $order_id, $arrPaymentDB[0], $payment_id);
928   
929    // ÅÅʸ¤ÎÁ÷ÉÕ
930    foreach($arrSend as $key => $val) {
931        $objPaygent->reqPut($key, $val);
932    }
933    // ÅÅʸ¤ÎÁ÷¿®
934    $objPaygent->post();
935
936    // ¥ì¥¹¥Ý¥ó¥¹¤Î¼èÆÀ
937    while($objPaygent->hasResNext()) {
938        # ¥Ç¡¼¥¿¤¬Â¸ºß¤¹¤ë¸Â¤ê¡¢¼èÆÀ
939        $arrRes[] = $objPaygent->resNext(); # Í×µá·ë²Ì¼èÆÀ
940    }
941
942    $resultStatus = $objPaygent->getResultStatus(); # ½èÍý·ë²Ì 0=Àµ¾ï½ªÎ», 1=°Û¾ï½ªÎ»
943    gfPrintLog('result'."->".$resultStatus);
944   
945    foreach($arrRes[0] as $key => $val) {
946        // Shift-JIS¤Ç±þÅú¤¬¤¢¤ë¤Î¤Ç¡¢¥¨¥ó¥³¡¼¥É¤¹¤ë¡£
947        $arrRes[0][$key] = mb_convert_encoding($val, CHAR_CODE, "Shift-JIS");
948        gfPrintLog($key."->".$arrRes[0][$key]);
949    }
950   
951    // Àµ¾ï½ªÎ»
952    if($resultStatus == '0') {
953        $objQuery = new SC_Query();
954        $arrVal['memo09'] = $kind;
955        $objQuery->update("dtb_order", $arrVal, "order_id = ?", array($order_id));
956        $arrReturn['return'] = true;   
957    } else {
958        $arrReturn['return'] = false;
959    }
960    $arrReturn['kind'] = $kind;
961    return $arrReturn;
962}
963
964/**************************************************************************************************************
965 * ´Ø¿ô̾   ¡§sfPaygentOrderPage($objPage)
966 * ½èÍýÆâÍÆ ¡§É½¼¨Íѥѥ顼¥á¡¼¥¿¤òÄɲ乤롣
967 * °ú¿ô1    ¡§
968 * °ú¿ô2    ¡§
969 * °ú¿ô3    ¡§
970 * Ìá¤êÃÍ   ¡§¼èÆÀ·ë²Ì
971 **************************************************************************************************************/
972function sfPaygentOrderPage($objPage) {
973    global $arrDispKind;
974    $objPage->arrDispKind = $arrDispKind;
975    return $objPage;
976}
977?>
Note: See TracBrowser for help on using the repository browser.