error(lang("controller.missing_order_sn"), url('visa/index')))); } $this->order_sn = input('order_sn'); } public function pay() { $order_info = Httpcurl::request(config('app.GET_ORDER_DETAIL_URL'), 'post', ['order_sn' => $this->order_sn, 'model' => MODEL]); $order_info = json_decode($order_info[0], true); if ($order_info['code'] == '0') { return json([ 'status' => 0, 'msg' => lang("controller.order_not_exist"), 'url' => url('visa/index')->build() ]); } $order_info = $order_info['data']; if (empty($order_info)) { return $this->error(lang("controller.order_not_exist"), url('visa/index')); } /*判断订单状态*/ if ($order_info['pay_status'] == 1 ) { return $this->success(lang("controller.payment_success"), url('visa/index')); } /*判断订单状态*/ View::assign('order_sn', $order_info['order_sn']); View::assign('total_fee', number_format($order_info['total_price'] / 100, 2)); View::assign('total_price', $order_info['total_price']); View::assign('order_info', $order_info); View::assign('applicationId', config('app.SQ_CONIG')['app_id']); View::assign('locationId', config('app.SQ_CONIG')['location_id']); View::assign('pay_country', config('app.SQ_COUNTRY')); View::assign('currency', config('app.SQ_CURRENCY')); View::assign('uid', uniqid()); return View::fetch(); } public function paySquare() { $request_body = file_get_contents('php://input'); $data = json_decode($request_body, true); $data['note'] = MODEL; $response = HttpCurl::request(config('app.SQ_PAY_URL'), 'post', $data); if ($response[3]) { return json(['code' => 0, 'msg' => lang("controller.payment_not_completed")]); } $pay_result = json_decode($response[0], true); if ($pay_result) { if ($pay_result['code'] == 1) { return json(['code' => 1, 'msg' => lang("controller.payment_success"), 'data' => $pay_result['msg'], 'url' => url('sqpay/succ',['order_sn'=>$this->order_sn])->build()]); } else { return json(['code' => 0, 'msg' => lang("controller.payment_not_completed")]); } } } private function getOrderDetail() { $order_info = Httpcurl::request(config('app.GET_ORDER_DETAIL_URL'), 'post', ['order_sn' => $this->order_sn, 'model' => MODEL]); return json_decode($order_info[0], true); } public function payStatus() { $order_info = $this->getOrderDetail(); if (($order_info['code'] ?? '0') == '0') { return json([ 'status' => -1, 'msg' => lang("controller.order_not_exist"), 'url' => url('visa/index')->build() ]); } $order_data = $order_info['data'] ?? []; $is_paid = ($order_data['pay_status'] ?? 0) == 1 ; return json([ 'status' => $is_paid ? 1 : 0, 'msg' => $is_paid ? lang("controller.payment_success") : lang("sqpay.notice_text"), 'url' => $is_paid ? url('sqpay/succ', ['order_sn' => $this->order_sn])->build() : url('sqpay/pay', ['order_sn' => $this->order_sn])->build() ]); } public function succ() { $order_info = $this->getOrderDetail(); if (($order_info['code'] ?? '0') == '0') { return $this->error(lang("controller.order_not_exist")); } $order_info = $order_info['data'] ?? []; $payment_confirmed = ($order_info['pay_status'] ?? 0) == 1 ; $arrive_date = $order_info['arrive_date'] ?? ''; $arrive_timestamp = $arrive_date ? strtotime($arrive_date) : false; $latest_submit_timestamp = strtotime(date('Y-m-d') . ' +' . ARRIVE_DATE_COUNT . ' days 23:59:59'); if ($arrive_timestamp === false || $arrive_timestamp < $latest_submit_timestamp) { View::assign('arrive_date_info', ''); } else { $arrive_date_info = sprintf(lang("pay.arrive_date_info"), $arrive_date, date('Y-m-d', $arrive_timestamp - ARRIVE_DATE_COUNT * 86400)); View::assign('arrive_date_info', $arrive_date_info); } View::assign('payment_confirmed', $payment_confirmed); View::assign('poll_status_url', url('sqpay/payStatus', ['order_sn' => $this->order_sn])->build()); View::assign('repay_url', url('sqpay/pay', ['order_sn' => $this->order_sn])->build()); View::assign('order_sn', $this->order_sn); return View::fetch('pay/success'); } }