source: branches/beta/data/downloads/module/mdl_cybs/mdl_cybs_credit.php @ 16911

Revision 16911, 9.3 KB checked in by adachi, 15 years ago (diff)

暫定コミット(サイバーソース決済モジュール)

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php
Line 
1<?php
2/*
3 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
4 *
5 * http://www.lockon.co.jp/
6 */
7require_once MODULE_PATH . "mdl_cybs/mdl_cybs.inc";
8require_once MODULE_PATH . "mdl_cybs/class/mdl_cybs_config.php";
9require_once MODULE_PATH . "mdl_cybs/class/mdl_cybs_request.php";
10dl(MDL_CYBS_EXT);
11
12class LC_Page {
13    function LC_Page() {
14        $this->tpl_mainpage = MODULE_PATH . 'mdl_cybs/mdl_cybs_credit.tpl';
15        global $arrPayMethod;
16        $this->arrPayMethod = $arrPayMethod;
17        /**
18         * session_start»þ¤Îno-cache¥Ø¥Ã¥À¡¼¤òÍÞÀ©¤¹¤ë¤³¤È¤Ç
19         * ¡ÖÌá¤ë¡×¥Ü¥¿¥ó»ÈÍÑ»þ¤ÎÍ­¸ú´ü¸ÂÀÚ¤ìɽ¼¨¤òÍÞÀ©¤¹¤ë¡£
20         * private-no-expire:¥¯¥é¥¤¥¢¥ó¥È¤Î¥­¥ã¥Ã¥·¥å¤òµö²Ä¤¹¤ë¡£
21         */
22        session_cache_limiter('private-no-expire');
23    }
24}
25
26$objPage = new LC_Page();
27$objView = new SC_SiteView();
28$objSiteSess = new SC_SiteSession();
29$objCartSess = new SC_CartSession();
30$objCampaignSess = new SC_CampaignSession();
31$arrInfo = sf_getBasisData();
32
33$objDate = new SC_Date();
34$objDate->setStartYear(RELEASE_YEAR);
35$objDate->setEndYear(RELEASE_YEAR + CREDIT_ADD_YEAR);
36$objPage->arrYear = $objDate->getZeroYear();
37$objPage->arrMonth = $objDate->getZeroMonth();
38
39// ¥æ¡¼¥¶¥æ¥Ë¡¼¥¯ID¤Î¼èÆÀ¤È¹ØÆþ¾õÂÖ¤ÎÀµÅöÀ­¤ò¥Á¥§¥Ã¥¯
40$uniqid = sfCheckNormalAccess($objSiteSess, $objCartSess);
41
42$objForm = lfInitParam();
43$objPage->arrForm = $objForm->getFormParamList();
44
45$mode = isset($_POST['mode']) ? $_POST['mode'] : '';
46switch($mode) {
47
48case 'register':
49    // ÆþÎϹàÌܤθ¡¾Ú
50    if ($arrErr = lfCheckError($objForm)) {
51        $objPage->arrErr = $arrErr;
52        break;
53    }
54    // ¥«¡¼¥È½¸·×½èÍý
55    $objPage = sfTotalCart($objPage, $objCartSess, $arrInfo);
56    // °ì»þ¼õÃí¥Æ¡¼¥Ö¥ë¤ÎÆɹþ
57    $arrData = sfGetOrderTemp($uniqid);
58    // ¥«¡¼¥È½¸·×¤ò¸µ¤ËºÇ½ª·×»»
59    $arrData = sfTotalConfirm($arrData, $objPage, $objCartSess, $arrInfo);
60
61    // ¥ê¥¯¥¨¥¹¥È¤ÎÁ÷¿®
62    gfPrintLog('#### cybs request start ###' , MDL_CYBS_LOG);
63    $arrResults = lfSendRequest($objForm->getHashArray(), $arrData);
64    // ·ë²Ì¤ÎȽÄê
65    $e = lfIsError($arrResults);
66    if (PEAR::isError($e)) {
67        gfPrintLog('#### cybs request error ###' , MDL_CYBS_LOG);
68        gfPrintLog('-> cybs request results' , MDL_CYBS_LOG);
69        gfPrintLog(print_r($arrResults, true), MDL_CYBS_LOG);
70        $objPage->tpl_error = $e->getMessage();
71        break;
72    }
73
74    gfPrintLog('#### cybs request successfull ###', MDL_CYBS_LOG);
75    gfPrintLog('-> cybs request results', MDL_CYBS_LOG);
76    gfPrintLog(print_r($arrResults, true), MDL_CYBS_LOG);
77    gfPrintLog('#### cybs request end ###' , MDL_CYBS_LOG);
78
79    // À®¸ù»þ¤Ï´°Î»²èÌ̤ØÁ«°Ü
80    $objSiteSess->setRegistFlag();
81    lfRegisterOrderTemp($uniqid, $objForm->getHashArray(), $arrResults);
82    header("Location: " . URL_SHOP_COMPLETE);
83    exit;
84
85// Ìá¤ë¥Ü¥¿¥ó²¡²¼»þ
86case 'return':
87    $objSiteSess->setRegistFlag();
88    header("Location: " . URL_SHOP_CONFIRM);
89    exit;
90
91// Ä̾ïɽ¼¨
92default:
93}
94
95$objView->assignobj($objPage);
96$objView->display(SITE_FRAME);
97
98
99/**
100 * ¥Ñ¥é¥á¡¼¥¿¤Î½é´ü²½
101 *
102 * @return SC_FormParam
103 */
104function lfInitParam() {
105    $objForm = new SC_FormParam;
106    $objForm->addParam("¥«¡¼¥ÉÈÖ¹æ1", "card_no01", CREDIT_NO_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
107    $objForm->addParam("¥«¡¼¥ÉÈÖ¹æ2", "card_no02", CREDIT_NO_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
108    $objForm->addParam("¥«¡¼¥ÉÈÖ¹æ3", "card_no03", CREDIT_NO_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
109    $objForm->addParam("¥«¡¼¥ÉÈÖ¹æ4", "card_no04", CREDIT_NO_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
110    $objForm->addParam("¥«¡¼¥É´ü¸Âǯ", "card_year", 2, "n", array("EXIST_CHECK", "NUM_COUNT_CHECK", "NUM_CHECK"));
111    $objForm->addParam("¥«¡¼¥É´ü¸Â·î", "card_month", 2, "n", array("EXIST_CHECK", "NUM_COUNT_CHECK", "NUM_CHECK"));
112    $objForm->addParam("À«", "card_name01", STEXT_LEN, "KVa", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "ALPHA_CHECK"));
113    $objForm->addParam("̾", "card_name02", STEXT_LEN, "KVa", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "ALPHA_CHECK"));
114    $objForm->addParam("»ÙʧÊýË¡", "paymethod", STEXT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK"));
115    $objForm->setParam($_POST);;
116    return $objForm;
117}
118
119/**
120 * ÆþÎϹàÌܤΥ¨¥é¡¼¥Á¥§¥Ã¥¯
121 *
122 * @param SC_FormParam $objForm
123 * @return array|null
124 */
125function lfCheckError($objForm) {
126    if ($arrErr = $objForm->checkError()) {
127        return $arrErr;
128    }
129    return null;
130}
131
132/**
133 * ¥ê¥¯¥¨¥¹¥È¤òÁ÷¿®¤¹¤ë
134 *
135 * @param array $arrForm
136 * @param array $arrData
137 * @return array
138 */
139function lfSendRequest($arrForm, $arrData) {
140    global $objCartSess;
141    global $arrCybsRequestURL;
142    global $arrPref;
143
144    $objConfig =& new Mdl_Cybs_Config;
145    $objRequest = new CYBS_REQ;
146
147    $arrConfig = $objConfig->getConfig();
148
149    $cardNo = $arrForm['card_no01'] . $arrForm['card_no02'] . $arrForm['card_no03'] . $arrForm['card_no04'];
150    $expMo = $arrForm['card_month'];
151    $expyr = '20' . $arrForm['card_year'];
152    $phoneNo = $arrData['order_tel01'] . $arrData['order_tel02'] . $arrData['order_tel03'];
153
154    $objRequest->add_request("server_host", $arrCybsRequestURL[$arrConfig['cybs_request_url']]);
155    $objRequest->add_request("server_port", "80");
156    $objRequest->add_request("customer_cc_number", $cardNo);
157    $objRequest->add_request("customer_cc_expmo", $expMo);
158    $objRequest->add_request("customer_cc_expyr", $expyr);
159    $objRequest->add_request("customer_firstname", lfToSjis($arrData['order_name02']));
160    $objRequest->add_request("customer_lastname", lfToSjis($arrData['order_name01']));
161    $objRequest->add_request("customer_email", $arrData['order_email']);
162    $objRequest->add_request("customer_phone", $phoneNo);
163    $objRequest->add_request("bill_address1", lfToSjis($arrData['order_addr02']));
164    $objRequest->add_request("bill_city", lfToSjis($arrData['order_addr01']));
165    $objRequest->add_request("bill_state", lfToSjis($arrPref[$arrData['order_pref']]));
166    $objRequest->add_request("bill_zip", $arrData['order_zip01'] . $arrData['order_zip02']);
167    $objRequest->add_request("bill_country", "JP");
168    $objRequest->add_request("merchant_id", $arrConfig['cybs_merchant_id']);
169    $objRequest->add_request("merchant_ref_number", $arrData['order_id']);
170    $objRequest->add_request("currency", "JPY");
171
172    if ($arrConfig['cybs_subs_use']) {
173        lfAddSubsParam($objRequest, $arrConfig, $arrData);
174    } else {
175        lfAddAuthParam($objRequest, $arrForm, $arrData);
176    }
177
178    $request_array = $objRequest->requests;
179    gfPrintLog(print_r($request_array, true), MDL_CYBS_LOG);
180gfPrintLog(print_r($arrConfig, true), MDL_CYBS_LOG);
181    if( ($result = cybs_send($request_array)) == false ) {
182      print("error");
183      gfPrintLog('#### cybs_send() error ###' , MDL_CYBS_LOG);
184      exit;
185    }
186
187sfPrintR($request_array);
188ksort($result);
189sfPrintR($result);
190
191    return $result;
192}
193
194/**
195 * ¥ê¥¯¥¨¥¹¥È¤Î¥¨¥é¡¼¥Á¥§¥Ã¥¯
196 *
197 * @param array $arrResults
198 * @return boolean|PEAR::Error
199 */
200function lfIsError($arrResults) {
201    global $arrIcsAuthErr;
202    $ret = null;
203
204    switch ($arrResults['ics_rcode']) {
205    // À®¸ù
206    case '1':
207        $ret = true;
208        break;
209    case '0':
210        $msg = "½èÍý¤¬µñÈݤµ¤ì¤Þ¤·¤¿¡£\n" . $arrIcsAuthErr[$arrResults['ics_rflag']];
211        $ret = PEAR::raiseError($msg);
212        break;
213    case '-1':
214        $msg = "¥·¥¹¥Æ¥à¤Þ¤¿¤Ï¥Í¥Ã¥È¥ï¡¼¥¯¥¨¥é¡¼¤Ë¤è¤ê½èÍý¤¬¥¨¥é¡¼¤È¤Ê¤ê¤Þ¤·¤¿¡£\n" . $arrIcsAuthErr[$arrResults['ics_rflag']];
215        $ret = PEAR::raiseError($msg);
216        break;
217    default:
218        $ret = PEAR::raiseError("ÉÔÌÀ¤Ê¥¨¥é¡¼¤¬È¯À¸¤·¤Þ¤·¤¿¡£\n");
219    }
220
221    return $ret;
222}
223
224/**
225 * SJIS¤ØÊÑ´¹¤¹¤ë
226 *
227 * @param string $str
228 * @return string
229 */
230function lfToSjis($str) {
231    return mb_convert_encoding($str, 'SJIS', CHAR_CODE);
232}
233
234/**
235 * ÆþÎϾðÊó¤ò°ìÉôµ­Ï¿
236 *
237 * @param string $uniqid
238 * @param array $arrForm
239 */
240function lfRegisterOrderTemp($uniqid, $arrForm, $arrResults) {
241    $sqlval = array();
242    $sqlval['memo03'] = $arrForm['card_name01'] . " " . $arrForm['card_name02'];
243    $sqlval['memo02'] = serialize($arrResults['auth_auth_code']);
244
245    $objQuery = new SC_Query;
246    $objQuery->update("dtb_order_temp", $sqlval, "order_temp_id = ?", array($uniqid));
247}
248
249function lfAddSubsParam(&$objRequest, $arrConfig, $arrData) {
250    global $arrSubsFrequency;
251    $objCustomer = new SC_Customer;
252
253    if ($objCustomer->isLoginSuccess()) {
254        $customer_id = $objCustomer->getValue('customer_id');
255        $objRequest->add_request("customer_account_id", $customer_id);
256        gfPrintLog('-> cybs subs user=' . $customer_id);
257    } else {
258        gfPrintLog('-> cybs subs not customer');
259    }
260
261    $objRequest->add_request("ics_applications", "ics_pay_subscription_create");
262    $objRequest->add_request('card_type', MDL_CYBS_SUBS_CARD); // XXX
263    $objRequest->add_request('recurring_disable_auto_auth', 'N');
264    $objRequest->add_request('recurring_frequency', $arrSubsFrequency[MDL_CYBS_SUBS_FREQ]); // XXX
265    $objRequest->add_request('recurring_payment_amount', (string)$arrData['payment_total']);
266}
267
268function lfAddAuthParam(&$objRequest, $arrForm, $arrData) {
269    $objRequest->add_request("ics_applications", "ics_auth");
270
271    // »Ùʧ¤¤ÊýË¡
272    list($method, $paytimes) = split("-", $arrForm['paymethod']);
273    $objRequest->add_request("jpo_payment_method", $method);
274    if ($paytimes > 0) $objRequest->add_request("jpo_installments", $paytimes);
275
276    $objRequest->add_request("offer0", "offerid:0^amount:" . $arrData['payment_total']);
277}
278?>
Note: See TracBrowser for help on using the repository browser.