/** * Calculates signature only for model which implements OrderInterface. * Signature for order is string with multiple variables described in SIGNATURE_FORMAT. * It uses SignatureCalculatorInterface to calculate one of the parameters. * * @param OrderInterface $order * @param CredentialsInterface $credentials * @param AlgorithmInterface $algorithm * * @return string * @throws SignatureCalculatorException */ public function calculate(OrderInterface $order, CredentialsInterface $credentials, AlgorithmInterface $algorithm) { $signature = $this->signatureCalculator->calculate($this->getSortedParameters($order), $credentials, $algorithm); $signature = sprintf(self::SIGNATURE_FORMAT, $signature, $algorithm->getName(), $credentials->getMerchantPosId()); $this->logCalculatedSignature($order, $signature); return $signature; }
/** * @param string $data * @param string $signatureHeader * @param CredentialsInterface $credentials * * @return bool * @throws SignatureCalculatorException */ public function isSignatureValid($data, $signatureHeader, CredentialsInterface $credentials) { $calculatedSignature = $this->signatureCalculator->calculate(json_decode($data, true), $credentials, $this->extractAlgorithm($signatureHeader)); return $this->compareSignatureStrings($calculatedSignature, $this->extractSignature($signatureHeader)); }