public function __construct(RequestInterface $request, $data) { parent::__construct($request, $data); $requestParams = $request->getParameters(); $secureKey = $requestParams['secureKey']; $hashedSignature = GopayHelper::hash(GopayHelper::concatPaymentStatus($data, $secureKey)); $decryptedHash = GopayHelper::decrypt($data->encryptedSignature, $secureKey); if ($decryptedHash != $hashedSignature) { throw new InvalidResponseException("Invalid response signature"); } }
/** * Kontrola parametru predavanych ve zpetnem volani po potvrzeni/zruseni platby - verifikace podpisu. * * @param float $returnedPaymentSessionId - paymentSessionId vracene v redirectu * @param string $returnedEncryptedSignature - kontrolni podpis vraceny v redirectu * @param float $paymentResult - vysledek volani * @param float $paymentSessionId - identifikator platby na GoPay * @param string $secureKey - kryptovaci klic prideleny eshopu / uzivateli, urceny k podepisovani komunikace * * @throws Exception */ public static function checkPaymentResult($returnedPaymentSessionId, $returnedEncryptedSignature, $paymentResult, $paymentSessionId, $secureKey) { if ($returnedPaymentSessionId != $paymentSessionId) { throw new Exception("PaymentResult invalid PSID"); } $hashedSignature = GopayHelper::hash(GopayHelper::concatPaymentResult((double) $paymentSessionId, $paymentResult, $secureKey)); $decryptedHash = GopayHelper::decrypt($returnedEncryptedSignature, $secureKey); if ($decryptedHash != $hashedSignature) { throw new Exception("PaymentResult invalid signature"); } }
/** * Zruseni opakovani plateb * * @param float $paymentSessionId - identifikator platby * @param float $targetGoId - identifikator prijemnce - GoId * @param string $secureKey - kryptovaci klic prideleny GoPay * @throws \Exception */ public function voidRecurrentPayment($paymentSessionId, $targetGoId, $secureKey) { try { //inicializace WS $go_client = self::createSoapClient(); $hash = GopayHelper::hash(GopayHelper::concatPaymentSession((double) $targetGoId, (double) $paymentSessionId, $secureKey)); $sessionEncryptedSignature = GopayHelper::encrypt($hash, $secureKey); $paymentSession = array("targetGoId" => (double) $targetGoId, "paymentSessionId" => (double) $paymentSessionId, "encryptedSignature" => $sessionEncryptedSignature); $paymentResult = $go_client->__call('voidRecurrentPayment', array('sessionInfo' => $paymentSession)); $returnHash = GopayHelper::decrypt($paymentResult->encryptedSignature, $secureKey); if ($hash != $returnHash) { throw new Exception("Encrypted signature differ"); } if ($paymentResult->result == GopayHelper::CALL_RESULT_FAILED) { throw new Exception("void recurrency failed [" . $paymentResult->resultDescription . "]"); } else { if ($paymentResult->result == GopayHelper::CALL_RESULT_ACCEPTED) { //zruseni opakovani platby bylo zarazeno ke zpracovani throw new Exception(GopayHelper::CALL_RESULT_ACCEPTED); } } } catch (SoapFault $f) { /* * Chyba v komunikaci s GoPay serverem */ throw new Exception("SOAP error"); } }