feat: PayPal: 处理webhook, 把资源地址写入 GAI 表

webht/payment
Lei OT 1 year ago
parent a1d4c4cce1
commit e1829d5685

@ -733,6 +733,58 @@ class Index extends CI_Controller {
return;
}
/**
* 处理webhook
* * 把资源地址写入 GAI 表
* * * IPN先执行, 更新 GAI
* * * WB先执行, 需要等待IPN
*/
public function handle_webhook($item) {
$webhook_memo = json_decode($item->pn_memo);
$res_links = null;
$res_links = $webhook_memo->resource->links;
$res_links = json_encode($res_links, JSON_UNESCAPED_SLASHES);
$pn_txn_id = $item->pn_txn_id;
$orderid_info = $this->analysis_orderid($item->pn_invoice);
if (!empty($orderid_info)) {
$orderid_info = json_decode($orderid_info);
if ($orderid_info->ordertype === 'TP' || $orderid_info->ordertype === 'A') {
$orderid_info->ordertype = 'B';
}
$data_gai = null;
if ($orderid_info->ordertype === 'T') {
$data_gai = $this->Paypal_model->get_money_t($pn_txn_id);
if ( ! empty($data_gai)) {
$this->Paypal_model->update_money_api_t($pn_txn_id, $res_links);
$this->Note_model->update_send($item->pn_txn_id, 'send-wh-API', $item->pn_sn);
}
} elseif ($orderid_info->ordertype === 'B') {
$data_gai = $this->Paypal_model->get_money_b($pn_txn_id, false);
if ( ! empty($data_gai)) {
$this->Paypal_model->update_money_api_b($pn_txn_id, $res_links);
$this->Note_model->update_send($item->pn_txn_id, 'send-wh-API', $item->pn_sn);
}
}
}
return $res_links;
}
public function handle_webhook_batch() {
$data = array();
$data['notelist'] = $this->Note_model->notewebhooks(200, true);
$show_index = 0;
foreach ($data['notelist'] as $item) {
if ($item->pn_send === 'send-wh-API') {
continue;
}
echo ++$show_index . ' ' . $item->pn_txn_id . ' ' . $item->pn_payment_date . '<br/>';
// $webhook_memo = json_decode($item->pn_memo);
$this->handle_webhook($item);
}
}
//解析出订单号
public function analysis_orderid($note_invoice_string) {
$data = array();
@ -888,7 +940,8 @@ class Index extends CI_Controller {
$payment_fee = property_exists($webhook_memo, 'mc_fee') ? $webhook_memo->mc_fee : 0;
}
if (empty($pn_txn_id) && true === $is_webhook) {
$this->Note_model->update_send($item->pn_txn_id, 'send-wh', $item->pn_sn);
$this->handle_webhook($item);
// $this->Note_model->update_send($item->pn_txn_id, 'send-wh', $item->pn_sn);
continue;
}
@ -1770,6 +1823,10 @@ class Index extends CI_Controller {
$pn_id = $this->input->post('pn_id');
$neworder = $this->input->post('pn_invoice');
// log_message('error','test: ' . __METHOD__ . ':' . __LINE__ . PHP_EOL . var_export(0, 1));
// $this->send_note($pn_txn_id, $old_ssje);
// return;
$data['note'] = $this->Note_model->note($pn_txn_id, $pn_id);
$orderid_info = $this->analysis_orderid($data['note']->pn_invoice);
if (!empty($orderid_info)) {

@ -73,13 +73,14 @@ class Note_model extends CI_Model {
return $this->get_list();
}
public function notewebhooks($topnum = 2) {
public function notewebhooks($topnum = 2, $api = false) {
$this->init();
$this->topnum = $topnum;
$sql = " AND (SUBSTRING(pn_memo, 8, 3) ='WH-' ) ";
$this->pn_send = $sql;
// $this->orderby=" ORDER BY pn_payment_date DESC, pn.pn_sn ASC ";
$this->orderby=" ORDER BY CASE pn.pn_send WHEN 'sendfail' THEN 1 ELSE 2 END ,pn.pn_sn DESC ";
$api_order = $api === false ? "" : " WHEN 'send-wh' THEN 2 ";
$this->orderby=" ORDER BY CASE pn.pn_send WHEN 'sendfail' THEN 1 $api_order ELSE 99 END ,pn.pn_sn DESC ";
return $this->get_list();
}

@ -601,12 +601,13 @@ class Paypal_model extends CI_Model {
return $result;
}
//根据交易号获取收款记录(商务订单)
public function get_money_b($pn_invoice) {
public function get_money_b($pn_invoice, $find_memo = true) {
$find_memo_sql = $find_memo === true ? " OR GAI_Memo='$pn_invoice' " : "";
$sql = "SELECT BIZ_GroupAccountInfo.*
from BIZ_GroupAccountInfo
where DeleteFlag=0 and ( GAI_AccreditNo=? or GAI_Memo=? )
where DeleteFlag=0 and ( GAI_AccreditNo=? $find_memo_sql )
";
$query = $this->HT->query($sql, array($pn_invoice, $pn_invoice));
$query = $this->HT->query($sql, array($pn_invoice));
$result = $query->result();
return $result;
}
@ -624,6 +625,20 @@ class Paypal_model extends CI_Model {
return $query;
}
/** 更新收款记录 */
public function update_money_api_t($deadId, $links)
{
$sql = "UPDATE GroupAccountInfo SET GAI_API=? WHERE GAI_AccreditNo=? AND GAI_API IS NULL ";
$query = $this->HT->query($sql, array($links, $deadId));
return $query;
}
public function update_money_api_b($deadId, $links)
{
$sql = "UPDATE BIZ_GroupAccountInfo SET GAI_API=? WHERE GAI_AccreditNo=? AND GAI_API IS NULL ";
$query = $this->HT->query($sql, array($links, $deadId));
return $query;
}
/** JJH: 添加订单收款记录之后执行 */
public function exec_addToTask($GAI_SN)
{

Loading…
Cancel
Save