function index() { $staging_url = 'https://gscash.com/gateway/staging/gsprocess.asmx?wsdl'; $live_url = 'https://gscash.com/gateway/gsprocess.asmx?wsdl'; $this->initial_order(); $res = array(); $res = $this->pay_model->get_merchant_data_by_pay_type($this->order['pay_type_id'], $this->order['method_id']); //PayWithGsCash $gsLogin = $res['merchant_name']; $gsPassword = $res['merchant_key']; if ($this->order['method_id'] == 1) { $gsCode = $this->CI->input->post('gscash_code'); } else { $gsCode = $this->CI->input->post('gscash_mobile_code'); } $currArr = $this->pay_model->get_currency_by_id($this->order['currency']); $mBaseCurrency = $currArr[0]['currency_name']; $today = new DateTime(); // $temp_order = $this->pay_model->get_recharge_order($this->order['order_sn']); $update_order = array('order_sn' => $this->order['order_sn'], 'auth_code' => $gsCode); $this->CI->payorder->update_order($update_order); $payload = array('gsLogin' => $gsLogin, 'gsPassword' => $gsPassword, 'gsCode' => $gsCode, 'mTransactionId' => $this->order['order_sn'], 'mBaseCurrency' => $mBaseCurrency, 'mPaymentValue' => $this->order['pay_amount'], 'mDateTime' => $today->format('c')); $log_array = array('type' => 'GsCash PayWithGsCash', 'value' => $payload); log_message('gash', json_encode($log_array)); $client = new SoapClient($live_url, array("soap_version" => SOAP_1_1, "trace" => 1, "exceptions" => 0, "cache_wsdl" => 0)); $response = $client->PayWithGscash(array('Input' => $payload))->PayWithGscashResult; $log_array = array('type' => 'GsCash PayWithGscashResult', 'value' => $response); log_message('gash', json_encode($log_array)); if ($response->statusCode == 1) { $message = "Be declined <br/>beacause of " . $response->errDesc; $this->CI->payorder->over($message); exit; } else { if ($response->statusCode == 99) { exit; } else { if ($response->statusCode == 0) { //update order if ($response->transactionId != $this->order['order_sn']) { log_message('gash', 'respose transactionId:' . $response->transactionId . ' != order_sn: ' . $this->order['order_sn']); $msg = $this->recharge_lang['ask_to_contact']; // $message = "transaction Id:".$response->transactionId ." doesn't exist<br/>" .$msg ; $message = $response->transactionId . " " . $this->recharge_lang['order_no_exist'] . "<br/>" . $msg; $this->CI->payorder->over($message); exit; } $update_order = array('order_sn' => $this->order['order_sn'], 'tradeseq' => $response->gsTransactionId); //检查付款金额 if ($response->paymentValue != $this->order['pay_amount']) { $payment_info['game_id'] = $this->order['game_id']; $payment_info['pay_type_id'] = $this->order['pay_type_id']; $payment_info['method_id'] = $this->order['method_id']; $payment_info['currency'] = $this->order['currency']; $payment_info['goods_type_id'] = $this->order['goods_type']; $payment_info['create_time'] = $this->order['create_time']; $payment_info['pay_amount'] = $response->paymentValue; $yuanbao_amount_info = $this->CI->payorder->get_yuanbao_amount($payment_info); if (empty($yuanbao_amount_info)) { $log_array['value'] = json_encode($payment_info) . ' no yuanbao amount to match'; log_message('gash', json_encode($log_array)); $msg = $this->recharge_lang['ask_to_contact']; $message = $response->paymentValue . $mBaseCurrency . $this->recharge_lang['amount_not_exist'] . "<br/>" . $msg; $this->CI->payorder->over($message); exit; } $update_order['basic_yuanbao_amount'] = $yuanbao_amount_info[0]->yuanbao_amount; $update_order['extra_yuanbao_amount'] = $yuanbao_amount_info[0]->yuanbao_extra; $update_order['huodong_yuanbao_amount'] = $yuanbao_amount_info[0]->yuanbao_huodong; $update_order['yuanbao_amount'] = $update_order['basic_yuanbao_amount'] + $update_order['extra_yuanbao_amount'] + $update_order['huodong_yuanbao_amount']; } $this->CI->payorder->update_order($update_order); //TransactionInfo $payload = array('gsLogin' => $gsLogin, 'gsPassword' => $gsPassword, 'gsCode' => $gsCode, 'mTransactionId' => $response->transactionId); $log_array = array('type' => 'GsCash TransactionInfo', 'value' => $payload); log_message('gash', json_encode($log_array)); $client = new SoapClient($live_url, array("soap_version" => SOAP_1_1, "trace" => 1, "exceptions" => 0, "cache_wsdl" => 0)); $response = $client->TransactionInfo(array('Input' => $payload))->TransactionInfoResult; $log_array = array('type' => 'GsCash TransactionInfoResult', 'value' => $response); log_message('gash', json_encode($log_array)); if ($response->statusCode == 1) { $message = "Be declined <br/>beacause of " . $response->errDesc; $this->CI->payorder->over($message); exit; } else { if ($response->statusCode == 99) { exit; } else { if ($response->statusCode == 0) { if ($response->transactionId != $this->order['order_sn']) { //判断订单号是否正确 log_message('gash', $this->order['order_sn'] . "doesn't equal " . $response->transactionId); $msg = $this->recharge_lang['ask_to_contact']; $message = $response->transactionId . " " . $this->recharge_lang['order_no_exist'] . "<br/>" . $msg; $this->CI->payorder->over($message); exit; } $temp_order = $this->pay_model->get_recharge_order($this->order['order_sn']); if ($temp_order->offer_yuanbao == 1) { $msg = $this->recharge_lang['yuanbao_has_offered']; $this->CI->payorder->over($msg); exit; } //要不要判断信息是否被篡改 if ($temp_order->pay_amount != $response->paymentValue) { log_message('gash', $this->order['order_sn'] . "payment value was changed "); $msg = $this->recharge_lang['ask_to_contact']; //$message = $response->transactionId ." ödeme değeri değişmiştir <br/>".$msg; $message = $response->transactionId . " " . $this->recharge_lang['payment_was_changed'] . "<br/>" . $msg; $this->CI->payorder->over($message); exit; } $order_update = array('order_sn' => $response->transactionId); $this->CI->payorder->update_order_to_get_payment($order_update); //发放元宝 $offer_data_res = $this->offer_service($temp_order->order_sn, $temp_order->game_id); $spend_info = $this->recharge_lang['spent'] . " :{$response->paymentValue} {$mBaseCurrency}"; $message = $spend_info; if (!empty($response->changeGsCode)) { $change_info = $this->recharge_lang['voucher'] . ": " . $response->changeGsCode . " " . $this->recharge_lang['value'] . ": {$response->changeGsValue} {$response->changeGsCurr}" . " " . $this->recharge_lang['expiryDate'] . ": {$response->changeGsExpiryDate}"; $message = $message . "</br>" . $change_info; } if (empty($offer_data_res) || !$offer_data_res['status']) { log_message('gash', 'gscash offer ' . $condition['recharge_id'] . ' YUANBAO wrong . reason: ' . $offer_data_res['message']); $msg = $this->recharge_lang['ask_to_contact']; $message = $message . "</br>" . $msg; $this->CI->payorder->over($message); exit; } $offer_order['order_sn'] = $this->order['order_sn']; $update_res = $this->CI->payorder->update_order_to_offer_service($offer_order); if ($update_res == true) { log_message('gash', 'gscash offer YUANBAO SUCCESS order_sn' . $offer_order['order_sn']); $msg = $this->recharge_lang['recharge_success']; $message = $message . "</br>" . $msg; $this->CI->payorder->over($message, $temp_order->order_sn); exit; } else { log_message('gash', 'gscach update_order_to_offer_service failed' . $offer_order['order_sn']); $msg = $this->recharge_lang['recharge_success']; $message = $message . "</br>" . $msg; $this->CI->payorder->over($message, $temp_order->order_sn); exit; } } } } } } } }