Esempio n. 1
0
        /// <summary>
        /// Kontrola parametru predavanych ve zpetnem volani po potvrzeni/zruseni platby
        ///
        /// - verifikace podpisu
        /// - pokud nesouhlasi udaje, tak se vyvola GopayException
        /// </summary>
        /// <param name="returnedPaymentSessionId">paymentSessionId vracene v redirectu</param>
        /// <param name="returnedEncryptedSignature">id puvodni platby pri opakovane platbe</param>
        /// <param name="paymentResult">vysledek volani</param>
        /// <param name="paymentSessionId">identifikator platby na GoPay</param>
        /// <param name="secureKey">kryptovaci klic prideleny eshopu / uzivateli, urceny k podepisovani komunikace</param>
        ///
        /// <returns>true</returns>
        public static bool CheckPaymentResult(
            long returnedPaymentSessionId,
            string returnedEncryptedSignature,
            string paymentResult,
            long paymentSessionId,
            string secureKey)
        {
            if (returnedPaymentSessionId != paymentSessionId)
            {
                throw new GopayException(GopayException.Reason.INVALID_PAYMENT_SESSION_ID);
            }

            string hashedSignature = GopayHelper.Hash(
                GopayHelper.ConcatPaymentResult(
                    (long)paymentSessionId,
                    paymentResult,
                    secureKey)
                );

            string decryptedHash = GopayHelper.Decrypt(returnedEncryptedSignature, secureKey);

            if (hashedSignature != decryptedHash)
            {
                throw new GopayException(GopayException.Reason.INVALID_STATUS_SIGNATURE);
            }

            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Zruseni opakovani plateb
        /// </summary>
        ///
        /// <param name="paymentSessionId">identifikator platby </param>
        /// <param name="targetGoId">identifikator prijemnce - GoId</param>
        /// <param name="secureKey">kryptovaci klic prideleny GoPay</param>
        public static void VoidRecurrentPayment(
            long paymentSessionId,
            long targetGoId,
            string secureKey
            )
        {
            try
            {
                // Inicializace providera pro WS
                AxisEPaymentProviderV2Service provider = new AxisEPaymentProviderV2Service(GopayConfig.Ws);
                EPaymentResult paymentResult;

                // Sestaveni dotazu na stav platby
                string hash = GopayHelper.Hash(
                    GopayHelper.ConcatPaymentSession(
                        targetGoId,
                        paymentSessionId,
                        secureKey)
                    );

                string sessionEncryptedSignature = GopayHelper.Encrypt(hash, secureKey);

                EPaymentSessionInfo paymentSessionInfo = new EPaymentSessionInfo();
                paymentSessionInfo.targetGoId         = targetGoId;
                paymentSessionInfo.paymentSessionId   = paymentSessionId;
                paymentSessionInfo.encryptedSignature = sessionEncryptedSignature;

                paymentResult = provider.voidRecurrentPayment(paymentSessionInfo);

                string returnHash = GopayHelper.Decrypt(paymentResult.encryptedSignature, secureKey);

                if (hash != returnHash)
                {
                    throw new GopayException("Encrypted signature differ");
                }

                if (paymentResult.result == GopayHelper.CALL_RESULT_FAILED)
                {
                    throw new GopayException("autorization not voided [" + paymentResult.resultDescription + "]");
                }
                else if (paymentResult.result == GopayHelper.CALL_RESULT_ACCEPTED)
                {
                    //zruseni opakovani platby bylo zarazeno ke zpracovani
                    //po urcite dobe je nutne dotazat zruseni se shodnymi parametry zda je j*z $paymentResult->result == GopayHelper::CALL_RESULT_FINISHED
                }
                else if (paymentResult.result == GopayHelper.CALL_RESULT_FINISHED)
                {
                    //opakovani platby bylo zruseno
                    //oznacte platbu
                }
            }
            catch (Exception ex)
            {
                //
                // Chyba pri komunikaci s WS
                //
                throw new GopayException(ex.ToString());
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Kontrola parametru predavanych ve zpetnem volani po potvrzeni/zruseni platby
        ///
        /// - verifikace podpisu
        /// - pokud nesouhlasi udaje, tak se vyvola GopayException
        /// </summary>
        ///
        /// <param name="returnedGoId">goId vracene v redirectu</param>
        /// <param name="returnedPaymentSessionId">paymentSessionId vracene v redirectu</param>
        /// <param name="returnedParentPaymentSessionId">id puvodni platby pri opakovane platbe</param>
        /// <param name="returnedOrderNumber">identifikace objednavky vracena v redirectu - identifikator platby na eshopu</param>
        /// <param name="returnedEncryptedSignature">kontrolni podpis vraceny v redirectu</param>
        /// <param name="targetGoId">identifikace prijemce - GoId pridelene GoPay</param>
        /// <param name="OrderNumber">identifikace akt. objednavky</param>
        /// <param name="secureKey">kryptovaci klic prideleny eshopu / uzivateli, urceny k podepisovani komunikace</param>
        ///
        /// <returns>True</returns>
        public static bool CheckPaymentIdentity(
            long returnedGoId,
            long returnedPaymentSessionId,
            System.Nullable <long> returnedParentPaymentSessionId,
            string returnedOrderNumber,
            string returnedEncryptedSignature,
            long targetGoId,
            string orderNumber,
            string secureKey)
        {
            if (returnedOrderNumber != orderNumber)
            {
                throw new GopayException(GopayException.Reason.INVALID_ON);
            }

            if (returnedGoId != targetGoId)
            {
                throw new GopayException(GopayException.Reason.INVALID_GOID);
            }

            string hashedSignature = GopayHelper.Hash(
                GopayHelper.ConcatPaymentIdentity(
                    returnedGoId,
                    returnedPaymentSessionId,
                    returnedParentPaymentSessionId,
                    returnedOrderNumber,
                    secureKey)
                );

            string decryptedHash = GopayHelper.Decrypt(returnedEncryptedSignature, secureKey).TrimEnd('\0');

            if (decryptedHash != hashedSignature)
            {
                throw new GopayException(GopayException.Reason.INVALID_SIGNATURE);
            }

            return(true);
        }
Esempio n. 4
0
        /// <summary>
        /// Kontrola stavu platby proti internim udajum objednavky
        ///
        /// - verifikace podpisu
        /// - pokud nesouhlasi udaje, tak se vyvola GopayException
        /// </summary>
        ///
        /// <param name="paymentStatus">vysledek volani paymentStatus</param>
        /// <param name="sessionState">ocekavany stav paymentSession (WAITING, PAYMENT_DONE)</param>
        /// <param name="gopayId">identifikator prijemce prideleny GoPay</param>
        /// <param name="OrderNumber">identifikace akt. objednavky u prijemce</param>
        /// <param name="totalPriceInCents">cena objednavky v halerich</param>
        /// <param name="currency">identifikator meny platby</param>
        /// <param name="productName">nazev objednavky / zbozi</param>
        /// <param name="secureKey">kryptovaci klic prideleny prijemci, urceny k podepisovani komunikace</param>
        ///
        /// <returns>True</returns>
        public static bool CheckPaymentStatus(
            EPaymentStatus paymentStatus,
            String sessionState,
            long gopayId,
            string orderNumber,
            long totalPriceInCents,
            string currency,
            string productName,
            string secureKey)
        {
            if (paymentStatus != null)
            {
                if (paymentStatus.result != GopayHelper.CALL_COMPLETED)
                {
                    throw new GopayException(GopayException.Reason.INVALID_CALL_STATE_STATE);
                }

                if (paymentStatus.sessionState != sessionState)
                {
                    throw new GopayException(GopayException.Reason.INVALID_SESSION_STATE);
                }

                if (paymentStatus.orderNumber != orderNumber)
                {
                    throw new GopayException(GopayException.Reason.INVALID_ON);
                }

                if (paymentStatus.productName != productName)
                {
                    throw new GopayException(GopayException.Reason.INVALID_PN);
                }

                if (paymentStatus.targetGoId != gopayId)
                {
                    throw new GopayException(GopayException.Reason.INVALID_GOID);
                }

                if (paymentStatus.totalPrice != totalPriceInCents)
                {
                    throw new GopayException(GopayException.Reason.INVALID_PRICE);
                }

                if (paymentStatus.currency != currency)
                {
                    throw new GopayException(GopayException.Reason.INVALID_CURRENCY);
                }
            }
            else
            {
                throw new GopayException(GopayException.Reason.NO_PAYMENT_STATUS);
            }

            /*
             * Kontrola podpisu objednavky
             */
            string hashedSignature = GopayHelper.Hash(
                GopayHelper.ConcatPaymentStatus(
                    (long)paymentStatus.targetGoId,
                    paymentStatus.productName,
                    (long)paymentStatus.totalPrice,
                    paymentStatus.currency,
                    paymentStatus.orderNumber,
                    paymentStatus.recurrentPayment,
                    paymentStatus.parentPaymentSessionId,
                    paymentStatus.preAuthorization,
                    paymentStatus.result,
                    paymentStatus.sessionState,
                    paymentStatus.sessionSubState,
                    paymentStatus.paymentChannel,
                    secureKey));

            string decryptedHash = GopayHelper.Decrypt(paymentStatus.encryptedSignature, secureKey);

            if (hashedSignature != decryptedHash)
            {
                throw new GopayException(GopayException.Reason.INVALID_STATUS_SIGNATURE);
            }

            return(true);
        }