From 639add9ad09b5fcb76dcca6f3e37d01172bc503d Mon Sep 17 00:00:00 2001 From: lyt Date: Thu, 23 May 2019 17:04:06 +0800 Subject: [PATCH] =?UTF-8?q?paypal=20=E6=8E=A5=E5=8F=97webhook=E9=80=9A?= =?UTF-8?q?=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../third_party/paypal/controllers/index.php | 64 ++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/webht/third_party/paypal/controllers/index.php b/webht/third_party/paypal/controllers/index.php index e609fba6..35fae3e7 100644 --- a/webht/third_party/paypal/controllers/index.php +++ b/webht/third_party/paypal/controllers/index.php @@ -611,9 +611,71 @@ class Index extends CI_Controller { return ; } + /*! + * [paypal_webhook description] + * @author LYT + * @date 2019-05-23 + * PAYMENT.SALE.COMPLETED 没有付款人信息 + * * resource.id=txn_id + * * invoice_number=invoice_number + */ public function paypal_webhook() { - log_message('error',"paypal_webhook" . var_export(file_get_contents('php://input'), 1)); + $raw_post = file_get_contents('php://input'); + if (empty($raw_post)) { + return; + } + $post_data = json_decode($raw_post); + if ($post_data->event_type != 'PAYMENT.SALE.COMPLETED') { + log_message('error',"paypal_webhook" . var_export(file_get_contents('php://input'), 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; + // } + + // $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_mc_currency = $post_data->resource->amount->currency; + $pn_payment_status = $post_data->resource->state; + $pn_payment_date = $post_data->resource->update_time; + // $pn_payer = $post_data->resource->amount->currency; + // $pn_payer_email = $post_data->resource->amount->currency; + $pn_memo = $raw_post; + if (!empty($pn_txn_id)) { + //把PDT时间转成GMT时间 + // $pn_payment_date = gmdate('Y-m-d H:i:s', strtotime($pn_payment_date)); + $this->Note_model->save_paypal_note( + $pn_txn_id, + $pn_invoice, + "", + $pn_mc_gross, + "", + "", + $pn_mc_currency, + $pn_payment_status, + "", + "", + $pn_payment_date, + $pn_memo); + log_message('error','paypal-webhook-succeed ' . $pn_txn_id . ' # ' . $pn_invoice); + // echo 'ok'; + } else { + // echo 'no'; + } + return; } //解析出订单号