perf: PayPal webhooks: 处理手续费

webht/payment
Lei OT 1 year ago
parent d6e692a3ac
commit 857e318e03

@ -648,17 +648,21 @@ class Index extends CI_Controller {
$pn_invoice = ''; $pn_invoice = '';
$pn_mc_gross = ''; $pn_mc_gross = '';
$pn_mc_currency = ''; $pn_mc_currency = '';
$pn_mc_fee = '';
switch ($post_data->event_type) { switch ($post_data->event_type) {
case 'PAYMENT.SALE.COMPLETED': case 'PAYMENT.SALE.COMPLETED':
$pn_invoice = $post_data->resource->invoice_number; $pn_invoice = $post_data->resource->invoice_number;
$pn_mc_gross = $post_data->resource->amount->total; $pn_mc_gross = $post_data->resource->amount->total;
$pn_mc_currency = $post_data->resource->amount->currency; $pn_mc_currency = $post_data->resource->amount->currency;
$pn_payment_status = $post_data->resource->state; $pn_payment_status = $post_data->resource->state;
$post_data->mc_fee = $post_data->resource->transaction_fee->value;
break; break;
case 'PAYMENT.SALE.REFUNDED': case 'PAYMENT.SALE.REFUNDED':
$pn_payment_status = 'Refunded'; $pn_payment_status = 'Refunded';
$pn_mc_gross = '-' . $post_data->resource->amount->total; $pn_mc_gross = '-' . $post_data->resource->amount->total;
$post_data->parent_txn_id = $post_data->resource->sale_id; $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;
break; break;
case 'PAYMENT.CAPTURE.COMPLETED': case 'PAYMENT.CAPTURE.COMPLETED':
@ -666,16 +670,21 @@ class Index extends CI_Controller {
$pn_mc_gross = $post_data->resource->amount->value; $pn_mc_gross = $post_data->resource->amount->value;
$pn_mc_currency = $post_data->resource->amount->currency_code; $pn_mc_currency = $post_data->resource->amount->currency_code;
$pn_payment_status = $post_data->resource->status; $pn_payment_status = $post_data->resource->status;
$post_data->mc_fee = $post_data->resource->seller_receivable_breakdown->paypal_fee->value;
break; break;
case 'PAYMENT.CAPTURE.REFUNDED': case 'PAYMENT.CAPTURE.REFUNDED':
$pn_invoice = $post_data->resource->invoice_id; $pn_invoice = $post_data->resource->invoice_id;
$pn_mc_currency = $post_data->resource->amount->currency_code; $pn_mc_currency = $post_data->resource->amount->currency_code;
$pn_mc_gross = '-' . $post_data->resource->amount->value; $pn_mc_gross = '-' . $post_data->resource->amount->value;
$pn_payment_status = 'Refunded'; $pn_payment_status = 'Refunded';
// $post_data->parent_txn_id = $post_data->resource->sale_id; // $post_data->parent_txn_id = $post_data->resource->sale_id;
$parent_link = $post_data->resource->links[1]->href; $parent_link = $post_data->resource->links[1]->href;
$parent_path = parse_url($parent_link, PHP_URL_PATH); // Get the path from the URL $parent_path = parse_url($parent_link, PHP_URL_PATH); // Get the path from the URL
$post_data->parent_txn_id = basename($parent_path); $post_data->parent_txn_id = basename($parent_path);
$pn_mc_fee = '-' . $post_data->resource->seller_payable_breakdown->paypal_fee->value;
$post_data->mc_fee = $pn_mc_fee;
break; break;
default: // capture COMPLETED default: // capture COMPLETED
@ -869,7 +878,7 @@ class Index extends CI_Controller {
$is_webhook = false; $is_webhook = false;
if (isset($webhook_memo->id) && substr($webhook_memo->id, 0, 2)==="WH") { if (isset($webhook_memo->id) && substr($webhook_memo->id, 0, 2)==="WH") {
$is_webhook = true; $is_webhook = true;
$payment_fee = $webhook_memo->resource->transaction_fee->value; $payment_fee = property_exists($webhook_memo, 'mc_fee') ? $webhook_memo->mc_fee : $webhook_memo->resource->transaction_fee->value;
} else { } else {
$payment_fee = $webhook_memo->mc_fee; $payment_fee = $webhook_memo->mc_fee;
} }
@ -1133,7 +1142,8 @@ class Index extends CI_Controller {
if (isset($payment_memo->id) && substr($payment_memo->id, 0, 2)==="WH") { if (isset($payment_memo->id) && substr($payment_memo->id, 0, 2)==="WH") {
$is_webhook = true; $is_webhook = true;
$refund_amount = $payment_memo->refund_from_received_amount; $refund_amount = $payment_memo->refund_from_received_amount;
$payment_fee = $payment_memo->resource->refund_from_transaction_fee->value; // $payment_fee = $payment_memo->resource->refund_from_transaction_fee->value;
$payment_fee = property_exists($payment_memo, 'mc_fee') ? $payment_memo->mc_fee : $payment_memo->resource->refund_from_transaction_fee->value;
} else { } else {
$refund_amount = bcsub($payment_memo->mc_gross, $payment_memo->mc_fee); $refund_amount = bcsub($payment_memo->mc_gross, $payment_memo->mc_fee);
$payment_fee = $payment_memo->mc_fee; $payment_fee = $payment_memo->mc_fee;

Loading…
Cancel
Save