PayPal webhook 接收 case

webht/payment
Lei OT 6 months ago
parent 36192408b1
commit c4500b4819

@ -46,8 +46,11 @@
.unknown-color{ background-color: #999999;}
/* .text-completed {color: #00CC00;} */
.text-pending {color: #ff9900;}
/* .text-pending {color: #ff9900;} */
.text-pending {color: #00A2E8;}
.text-declined {color: #a94442;}
.text-under_review {color: #ff9900;}
.text-resolved {color: #ff9900;}
.text-approved {color: #777;}
.flex {display: flex;}
@ -168,19 +171,19 @@
</a>
<h1>Payment List</h1>
<a <?php if($method_code==='all') { ?> class="text-muted"<?php } ?>
href="<?php echo set_url_param(array('method'=>'all')) ?>">ALL</a>
href="<?php echo set_url_param(array('keywords'=>'','method'=>'all')) ?>">ALL</a>
&NonBreakingSpace;&boxv;&NonBreakingSpace;
<a <?php if(stripos($method_code, '15016') !== false) { ?> class="text-muted"<?php } ?>
href="<?php echo set_url_param(array('method'=>15016)) ?>">微信&raquo;</a>
href="<?php echo set_url_param(array('keywords'=>'','method'=>15016)) ?>">微信&raquo;</a>
&NonBreakingSpace;
<a <?php if(stripos($method_code,'15002') !== false) { ?> class="text-muted"<?php } ?>
href="<?php echo set_url_param(array('method'=>15002)) ?>">PayPal&raquo;</a>
href="<?php echo set_url_param(array('keywords'=>'','method'=>15002)) ?>">PayPal&raquo;</a>
&NonBreakingSpace;
<a <?php if(stripos($method_code,'15018') !== false || stripos($method_code,'15035') !== false) { ?> class="text-muted"<?php } ?>
href="<?php echo set_url_param(array('method'=>'15018,15035')) ?>">信用卡&raquo;</a>
href="<?php echo set_url_param(array('keywords'=>'','method'=>'15018,15035')) ?>">信用卡&raquo;</a>
&NonBreakingSpace;
<a <?php if(stripos($method_code,'15015') !== false) { ?> class="text-muted"<?php } ?>
href="<?php echo set_url_param(array('method'=>15015)) ?>">支付宝&raquo;</a>
href="<?php echo set_url_param(array('keywords'=>'','method'=>15015)) ?>">支付宝&raquo;</a>
&NonBreakingSpace;
&boxv;&NonBreakingSpace;
<!-- <a target="_blank" href="/webht.php/apps/pay/paymentservice/income_statistics">汇总统计&raquo;</a> -->

@ -643,25 +643,15 @@ class Index extends CI_Controller {
log_message('error',"paypal_webhook" . var_export($raw_post, 1));
$post_data = json_decode($raw_post);
log_message('error','paypal_webhook: ' . $post_data->event_type);
if (
strpos($post_data->event_type, 'COMPLETED') === false
&& strpos($post_data->event_type, 'REFUNDED') === false
&& strpos($post_data->event_type, 'PAYMENT.CAPTURE.REVERSED') === false
&& strpos($post_data->event_type, 'PAYMENT.CAPTURE.DECLINED') === false
&& strpos($post_data->event_type, 'PAYMENT.CAPTURE.PENDING') === false
&& strpos($post_data->event_type, 'PAYMENT.SALE.REVERSED') === false
&& strpos($post_data->event_type, 'CHECKOUT.ORDER.APPROVED') === false
) {
if ( ! in_array($post_data->event_type, [
'PAYMENT.CAPTURE.REVERSED','PAYMENT.CAPTURE.DECLINED','PAYMENT.CAPTURE.PENDING',
'PAYMENT.CAPTURE.COMPLETED','PAYMENT.CAPTURE.REFUNDED',
'CHECKOUT.ORDER.APPROVED',
'CUSTOMER.DISPUTE.UPDATED','CUSTOMER.DISPUTE.RESOLVED',
'PAYMENT.SALE.COMPLETED','PAYMENT.SALE.REFUNDED','PAYMENT.SALE.REVERSED',
])) {
return;
}
if ($post_data->event_type === 'PAYMENT-NETWORKS.ALTERNATIVE-PAYMENT.COMPLETED') {
return ;
}
// todo: CUSTOMER.DISPUTE.CREATED
// if ($post_data->event_type != 'PAYMENT.SALE.COMPLETED' && $post_data->event_type != 'PAYMENT.SALE.REFUNDED') {
// log_message('error',"paypal_webhook" . var_export($raw_post, 1));
// return;
// }
$default_payee = new stdClass();
$default_payee->email_address = "pays@chinahighlights.com";
@ -673,7 +663,7 @@ class Index extends CI_Controller {
$tp_payee->merchant_id = "5FUTQ9SU5P7CJ";
$tp_payee->merchant = "trippest";
$pn_txn_id = $post_data->resource->id;
$pn_txn_id = isset($post_data->resource->id) ? $post_data->resource->id : '';
$save_to_pn = true;
$pn_invoice = '';
@ -827,6 +817,36 @@ class Index extends CI_Controller {
// $payment_type = array_key_first($paymentSource);
$payer_state = $payment_type == 'paypal' ? strtolower($paymentSource[$payment_type]->account_status) : '';
break;
case 'CUSTOMER.DISPUTE.UPDATED':
case 'CUSTOMER.DISPUTE.RESOLVED':
$save_to_pn = false;
$fund_type = 'paypal.dispute';
$notice_status = $post_data->event_type === 'CUSTOMER.DISPUTE.UPDATED' ? 'sendfail' : 'closed';
$pn_txn_id = $post_data->resource->dispute_id;
$transactions = $post_data->resource->disputed_transactions[0];
$transaction_id = $transactions->seller_transaction_id;
$post_data->parent_txn_id = !empty($transaction_id) ? $transaction_id : ''; // refer_id
$pn_invoice = isset($transactions->invoice_number) ? $transactions->invoice_number : '';
// $pn_custom = isset($transactions->custom) ? $transactions->custom : '';
$dispute_amount = $post_data->resource->dispute_amount;
$pn_mc_gross = $dispute_amount->value;
$pn_mc_currency = $dispute_amount->currency_code;
$net_amount = $pn_mc_gross;
$pn_payment_status = $post_data->resource->status;
$transaction_status = strtolower($pn_payment_status);
// subject
$pn_custom = $post_data->resource->dispute_life_cycle_stage . "." . $post_data->resource->reason;
$remark = "[{$pn_custom}] " . (isset($post_data->resource->messages[0]) ? $post_data->resource->messages[0]->content : '');
$pn_receiver_account_id = $transactions->seller->merchant_id;
$seller = $this->fundsource_map('', $pn_receiver_account_id);
$pn_receiver_account_name = $seller->merchant;
$pn_receiver_account = $seller->email_address;
break;
default: // capture COMPLETED
@ -880,13 +900,13 @@ class Index extends CI_Controller {
'pay_amount' => $pn_mc_gross,
'pay_currency' => $pn_mc_currency,
'net_amount' => $net_amount,
'pay_fee' => $post_data->mc_fee,
'transaction_status' => $transaction_status, // $pn_payment_status,
'pay_fee' => isset($post_data->mc_fee) ? $post_data->mc_fee : 0,
'transaction_status' => $transaction_status, // $pn_payment_status, OPN_transactionResult
'payment_date' => $pn_payment_date,
'fund_source' => $pn_receiver_account_name,
'fund_type' => $fund_type,
'event' => $post_data->event_type,
'event_result' => $pn_payment_status,
'event_result' => $pn_payment_status, // OPN_resultCode
'referer_id' => isset($post_data->parent_txn_id) ? $post_data->parent_txn_id : '',
'payer_id' => $payer_id,
@ -2254,7 +2274,7 @@ class Index extends CI_Controller {
}
private function fundsource_map($pn_receiver_account) {
private function fundsource_map($pn_receiver_account, $pn_receiver_account_id = null) {
$default_payee = new stdClass();
$default_payee->email_address = "pays@chinahighlights.com";
$default_payee->merchant_id = "JE4VX9SSVGTVN";
@ -2278,7 +2298,20 @@ class Index extends CI_Controller {
"ycc@hainatravel.com" => "dev",
"0" => "unknown",
);
$find = isset($fundsource[$pn_receiver_account]) ? $fundsource[$pn_receiver_account] : $default_payee;
$fundsource_id = array(
"BUTDAQXCYBPTA" => $htravel_payee, // business":"pay@trippest.com"
"5FUTQ9SU5P7CJ" => $tp_payee, // business":"pay@trippest.com"
"JE4VX9SSVGTVN" => $default_payee, // "CHT",
"JE4VX9SSVGTVN" => $default_payee, // "CHT",
// "ycc@hainatravel.com" => "dev",
// "0" => "unknown",
);
if ($pn_receiver_account_id) {
$find = isset($fundsource_id[$pn_receiver_account_id]) ? $fundsource_id[$pn_receiver_account_id] : $default_payee;
}
if ($pn_receiver_account) {
$find = isset($fundsource[$pn_receiver_account]) ? $fundsource[$pn_receiver_account] : $default_payee;
}
return $find;
}
}

@ -34,9 +34,9 @@ class Online_payment_note_model extends CI_Model {
return false;
}
if ($check_exists === true) {
$sql = "SELECT TOP 1 OPN_SN
$sql = "SELECT TOP 1 OPN_SN,OPN_transactionResult
FROM OnlinePaymentNote
WHERE OPN_accountMethod={$column['OPN_accountMethod']} AND OPN_transactionId = '{$column['OPN_transactionId']}'";
WHERE OPN_accountMethod={$column['OPN_accountMethod']} AND OPN_transactionId = '{$column['OPN_transactionId']}' AND OPN_resultMsg = '{$column['OPN_resultMsg']}' ";
$query = $this->info->query($sql);
if ($query->num_rows() > 0) {
$update = array(
@ -44,6 +44,12 @@ class Online_payment_note_model extends CI_Model {
'OPN_netAmount' => $column['OPN_netAmount'],
'OPN_entryAmountCNY' => $column['OPN_entryAmountCNY'],
);
if ($query->row()->OPN_transactionResult !== $column['OPN_transactionResult']) {
$update['OPN_transactionResult'] = $column['OPN_transactionResult'];
$update['OPN_resultCode'] = $column['OPN_resultCode'];
$update['OPN_rawContent'] = $column['OPN_rawContent'];
$update['OPN_completeTime'] = $column['OPN_completeTime'];
}
$where = " OPN_SN=" . $query->row()->OPN_SN;
$this->update_note($where, $update);
return false;

Loading…
Cancel
Save