diff --git a/webht/third_party/paypal/controllers/index.php b/webht/third_party/paypal/controllers/index.php index 0f820481..04193088 100644 --- a/webht/third_party/paypal/controllers/index.php +++ b/webht/third_party/paypal/controllers/index.php @@ -643,6 +643,15 @@ class Index extends CI_Controller { // log_message('error',"paypal_webhook" . var_export($raw_post, 1)); // return; // } + + $default_payee = new stdClass(); + $default_payee->email_address = "pays@chinahighlights.com"; + $default_payee->merchant_id = "JE4VX9SSVGTVN"; + + $tp_payee = new stdClass(); + $tp_payee->email_address = "pay@trippest.com"; + $tp_payee->merchant_id = "5FUTQ9SU5P7CJ"; + $pn_txn_id = $post_data->resource->id; $pn_invoice = ''; @@ -650,6 +659,7 @@ class Index extends CI_Controller { $pn_mc_gross = ''; $pn_mc_currency = ''; $pn_mc_fee = ''; + $GAI_API = new stdClass(); switch ($post_data->event_type) { case 'PAYMENT.SALE.COMPLETED': $pn_invoice = $post_data->resource->invoice_number; @@ -657,6 +667,16 @@ class Index extends CI_Controller { $pn_mc_currency = $post_data->resource->amount->currency; $pn_payment_status = $post_data->resource->state; $post_data->mc_fee = $post_data->resource->transaction_fee->value; + + $GAI_API->payee = new stdClass(); + if (stripos($post_data->resource->soft_descriptor, 'CHINAHIG') !== false) { + $GAI_API->payee = $default_payee; + } + if (stripos($post_data->resource->soft_descriptor, 'TRIPP') !== false) { + $GAI_API->payee = $tp_payee; + } + $GAI_API->res_links = $post_data->resource->links; + $post_data->GAI_API = $GAI_API; break; case 'PAYMENT.SALE.REFUNDED': $pn_invoice = $post_data->resource->invoice_number; @@ -666,6 +686,10 @@ class Index extends CI_Controller { $post_data->parent_txn_id = $post_data->resource->sale_id; $pn_mc_fee = '-' . $post_data->resource->refund_from_transaction_fee->value; $post_data->mc_fee = $pn_mc_fee; + + $GAI_API->payee = new stdClass(); + $GAI_API->res_links = $post_data->resource->links; + $post_data->GAI_API = $GAI_API; break; case 'PAYMENT.CAPTURE.COMPLETED': @@ -675,6 +699,10 @@ class Index extends CI_Controller { $pn_mc_currency = $post_data->resource->amount->currency_code; $pn_payment_status = $post_data->resource->status; $post_data->mc_fee = $post_data->resource->seller_receivable_breakdown->paypal_fee->value; + + $GAI_API->payee = $post_data->resource->payee; + $GAI_API->res_links = $post_data->resource->links; + $post_data->GAI_API = $GAI_API; break; case 'PAYMENT.CAPTURE.REFUNDED': $pn_invoice = $post_data->resource->invoice_id; @@ -690,6 +718,12 @@ class Index extends CI_Controller { $pn_mc_fee = '-' . $post_data->resource->seller_payable_breakdown->paypal_fee->value; $post_data->mc_fee = $pn_mc_fee; + + $GAI_API->payee = $post_data->resource->payer; + $GAI_API->res_links = $post_data->resource->links; + + $post_data->GAI_API = $GAI_API; + break; default: // capture COMPLETED @@ -746,12 +780,13 @@ class Index extends CI_Controller { $res_links = $webhook_memo->resource->links; // $res_links = json_encode($res_links, JSON_UNESCAPED_SLASHES); - $default_payee = new stdClass; + $default_payee = new stdClass(); $default_payee->email_address = "pays@chinahighlights.com"; $default_payee->merchant_id = "JE4VX9SSVGTVN"; $payee = isset($webhook_memo->resource->payee) ? $webhook_memo->resource->payee : $default_payee; + $payee = property_exists($webhook_memo, 'GAI_API') ? $webhook_memo->GAI_API->payee : $payee; - $API = new stdClass; + $API = new stdClass(); $API->payee = $payee; $API->res_links = $res_links; @@ -944,6 +979,7 @@ class Index extends CI_Controller { echo ++$show_index . ' ' . $item->pn_txn_id . '
'; } + $GAI_API = null; $payment_fee = 0; // webhook的跳过 $webhook_memo = json_decode($item->pn_memo); @@ -951,6 +987,8 @@ class Index extends CI_Controller { if (isset($webhook_memo->id) && substr($webhook_memo->id, 0, 2)==="WH") { $is_webhook = true; $payment_fee = property_exists($webhook_memo, 'mc_fee') ? $webhook_memo->mc_fee : $webhook_memo->resource->transaction_fee->value; + + $GAI_API = property_exists($webhook_memo, 'GAI_API') ? $webhook_memo->GAI_API : null; } else { $payment_fee = property_exists($webhook_memo, 'mc_fee') ? $webhook_memo->mc_fee : 0; } @@ -1080,7 +1118,7 @@ class Index extends CI_Controller { $ht_memo = '交易号(自动录入):' . $item->pn_txn_id; //CHTAPP订单添加记录前判断是否有记录,以前的APP版本没有交易号,只能拿金额来判断 if (substr($advisor_info->COLI_WebCode, 0, 6) == 'CHTAPP' && strstr($advisor_info->COLI_WebCode, "-") !== '-biz') {//只判断前6位字符,CHTAPP-fr CHTAPP-jp等各语种都属于APP订单 - $this->Paypal_model->add_account_info_forAPP($GAI_COLI_SN, $advisor_info->COLI_ID, $item->pn_mc_gross, $item->pn_payment_date, mb_strtoupper($item->pn_mc_currency), $ssje, $item->pn_payment_date, $item->pn_payment_date, $item->pn_payment_date, $item->pn_payer, $item->pn_payer_email, $item->pn_txn_id, $ht_memo); + $this->Paypal_model->add_account_info_forAPP($GAI_COLI_SN, $advisor_info->COLI_ID, $item->pn_mc_gross, $item->pn_payment_date, mb_strtoupper($item->pn_mc_currency), $ssje, $item->pn_payment_date, $item->pn_payment_date, $item->pn_payment_date, $item->pn_payer, $item->pn_payer_email, $item->pn_txn_id, $ht_memo, $GAI_API); if ($advisor_info->COLI_WebCode == 'CHTAPP' && $advisor_info->COLI_State == 11) { //只修改APP组的订单状态,并且订单进度是我的订单 $this->Paypal_model->update_biz_coli_state($GAI_COLI_SN, 8); //把订单状态改为已付款 $this->Paypal_model->insert_biz_order_log($GAI_COLI_SN, 'BS8'); @@ -1105,7 +1143,7 @@ class Index extends CI_Controller { $item->pn_payer, $item->pn_payer_email, $item->pn_txn_id, - $ht_memo); + $ht_memo, $GAI_API); // 更新订单主表付款方式,防止没访问thankyou-train.asp $this->Paypal_model->update_paymanner($GAI_COLI_SN, '15010'); } @@ -1114,7 +1152,7 @@ class Index extends CI_Controller { elseif (isset($advisor_info->order_type) && $advisor_info->order_type == 1) { $ht_memo = '交易号(自动录入):' . $item->pn_txn_id; $GAI_COLI_SN = isset($advisor_info->COLI_SN) ? $advisor_info->COLI_SN : 0; - $gai_sn = $this->Paypal_model->add_tour_account_info($GAI_COLI_SN, $item->pn_mc_gross, $item->pn_payment_date, mb_strtoupper($item->pn_mc_currency), $ssje, $item->pn_payment_date, $item->pn_payment_date, $item->pn_payment_date, $item->pn_payer, $item->pn_payer_email, $item->pn_txn_id, $ht_memo); + $gai_sn = $this->Paypal_model->add_tour_account_info($GAI_COLI_SN, $item->pn_mc_gross, $item->pn_payment_date, mb_strtoupper($item->pn_mc_currency), $ssje, $item->pn_payment_date, $item->pn_payment_date, $item->pn_payment_date, $item->pn_payer, $item->pn_payer_email, $item->pn_txn_id, $ht_memo, $GAI_API); //添加汉特的订单提醒 $this->Paypal_model->update_coli_introduction($GAI_COLI_SN, '已支付 ' . mb_strtoupper($item->pn_mc_currency) . $item->pn_mc_gross); // 添加HT任务 diff --git a/webht/third_party/paypal/models/paypal_model.php b/webht/third_party/paypal/models/paypal_model.php index c10d5c4d..f2278b71 100644 --- a/webht/third_party/paypal/models/paypal_model.php +++ b/webht/third_party/paypal/models/paypal_model.php @@ -188,7 +188,7 @@ class Paypal_model extends CI_Model { } //添加收款记录(商务订单),APP会自动增加记录,所以添加前根据金额来判断是否有重复记录 - public function add_account_info_forAPP($GAI_COLI_SN, $GAI_COLI_ID, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo) { + public function add_account_info_forAPP($GAI_COLI_SN, $GAI_COLI_ID, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo, $GAI_API=null) { //先判断是否有这条数据 $sql = " IF NOT EXISTS( @@ -216,16 +216,17 @@ class Paypal_model extends CI_Model { ,GAI_CusEmail ,GAI_AccreditNo ,GAI_Memo + ,GAI_API ,GAI_State ,DeleteFlag,LastEditTime - ) VALUES (?,?,15010,?,?,?,?,?,?,?,?,?,?,?,0,0,GETDATE())"; - $query = $this->HT->query($sql, array($GAI_COLI_SN, $GAI_SQJE, $GAI_COLI_SN, $GAI_COLI_ID, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo)); + ) VALUES (?,?,15010,?,?,?,?,?,?,?,?,?,?,?,?,0,0,GETDATE())"; + $query = $this->HT->query($sql, array($GAI_COLI_SN, $GAI_SQJE, $GAI_COLI_SN, $GAI_COLI_ID, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo,$GAI_API)); $insertid = $this->HT->last_id('BIZ_GroupAccountInfo'); return $query; } //添加收款记录(商务订单) - public function add_account_info($GAI_COLI_SN, $GAI_COLI_ID, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_Money, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo) { + public function add_account_info($GAI_COLI_SN, $GAI_COLI_ID, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_Money, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo, $GAI_API=null) { //先判断是否有这条数据 $sql = " @@ -250,16 +251,17 @@ class Paypal_model extends CI_Model { ,GAI_CusEmail ,GAI_AccreditNo ,GAI_Memo + ,GAI_API ,GAI_State ,DeleteFlag,LastEditTime - ) VALUES (?,?,15002,?,?,?,?,?,?,?,?,?,?,?,?,0,0,GETDATE())"; - $query = $this->HT->query($sql, array($GAI_AccreditNo, $GAI_COLI_SN, $GAI_COLI_ID, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_Money, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo)); + ) VALUES (?,?,15002,?,?,?,?,?,?,?,?,?,?,?,?,?,0,0,GETDATE())"; + $query = $this->HT->query($sql, array($GAI_AccreditNo, $GAI_COLI_SN, $GAI_COLI_ID, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_Money, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo,$GAI_API)); $insertid = $this->HT->last_id('BIZ_GroupAccountInfo'); return $query; } //添加收款记录(传统订单) - public function add_tour_account_info($GAI_COLI_SN, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo) { + public function add_tour_account_info($GAI_COLI_SN, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo,$GAI_API=null) { //先判断是否有这条数据 $sql = " @@ -281,11 +283,11 @@ class Paypal_model extends CI_Model { ,GAI_CusName ,GAI_CusEmail ,GAI_AccreditNo - ,GAI_Memo + ,GAI_Memo,GAI_API ,GAI_State ,DeleteFlag,LastEditTime - ) VALUES (?,15002,?,?,?,?,?,?,?,?,?,?,?,0,0,GETDATE())"; - $query = $this->HT->query($sql, array($GAI_AccreditNo, $GAI_COLI_SN, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo)); + ) VALUES (?,15002,?,?,?,?,?,?,?,?,?,?,?,?,0,0,GETDATE())"; + $query = $this->HT->query($sql, array($GAI_AccreditNo, $GAI_COLI_SN, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo,$GAI_API)); $insertid = $this->HT->last_id('GroupAccountInfo'); return $insertid; }