onlinepayment: PayPal 获取支付方式

webht/payment
Lei OT 6 months ago
parent da2d812070
commit 100d06edb4

@ -50,6 +50,7 @@ class PaymentService extends CI_Controller {
if (!empty($data['keywords'])) {
$data['notelist'] = $this->note_model->search_key($data['keywords']);
} else {
// log_message('error','test: ' . __METHOD__ . ': ' . __LINE__ . ' ------' . PHP_EOL . var_export(1, 1));
$search_date = $this->note_model->search_date($data['date'], $method);
$unsend = $this->note_model->unsend_note(false, $method);
$sendfail = $this->note_model->sendfail_note(false, $method);
@ -133,6 +134,10 @@ class PaymentService extends CI_Controller {
}
// 开始处理
foreach ($data['unsend_list'] as $key => $item) {
if ($item->OPN_accountMethod === 15002) {
$this->paypal_flow($item);
continue;
}
// 只处理完成状态
if (mb_strtolower($item->OPN_transactionResult) !== 'completed') {
continue;
@ -429,6 +434,74 @@ class PaymentService extends CI_Controller {
return;
}
protected function paypal_flow($item)
{
// $calc_paypal_rate =
// 更新 付款方式, payer
$memo = json_decode($item->OPN_rawContent);
$paypal_order = '';
if ($item->OPN_noticeType == 'pay') {
$paypal_order = isset($memo->resource->supplementary_data) ?$memo->resource->supplementary_data->related_ids->order_id : (isset($memo->resource->application_context) ? $memo->resource->application_context->related_qualifiers[0]->id : '');
}
$paypal_account = $item->OPN_fundSource ? $item->OPN_fundSource : 'cht';
// log_message('error','test: ' . __METHOD__ . ': ' . __LINE__ . ' ' . PHP_EOL . var_export($paypal_order, 1));
// log_message('error','test: ' . __METHOD__ . ': ' . __LINE__ . ' ' . PHP_EOL . var_export($paypal_account, 1));
// log_message('error','test: ' . __METHOD__ . ': ' . __LINE__ . ' ' . PHP_EOL . var_export($item->OPN_noticeType, 1));
if (!empty($paypal_order) && !empty($paypal_account) && $item->OPN_noticeType == 'pay') {
$payment_ret = $this->get_paypal_order($paypal_order, $paypal_account);
if (!empty($payment_ret)) {
$where_str = " OPN_SN=" . $item->OPN_SN;
$update_note_column = array(
'OPN_paymentSource' => $payment_ret->payment_source_type,
'OPN_remark' => $payment_ret->description,
'OPN_payerLogId' => isset($payment_ret->payer->payer_id) ? $payment_ret->payer->payer_id : '',
'OPN_payerName' => isset($payment_ret->payer->fullname) ? $payment_ret->payer->fullname : '',
'OPN_payerEmail' => isset($payment_ret->payer->email_address) ? $payment_ret->payer->email_address : '',
'OPN_subject' => isset($payment_ret->item_number) && empty($item->subject) ? $payment_ret->item_number : $item->subject,
'OPN_noticeSendStatus' => 'closed', // 先忽略
);
$this->note_model->update_note($where_str, $update_note_column);
return false;
}
}
// todo: 退款记录
$where_str = " OPN_SN=" . $item->OPN_SN;
$update_note_column = array(
'OPN_noticeSendStatus' => 'closed', // 先忽略
);
$this->note_model->update_note($where_str, $update_note_column);
return false;
}
protected function get_paypal_order($paypal_order, $paypal_account)
{
$url = "https://secure.chinahighlights.com/pay/paypalservice/get_v2/order/$paypal_order/$paypal_account";
$order_str = get_url_contents($url);
// log_message('error','test: ' . __METHOD__ . ': ' . __LINE__ . ' ' . PHP_EOL . var_export($order_str, 1));
$order = json_decode($order_str, true);
$payment_source = $order['payment_source'];
$type = array_keys($payment_source)[0];
$purchase_units = $order['purchase_units'];
$description = isset($purchase_units[0]['description']) ? $purchase_units[0]['description'] : (isset($purchase_units[0]['items']) ? $purchase_units[0]['items'][0]['name'] : '');
$item_number = !isset($purchase_units[0]['invoice_id']) ? $description : '';
$payer = new stdClass();
if (isset($order['payer'])) {
$payer = (object) $order['payer'];
$payer->fullname = $payer->name['given_name'] . ' ' . $payer->name['surname'];
} else {
$payer->fullname = $payment_source[$type]['name'];
}
$ret = new stdClass();
// $ret->payment_source = $payment_source;
$ret->payment_source_type = $type;
$ret->description = $description;
$ret->payer = $payer;
$ret->item_number = $item_number;
return $ret;
}
/** 支付方式参数对应的配置文件名 */
/** @Deprecated */
public function method_name($name)
@ -677,6 +750,45 @@ class PaymentService extends CI_Controller {
return false;
}
/**
* 检查PayPal是否达到最低汇率的额度
* * 达到120万美元, 发邮件提醒
* 15号之后开始检查
*
**/
public function check_paypal_limit()
{
if (date('d') < '15') {
return false;
}
$year = date('Y', time());
$month = date('m', time());
$start = date('Y-m-d', strtotime("{$year}-{$month}-02"));
$end = date('Y-m-d', strtotime('+1 month', strtotime($start)));
// ? PayPal使用太平洋时间? GMT时间?
// * 从本月2 号开始, 到下个月2号.
$summary = $this->account_model->query_paypal_note_summary($start, $end);
$if_got_line = $summary[0]['running_total'] > 120*10000;
$current_total = number_format(bcdiv($summary[0]['running_total'], (1*10000)), 2);
if ( ! $if_got_line) {
return false;
}
// 达到了 120 万美元, 就发邮件, 提醒切换渠道
$time_set = date('Y-m-d_H_i_s');
$fromName = 'PayPal 额度提醒';
$fromEmail = 'lyt@hainatravel.com';
$toName = 'LOT, fgy'; // 'fgy';
$toEmail = 'lyt@hainatravel.com, fgy@hainatravel.com'; // 'fgy@hainatravel.com';
$subject = $fromName;
$body = "PayPal收款额度已达, 可切换信用卡渠道. <br>当前总额: {$current_total} 万 USD<br/>------------<br/>支付系统自动发送<br>". date("Y-m-d H:i"). ". <br>";
$M_AddTime = $time_set;
$M_State = 0;
// $this->account_model->save_automail($fromName, $fromEmail, $toName, $toEmail, $subject, $body, 0, $M_State, $M_AddTime, $fromName, $fromName);
echo $toEmail.'<br>';
echo $body;
return false;
}
public function ipalinks_settlement($year, $month, $day="01")
{
set_time_limit(0);

@ -342,6 +342,22 @@ function checkEmpty($value)
return false;
}
function get_url_contents($url)
{
if (ini_get("allow_url_fopen") == "1")
{
return file_get_contents($url);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
/**
* 连连支付
* @uses LianlianService

@ -615,6 +615,45 @@ class Online_payment_account_model extends CI_Model {
return $this->HT->query($sql, $note_sn);
}
function query_paypal_note_summary($start, $end) {
$sql = "SELECT pn_mc_currency
,round(sum(pn_mc_gross), 3) AS _sum_currency
,round(sum(pn_mc_gross)*to_usd,3) as _sum_usd
,SUM(sum(pn_mc_gross)*to_usd) OVER () AS running_total
FROM (
SELECT pn_txn_id
,pn_invoice
,cast(pn_mc_gross AS FLOAT) AS pn_mc_gross
,pn_mc_currency
,case pn_mc_currency when 'USD' then 1
when 'AUD' then 0.63
when 'CAD' then 0.70
when 'CHF' then 1.13
when 'EUR' then 1.08
when 'GBP' then 1.29
when 'HKD' then 0.13
when 'JPY' then 0.0067
when 'SGD' then 0.75
when 'NZD' then 0.57
else 1
end as to_usd
,pn_payer_email
,pn_payer
,pn_payment_date
,pn_datetime
,pn_sn
,ROW_NUMBER() OVER ( PARTITION BY pn_txn_id ORDER BY pn_sn DESC ) AS rn
FROM paypal_note p1
WHERE p1.pn_send = 'send'
-- AND p1.pn_datetime BETWEEN '2025-03-02' AND '2025-03-15'
AND p1.pn_datetime BETWEEN '{$start}' AND '{$end}'
) cn
GROUP BY cn.pn_mc_currency, to_usd
order by pn_mc_currency ";
$ret = $paypal_sum = $this->HT->query($sql)->result_array();
return $ret;
}
public function get_advisor_detail($COLI_SN, $OPI_SN, $lgc=1)
{
$advisor_signature = $this->get_advisor_signature($COLI_SN);

@ -87,6 +87,7 @@ class Online_payment_note_model extends CI_Model {
$this->send = " AND (OPN_noticeSendStatus) = 'closed' ";
$this->search = $method===null ? "" : " AND OPN_accountMethod IN ($method) ";
$this->search .= " AND OPN_noticeTime BETWEEN '$date 00:00:00' AND '$date 23:59:59' ";
$this->orderby = " ORDER BY CASE OPN_transactionResult WHEN 'completed' THEN 0 ELSE 1 END, OPN_SN DESC ";
return $this->query_note();
}

@ -46,12 +46,16 @@
<p>
<?php
if (!empty($order_info)) {
$show_info = array_intersect_key((array)$order_info, array_flip(['COLI_SN', 'COLI_ID', 'OPI_Email', 'OPI_Name','COLI_GroupCode', 'COLI_OrderDetailText']));
$show_json = json_encode($show_info, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
echo "<pre style='max-height:220px;overflow-y:auto;'>";
echo "COLI_SN => $order_info->COLI_SN<br/>";
echo "COLI_ID => $order_info->COLI_ID<br/>";
echo "OPI_Email => $order_info->OPI_Email<br/>";
echo "OPI_Name => $order_info->OPI_Name<br/>";
echo!empty($order_info->COLI_GroupCode) ? "COLI_GroupCode => $order_info->COLI_GroupCode<br/>" : false;
echo!empty($order_info->COLI_OrderDetailText) ? "COLI_OrderDetailText => $order_info->COLI_OrderDetailText\n" : false;
echo "</pre>";
} else {
echo '找不到目标订单内容';
}

@ -220,7 +220,7 @@
<p>5.Denied 银行拒付,需要手工关闭此通知</p>
<p>6.closed 已经关闭此通知</p>
<h4>记录状态:</h4>
<p>1.recorded 表示已经录入HT订单收款</p>
<p>1. 表示已经录入HT订单收款</p>
</div>
</div>
<!-- left end -->
@ -230,8 +230,9 @@
<tr>
<th width="20">#</th>
<th width="360">主题</th>
<th width="280" class="hidden-xs">subject</th>
<th width="280" class="hidden-xs">交易号</th>
<th width="150">付款人</th>
<th width="240" class="hidden-xs">subject</th>
<th width="150" class="hidden-xs">交易号</th>
<th width="150">收单时间</th>
<!-- <th width="150" class="hidden-xs">通知时间</th> -->
<th width="150" class="hidden-xs">账单&nbsp;/&nbsp;录入</th>
@ -246,15 +247,21 @@
<td><?php echo $key+1; ?></td>
<td><span class="brand_text <?php echo strtolower(str_replace(" ","",$item->brand_name))."-color"; ?>"><?php echo $item->brand_name; ?></span>
<span class="brand_text <?php echo strtolower(str_replace('cht', '',str_replace(" ","",$item->OPN_fundSource)))."-color"; ?>"><?php echo str_replace('cht', '', $item->OPN_fundSource); ?></span>
<?php echo $item->OPN_orderId . ' / ' . $item->OPN_orderAmount . $item->OPN_currency; ?></td>
<span><?php echo $item->OPN_orderId . ' / ' ?><b><?php echo $item->OPN_orderAmount; ?></b><?php echo $item->OPN_currency; ?></span>
<?php // echo $item->OPN_orderId . ' / ' . $item->OPN_orderAmount . $item->OPN_currency; ?>
</td>
<td><?= $item->OPN_payerName ? $item->OPN_payerName : $item->OPN_payerEmail ?></td>
<td class="hidden-xs">
<span class="brand_text <?php echo strtolower(str_replace(" ","",$item->app_name))."-color"; ?>"><?php echo $item->app_name; ?></span>
<?php
echo $item->OPN_subject;
?>
<?php if ($item->app_name) { ?>
<span class="brand_text <?php echo strtolower(str_replace(" ","",$item->app_name))."-color"; ?>"><?php echo $item->app_name; ?></span>
<?php } ?>
<?php if ($item->OPN_subject) { ?>
<span><?= $item->OPN_subject ?></span>
<?php } else { ?>
<div><?= $item->OPN_remark ?></div>
<?php } ?>
<?php // echo $item->OPN_subject ? "<span>{$item->OPN_subject}</span>" : ''; ?>
<?php // echo $item->OPN_remark ? "<div>{$item->OPN_remark}</div>" : ''; ?>
</td>
<td class="hidden-xs"><?php echo $item->OPN_transactionId; ?></td>
<td><?php echo $item->OPN_acquiringTime; ?></td>

@ -568,7 +568,7 @@ class Online_payment_note_model extends CI_Model {
$save_column['OPN_completeTime'] = $localSqlDateTime;
$save_column['OPN_accountMethod'] = 15002; // $this->config->item('method_code', 'paypal');
$save_column['OPN_noticeSendStatus'] = 'closed';
$save_column['OPN_noticeSendStatus'] = '';
$save_column['OPN_transactionResult'] = $result_data['transaction_status'];
$save_column['OPN_orderId'] = $result_data['invoice_id'];
$save_column['OPN_rawOrderId'] = $result_data['invoice_id'];

Loading…
Cancel
Save