/** * Validate the request's checksum * @throws Syspay_Merchant_RedirectException If the checksum didn't validate */ private function checkChecksum($result, $merchant, $checksum) { if (empty($merchant) || empty($checksum) || empty($result)) { throw new Syspay_Merchant_RedirectException('Missing parameter', Syspay_Merchant_RedirectException::CODE_MISSING_PARAM); } if (empty($this->secrets[$merchant])) { throw new Syspay_Merchant_RedirectException('Unknown merchant: ' . $merchant, Syspay_Merchant_RedirectException::CODE_UNKNOWN_MERCHANT); } if (!Syspay_Merchant_Utils::checkChecksum($result, $this->secrets[$merchant], $checksum)) { throw new Syspay_Merchant_RedirectException('Invalid checksum', Syspay_Merchant_RedirectException::CODE_INVALID_CHECKSUM); } }
/** * Validate the header's checksum * @throws Syspay_Merchant_EMSException If the checksum didn't validate */ private function checkChecksum() { if (empty($this->headers['x-merchant'])) { throw new Syspay_Merchant_EMSException('Missing x-merchant header', Syspay_Merchant_EMSException::CODE_MISSING_HEADER); } if (empty($this->headers['x-checksum'])) { throw new Syspay_Merchant_EMSException('Missing x-checksum header', Syspay_Merchant_EMSException::CODE_MISSING_HEADER); } if (!isset($this->secrets[$this->headers['x-merchant']])) { throw new Syspay_Merchant_EMSException('Unknown merchant: ' . $this->headers['x-merchant'], Syspay_Merchant_EMSException::CODE_UNKNOWN_MERCHANT); } if (!Syspay_Merchant_Utils::checkChecksum($this->content, $this->secrets[$this->headers['x-merchant']], $this->headers['x-checksum'])) { throw new Syspay_Merchant_EMSException('Invalid checksum', Syspay_Merchant_EMSException::CODE_INVALID_CHECKSUM); } }