verifyHash($data, $this->appota_api_secret)) { return array( 'error_code' => 103, 'message' => 'Sai signature gửi đến. Không thể thực hiện thanh toán!' ); } return array( 'error_code' => 0, 'message' => 'Thông tin request thành công!' ); } public function checkValidOrder($data) { $developer_trans_id = $data['developer_trans_id']; $tran_id_arr = explode('-', $developer_trans_id); $order_id = (int) $tran_id_arr[1]; $transaction_status = (int) $data['status']; $total_amount = floatval($data['amount']); $confirm = ''; //Kiểm tra trạng thái giao dịch if ($transaction_status == APPOTA_WALLET_TRANSACTION_STATUS_COMPLETED) { //Lấy thông tin order if ($order_id === 0) { $confirm .= "\r\n" . ' Không nhận được mã đơn hàng nào : ' . $order_id; return array( 'error_code' => 106, 'message' => $confirm ); } //Kiểm tra sự tồn tại của đơn hàng $order_info = new WC_Order($order_id); if (empty($order_info)) { $confirm .= "\r\n" . ' Đơn hàng với mã đơn : ' . $order_id . ' không tồn tại trên hệ thống'; return array( 'error_code' => 107, 'message' => $confirm ); } //Kiểm tra số tiền đã thanh toán phải >= giá trị đơn hàng //Lấy giá trị đơn hàng if ($total_amount < $order_info->order_total) { $confirm .= "\r\n" . ' Số tiền thanh toán: ' . $total_amount . ' cho đơn hàng có mã : ' . $order_id . ' nhỏ hơn giá trị của đơn hàng.'; $order_info->update_status('on-hold', sprintf(__('Thanh toán tạm giữ: %s', 'woocommerce'), $confirm)); return array( 'error_code' => 108, 'message' => $confirm ); } } else { $confirm .= "\r\n" . ' Trạng thái giao dịch:' . $transaction_status . ' chưa thành công với mã đơn hàng : ' . $order_id; return array( 'error_code' => 109, 'message' => $confirm ); } if ($confirm == '') { return array( 'error_code' => 0, 'message' => 'Đơn hàng hợp lệ' ); } return array( 'error_code' => 104, 'message' => $confirm ); } private function verifyHash($data, $secret_key) { $hash = $data['hash']; $hash_data = array( 'amount' => $data['amount'], 'country_code' => $data['country_code'], 'currency' => $data['currency'], 'developer_trans_id' => $data['developer_trans_id'], 'sandbox' => $data['sandbox'], 'state' => $data['state'], 'status' => $data['status'], 'target' => $data['target'], 'transaction_id' => $data['transaction_id'], 'transaction_type' => $data['transaction_type'], 'vendor' => $data['vendor'] ); ksort($hash_data); $data_str = implode('', $hash_data); // $data_str .= $secret_key; $new_hash = md5($data_str . $secret_key); if($hash == $new_hash) { return true; } else { return false; } } }