verifySignature($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) { $order_id = (int) $data['order_id']; $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_PAY_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 verifySignature($data, $secret_key) { $signature = $data['signature']; // unset($data['signature']); // unset($data['wc-api']); $sign_data = array( 'status' => $data['status'], 'transaction_id' => $data['transaction_id'], 'order_id' => $data['order_id'], 'amount' => $data['amount'], 'shipping_fee' => $data['shipping_fee'], 'tax_fee' => $data['tax_fee'], 'transaction_type' => $data['transaction_type'], 'currency' => $data['currency'], 'country_code' => $data['country_code'], 'message' => $data['message'], ); ksort($sign_data); $data_str = implode('', $sign_data); $secret = pack('H*', strtoupper(md5($secret_key))); $new_signature = hash_hmac('sha256', $data_str, $secret); if($signature == $new_signature) { return true; } else { return false; } } }