diff --git a/webht/third_party/paypal/controllers/index.php b/webht/third_party/paypal/controllers/index.php index a5674e2e..3ab61712 100644 --- a/webht/third_party/paypal/controllers/index.php +++ b/webht/third_party/paypal/controllers/index.php @@ -632,35 +632,65 @@ class Index extends CI_Controller { return; } $post_data = json_decode($raw_post); - if ($post_data->event_type != 'PAYMENT.SALE.COMPLETED' && $post_data->event_type != 'PAYMENT.SALE.REFUNDED') { + if ( + strpos($post_data->event_type, 'COMPLETED') === false + && strpos($post_data->event_type, 'REFUNDED') === false + ) { log_message('error',"paypal_webhook" . var_export($raw_post, 1)); return; } - $pn_txn_id = $post_data->resource->id; - - $pn_invoice = $post_data->resource->invoice_number; - - $pn_mc_gross = $post_data->resource->amount->total; - - // $pn_item_name = $this->input->post('item_name'); - // if (empty($pn_item_name)) { - // $pn_item_name = $this->input->post('item_name1'); //APP用SDK支付的话会是item_name1 - // empty($pn_item_name) ? $pn_item_name = '' : false; + // 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; // } + $pn_txn_id = $post_data->resource->id; - // $pn_item_number = $this->input->post('item_number'); - // if (empty($pn_item_number)) { - // $pn_item_number = $this->input->post('item_number1'); //APP用SDK支付的话会是item_number1 - // empty($pn_item_number) ? $pn_item_number = '' : false; + $pn_invoice = ''; + $pn_mc_gross = ''; + $pn_mc_currency = ''; + switch ($post_data->event_type) { + case 'PAYMENT.SALE.COMPLETED': + $pn_invoice = $post_data->resource->invoice_number; + $pn_mc_gross = $post_data->resource->amount->total; + $pn_mc_currency = $post_data->resource->amount->currency; + $pn_payment_status = $post_data->resource->state; + break; + case 'PAYMENT.SALE.REFUNDED': + $pn_payment_status = 'Refunded'; + $pn_mc_gross = '-' . $post_data->resource->amount->total; + $post_data->parent_txn_id = $post_data->resource->sale_id; + break; + + case 'PAYMENT.CAPTURE.COMPLETED': + $pn_invoice = $post_data->resource->invoice_id; + $pn_mc_gross = $post_data->resource->amount->value; + $pn_mc_currency = $post_data->resource->amount->currency_code; + $pn_payment_status = $post_data->resource->status; + break; + case 'PAYMENT.CAPTURE.REFUNDED': + $pn_invoice = $post_data->resource->invoice_id; + $pn_mc_currency = $post_data->resource->amount->currency_code; + $pn_mc_gross = '-' . $post_data->resource->amount->value; + $pn_payment_status = 'Refunded'; + // $post_data->parent_txn_id = $post_data->resource->sale_id; + $parent_link = $post_data->resource->links[1]->href; + $parent_path = parse_url($parent_link, PHP_URL_PATH); // Get the path from the URL + $post_data->parent_txn_id = basename($parent_path); + break; + + default: // capture COMPLETED + $pn_invoice = $post_data->resource->invoice_id; + $pn_mc_gross = $post_data->resource->amount->value; + $pn_mc_currency = $post_data->resource->amount->currency_code; + $pn_payment_status = $post_data->resource->status; + break; + } + + // if ($post_data->event_type == 'PAYMENT.SALE.REFUNDED') { + // $pn_payment_status = 'Refunded'; + // $pn_mc_gross = '-' . $post_data->resource->amount->total; + // $post_data->parent_txn_id = $post_data->resource->sale_id; // } - - $pn_mc_currency = $post_data->resource->amount->currency; - $pn_payment_status = $post_data->resource->state; - if ($post_data->event_type == 'PAYMENT.SALE.REFUNDED') { - $pn_payment_status = 'Refunded'; - $pn_mc_gross = '-' . $post_data->resource->amount->total; - $post_data->parent_txn_id = $post_data->resource->sale_id; - } $pn_payment_date = $post_data->resource->update_time; // $pn_payer = $post_data->resource->amount->currency; // $pn_payer_email = $post_data->resource->amount->currency;