/** * Kontrola stavu platby proti internim udajum objednavky - verifikace podpisu. * * @param mixed $paymentStatus - vysledek volani paymentStatus * @param string $sessionState - ocekavany stav paymentSession (WAITING, PAYMENT_DONE) * @param float $goId - identifikator prijemce prideleny GoPay * @param string $orderNumber - identifikace akt. objednavky u prijemce * @param float $totalPriceInCents - cena objednavky v halerich * @param string $currency - identifikator meny platby * @param string $productName - nazev objednavky / zbozi * @param string $secureKey - kryptovaci klic prideleny prijemci, urceny k podepisovani komunikace * * @throws \Exception */ public static function checkPaymentStatus($paymentStatus, $sessionState, $goId, $orderNumber, $totalPriceInCents, $currency, $productName, $secureKey) { if (!empty($paymentStatus)) { if ($paymentStatus->result != GopayHelper::CALL_COMPLETED) { throw new \Exception("PS invalid call state state"); } if ($paymentStatus->sessionState != $sessionState) { throw new \Exception("PS invalid session state"); } if (trim($paymentStatus->orderNumber) != trim($orderNumber)) { throw new \Exception("PS invalid VS"); } if (trim($paymentStatus->productName) != trim($productName)) { throw new \Exception("PS invalid PN"); } if ($paymentStatus->targetGoId != $goId) { throw new \Exception("PS invalid GoID"); } if ($paymentStatus->totalPrice != $totalPriceInCents) { throw new \Exception("PS invalid price"); } if ($paymentStatus->currency != $currency) { throw new \Exception("PS invalid currency"); } } else { throw new \Exception("None payment status"); } /* * Kontrola podpisu objednavky */ $hashedSignature = GopayHelper::hash(GopayHelper::concatPaymentStatus($paymentStatus->targetGoId, $paymentStatus->productName, $paymentStatus->totalPrice, $paymentStatus->currency, $paymentStatus->orderNumber, $paymentStatus->recurrentPayment, $paymentStatus->parentPaymentSessionId, $paymentStatus->preAuthorization, $paymentStatus->result, $paymentStatus->sessionState, $paymentStatus->sessionSubState, $paymentStatus->paymentChannel, $secureKey)); $decryptedHash = GopayHelper::decrypt($paymentStatus->encryptedSignature, $secureKey); if ($decryptedHash != $hashedSignature) { throw new \Exception("PS invalid signature"); } }
/** * Kontrola stavu platby proti internim udajum objednavky uzivatele - verifikace podpisu * * @param mixed $payment_status - vysledek volani paymentStatus * @param string $session_state - ocekavany stav paymentSession (WAITING, PAYMENT_DONE) * @param float $buyerGoId - identifikace uzivatele - GoId uzivatele pridelene GoPay * @param string $variableSymbol - identifikace akt. objednavky * @param float $totalPriceInCents - cena objednavky v halerich * @param string $productName - nazev objednavky / zbozi * @param string $secret - kryptovaci heslo pridelene uzivateli, urcene k podepisovani komunikace * * @return true * @return false */ public static function checkBuyerPaymentStatus($payment_status, $session_state, $buyerGoId, $variableSymbol, $totalPriceInCents, $productName, $secret) { $valid = true; /* * Kontrola parametru objednavky */ $valid = GopayHelper::checkPaymentResultCommon($payment_status, $session_state, $buyerGoId, null, $variableSymbol, $totalPriceInCents, $productName, $secret); if ($valid) { /* * Kontrola parametru objednavky */ $hashedSignature = GopayHelper::hash(GopayHelper::concatPaymentStatus($payment_status->buyerGoId, $payment_status->productName, $payment_status->totalPrice, $payment_status->variableSymbol, $payment_status->result, $payment_status->sessionState, $payment_status->paymentChannel, $secret)); $decryptedHash = GopayHelper::decrypt($payment_status->encryptedSignature, $secret); if ($decryptedHash != $hashedSignature) { $valid = false; // echo "PS invalid signature <br>"; } } return $valid; }