/// <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);
        }
        /// <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());
            }
        }
        /// <summary>
        /// Castecne zruseni platby
        /// </summary>
        ///
        /// <param name="paymentSessionId">identifikator platby</param>
        /// <param name="targetGoId">identifikator prijemnce - GoId</param>
        /// <param name="secureKey">kryptovaci klic prideleny GoPay</param>
        ///
        /// <returns>result</returns>
        public static string RefundPaymentPartially(
            long paymentSessionId,
            long amount,
            String currency,
            String description,
            long targetGoId,
            string secureKey)
        {
            try
            {
                // Inicializace providera pro WS
                AxisEPaymentProviderV2Service provider = new AxisEPaymentProviderV2Service(GopayConfig.Ws);
                EPaymentResult paymentResult;

                string encryptedSignature = GopayHelper.Encrypt(
                    GopayHelper.Hash(
                        GopayHelper.ConcatRefundRequest(
                            targetGoId,
                            paymentSessionId,
                            amount,
                            currency,
                            description,
                            secureKey)
                        ), secureKey);

                ERefundRequest eRefundRequest = new ERefundRequest();
                eRefundRequest.targetGoId         = targetGoId;
                eRefundRequest.paymentSessionId   = paymentSessionId;
                eRefundRequest.amount             = amount;
                eRefundRequest.currency           = currency;
                eRefundRequest.description        = description;
                eRefundRequest.encryptedSignature = encryptedSignature;

                paymentResult = provider.refundPayment(eRefundRequest);

                if (paymentResult.result == GopayHelper.CALL_RESULT_FAILED)
                {
                    throw new GopayException("payment not refunded [" + paymentResult.resultDescription + "]");
                }

                return(paymentResult.result);
            }
            catch (Exception ex)
            {
                //
                // Chyba pri komunikaci s WS
                //
                throw new GopayException(ex.ToString());
            }
        }
        /// <summary>
        /// Zruseni predautorizovani 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 VoidAuthorization(
            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 sessionEncryptedSignature = GopayHelper.Encrypt(
                    GopayHelper.Hash(
                        GopayHelper.ConcatPaymentSession(
                            targetGoId,
                            paymentSessionId,
                            secureKey)),
                    secureKey);

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

                paymentResult = provider.voidAuthorization(paymentSessionInfo);

                if (paymentResult.result == GopayHelper.CALL_RESULT_FAILED)
                {
                    throw new GopayException("autorization not voided [" + paymentResult.resultDescription + "]");
                }

                //Overeni podpisu
                GopayHelper.CheckPaymentResult(
                    (long)paymentResult.paymentSessionId,
                    paymentResult.encryptedSignature,
                    paymentResult.result,
                    paymentSessionId,
                    secureKey);
            }
            catch (Exception ex)
            {
                //
                // Chyba pri komunikaci s WS
                //
                throw new GopayException(ex.ToString());
            }
        }
        /// <summary>
        /// Zruseni platby
        /// </summary>
        ///
        /// <param name="paymentSessionId">identifikator platby</param>
        /// <param name="targetGoId">identifikator prijemnce - GoId</param>
        /// <param name="secureKey">kryptovaci klic prideleny GoPay</param>
        ///
        /// <returns>result/returns>
        public static string RefundPayment(
            long paymentSessionId,
            long targetGoId,
            string secureKey)
        {
            try
            {
                // Inicializace providera pro WS
                AxisEPaymentProviderV2Service provider = new AxisEPaymentProviderV2Service(GopayConfig.Ws);
                EPaymentResult paymentResult;

                string encryptedSignature = GopayHelper.Encrypt(
                    GopayHelper.Hash(
                        GopayHelper.ConcatPaymentSession(
                            targetGoId,
                            paymentSessionId,
                            secureKey)
                        ), secureKey);

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

                paymentResult = provider.refundPayment(paymentSessionInfo);

                if (paymentResult.result == GopayHelper.CALL_RESULT_FAILED)
                {
                    throw new GopayException("payment not refunded [" + paymentResult.resultDescription + "]");
                }

                return(paymentResult.result);
            }
            catch (Exception ex)
            {
                //
                // Chyba pri komunikaci s WS
                //
                throw new GopayException(ex.ToString());
            }
        }
        /// <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);
        }
        /// <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);
        }
        /// <summary>
        /// Založení opakovane platby
        /// </summary>
        ///
        /// <param name="parentPaymentSessionId">identifikator rodicovske platby</param>
        /// <param name="recurrentPaymentOrderNumber">identifikator objednavky</param>
        /// <param name="recurrentPaymentTotalPriceInCents">celkova cena v halerich</param>
        /// <param name="recurrentPaymentCurrency">mena, ve ktere platba probiha</param>
        /// <param name="recurrentPaymentProductName">popis objednavky zobrazujici se na platebni brane</param>
        /// <param name="targetGoId">identifikator prijemnce - GoId</param>
        /// <param name="secureKey">kryptovaci klic prideleny GoPay</param>
        ///
        /// <returns>paymentSessionId</returns>
        public static long PerformRecurrence(
            long parentPaymentSessionId,
            string recurrentPaymentOrderNumber,
            long recurrentPaymentTotalPriceInCents,
            string recurrentPaymentCurrency,
            string recurrentPaymentProductName,
            long targetGoId,
            string secureKey)
        {
            try
            {
                // Inicializace providera pro WS
                AxisEPaymentProviderV2Service provider = new AxisEPaymentProviderV2Service(GopayConfig.Ws);
                EPaymentStatus paymentStatus;

                string encryptedSignature = GopayHelper.Encrypt(
                    GopayHelper.Hash(
                        GopayHelper.ConcatRecurrenceRequest(
                            parentPaymentSessionId,
                            recurrentPaymentOrderNumber,
                            recurrentPaymentTotalPriceInCents,
                            targetGoId,
                            secureKey)
                        ), secureKey);

                ERecurrenceRequest recurrenceRequest = new ERecurrenceRequest();
                recurrenceRequest.parentPaymentSessionId = parentPaymentSessionId;
                recurrenceRequest.orderNumber            = recurrentPaymentOrderNumber;
                recurrenceRequest.totalPrice             = recurrentPaymentTotalPriceInCents;
                recurrenceRequest.targetGoId             = targetGoId;
                recurrenceRequest.encryptedSignature     = encryptedSignature;

                paymentStatus = provider.createRecurrentPayment(recurrenceRequest);

                if (paymentStatus.result == GopayHelper.CALL_COMPLETED)
                {
                    GopayHelper.CheckPaymentStatus(
                        paymentStatus,
                        GopayHelper.SessionState.CREATED.ToString(),
                        targetGoId,
                        recurrentPaymentOrderNumber,
                        recurrentPaymentTotalPriceInCents,
                        recurrentPaymentCurrency,
                        recurrentPaymentProductName,
                        secureKey);

                    return((long)paymentStatus.paymentSessionId);
                }
                else
                {
                    throw new GopayException("Bad payment status");
                }
            }
            catch (Exception ex)
            {
                //
                // Chyba pri komunikaci s WS
                //
                throw new GopayException(ex.ToString());
            }
        }
        /// <summary>
        /// Kontrola stavu platby eshopu
        /// - verifikace parametru z redirectu
        /// - kontrola stavu platby
        /// - pokud nesouhlasi udaje vyhazuje GopayException
        /// - pri chybe komunikace s WS vyhazuje GopayException
        /// </summary>
        ///
        /// <param name="paymentSessionId">identifikator platby </param>
        /// <param name="targetGoId">identifikator prijemnce - GoId</param>
        /// <param name="orderNumber">identifikace akt. objednavky</param>
        /// <param name="totalPriceInCents">celkova cena v halerich</param>
        /// <param name="currency">mena, ve ktere platba probiha</param>
        /// <param name="productName">popis objednavky zobrazujici se na platebni brane</param>
        /// <param name="secureKey">kryptovaci klic pridelene GoPay</param>
        ///
        /// <returns>callbackResult</returns>
        /// callbackResult.sessionState   - stav platby
        /// callbackResult.sessionSubState - detailnejsi popis stavu platby
        public static CallbackResult IsPaymentDone(
            long paymentSessionId,
            long targetGoId,
            string orderNumber,
            long totalPriceInCents,
            string currency,
            string productName,
            string secureKey)
        {
            // Inicializace providera pro WS
            AxisEPaymentProviderV2Service provider = new AxisEPaymentProviderV2Service(GopayConfig.Ws);
            EPaymentStatus status;

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

            EPaymentSessionInfo paymentSessionInfo = new EPaymentSessionInfo();

            paymentSessionInfo.targetGoId         = targetGoId;
            paymentSessionInfo.paymentSessionId   = paymentSessionId;
            paymentSessionInfo.encryptedSignature = sessionEncryptedSignature;

            CallbackResult callbackResult = new CallbackResult();

            try
            {
                /*
                 * Kontrola stavu platby na strane GoPay prostrednictvim WS
                 */
                status = provider.paymentStatus(paymentSessionInfo);

                callbackResult.sessionState    = status.sessionState;
                callbackResult.sessionSubState = status.sessionSubState;

                /*
                 * Kontrola zaplacenosti objednavky, verifikace parametru objednavky
                 */
                if (status.result != GopayHelper.CALL_COMPLETED)
                {
                    throw new GopayException("Payment Status Call failed: " + status.resultDescription);
                }

                if (callbackResult.sessionState != GopayHelper.SessionState.PAYMENT_METHOD_CHOSEN.ToString() &&
                    callbackResult.sessionState != GopayHelper.SessionState.CREATED.ToString() &&
                    callbackResult.sessionState != GopayHelper.SessionState.PAID.ToString() &&
                    callbackResult.sessionState != GopayHelper.SessionState.AUTHORIZED.ToString() &&
                    callbackResult.sessionState != GopayHelper.SessionState.CANCELED.ToString() &&
                    callbackResult.sessionState != GopayHelper.SessionState.TIMEOUTED.ToString() &&
                    callbackResult.sessionState != GopayHelper.SessionState.REFUNDED.ToString()
                    )
                {
                    throw new GopayException("Bad Payment Session State: " + callbackResult.sessionState);
                }

                GopayHelper.CheckPaymentStatus(
                    status,
                    callbackResult.sessionState,
                    targetGoId,
                    orderNumber,
                    totalPriceInCents,
                    currency,
                    productName,
                    secureKey);

                return(callbackResult);
            }
            catch (Exception ex1)
            {
                callbackResult.sessionState = GopayHelper.SessionState.FAILED.ToString();
            }
            finally
            {
                provider.Dispose();
            }

            return(callbackResult);
        }
        /// <summary>
        /// Vytvoreni platby pomoci WS z eshopu
        ///
        /// - pri chybe komunikace s WS vyhozeni GopayException
        /// - pokud nesouhlasi udaje pri kontrole platby vyhozeni GopayException
        /// </summary>
        ///
        /// <param name="targetGoId">identifikator prijemce - GoId</param>
        /// <param name="productName">popis objednavky zobrazujici se na platebni brane</param>
        /// <param name="totalPriceInCents">celkova cena objednavky v halerich</param>
        /// <param name="currency">mena, ve ktere platba probiha</param>
        /// <param name="orderNumber">identifikator objednavky</param>
        /// <param name="successUrl">URL stranky, kam je zakaznik presmerovan po uspesnem zaplaceni</param>
        /// <param name="failedUrl">URL stranky, kam je zakaznik presmerovan po zruseni platby / neuspesnem zaplaceni</param>
        /// <param name="preAuthorization">jedna-li se o predautorizovanou platbu</param>
        /// <param name="recurrentPayment">jedna-li se o opakovanou platbu</param>
        /// <param name="recurrenceDateTo">datum, do nehoz budou provadeny opakovane platby. Jedna se textovy retezec ve formatu yyyy-MM-dd.</param>
        /// <param name="recurrenceCycle">zakladni casovou jednotku opakovani. Nabyva hodnot [DAY, WEEK, MONTH], pro opakování od CS a.s. lze pouzit pouze hodnotu DAY.</param>
        /// <param name="recurrencePeriod">definuje periodu opakovane platby. Napr. při konfiguraci DAY,5 bude platba provadena kazdy 5. den</param>
        /// <param name="paymentChannels">pole platebnich kanalu, ktere se zobrazi na platebni brane</param>
        /// <param name="defaultPaymentChannel">platebni kanal, ktery se zobrazi (predvybere) na platebni brane po presmerovani</param>
        /// <param name="secureKey">kryptovaci klic prideleny prijemci</param>
        ///
        /// Informace o zakaznikovi
        /// <param name="firstName">Jmeno</param>
        /// <param name="lastName">Prijmeno</param>
        ///
        /// Adresa
        /// <param name="city">Mesto</param>
        /// <param name="street">Ulice</param>
        /// <param name="postalCode">PSC</param>
        /// <param name="countryCode">stat</param>
        /// <param name="email">Email</param>
        /// <param name="phoneNumber">Tel. cislo</param>
        ///
        /// <param name="p1 - p4">volitelne parametry (max. 128 znaku).</param>
        /// <param name="lang">jazyk plat. brany</param>
        /// Parametry jsou vraceny v nezmenene podobe jako soucast volani dotazu na stav platby $paymentStatus (viz metoda isPaymentDone)
        ///
        /// <returns>paymentSessionId</returns>
        public static long CreateBasePayment(
            long targetGoId,
            string productName,
            long totalPriceInCents,
            string currency,
            string orderNumber,
            string successURL,
            string failedURL,
            System.Nullable <bool> preAuthorization,
            System.Nullable <bool> recurrentPayment,
            string recurrenceDateTo,
            string recurrenceCycle,
            System.Nullable <int> recurrencePeriod,
            string[] paymentChannels,
            string defaultPaymentChannel,
            string secureKey,
            string firstName,
            string lastName,
            string city,
            string street,
            string postalCode,
            string countryCode,
            string email,
            string phoneNumber,
            string p1,
            string p2,
            string p3,
            string p4,
            string lang
            )
        {
            String paymentChannelsString = (null == paymentChannels) ? "" : String.Join(",", paymentChannels);

            // Sestaveni pozadavku pro podpis platby
            string encryptedSignature = GopayHelper.Encrypt(
                GopayHelper.Hash(
                    GopayHelper.ConcatPaymentCommand(
                        targetGoId,
                        productName,
                        totalPriceInCents,
                        currency,
                        orderNumber,
                        failedURL,
                        successURL,
                        preAuthorization,
                        recurrentPayment,
                        recurrenceDateTo,
                        recurrenceCycle,
                        recurrencePeriod,
                        paymentChannelsString,
                        secureKey)
                    ),
                secureKey);

            // Sestaveni pozadavku pro zalozeni platby

            ECustomerData customerData = new ECustomerData();

            customerData.firstName   = firstName;
            customerData.lastName    = lastName;
            customerData.city        = city;
            customerData.street      = street;
            customerData.postalCode  = postalCode;
            customerData.countryCode = countryCode;
            customerData.email       = email;
            customerData.phoneNumber = phoneNumber;

            if (!validateCustomerData(customerData))
            {
                throw new GopayException(GopayException.Reason.INVALID_COUNTRY_CODE);
            }

            EPaymentCommand customerPaymentCommand = new EPaymentCommand();

            customerPaymentCommand.targetGoId            = targetGoId;
            customerPaymentCommand.productName           = productName;
            customerPaymentCommand.totalPrice            = totalPriceInCents;
            customerPaymentCommand.currency              = currency;
            customerPaymentCommand.orderNumber           = orderNumber;
            customerPaymentCommand.failedURL             = failedURL;
            customerPaymentCommand.successURL            = successURL;
            customerPaymentCommand.preAuthorization      = preAuthorization;
            customerPaymentCommand.recurrentPayment      = recurrentPayment;
            customerPaymentCommand.recurrenceDateTo      = recurrenceDateTo;
            customerPaymentCommand.recurrenceCycle       = recurrenceCycle;
            customerPaymentCommand.recurrencePeriod      = recurrencePeriod;
            customerPaymentCommand.paymentChannels       = paymentChannelsString;
            customerPaymentCommand.defaultPaymentChannel = defaultPaymentChannel;
            customerPaymentCommand.encryptedSignature    = encryptedSignature;
            customerPaymentCommand.customerData          = customerData;
            customerPaymentCommand.p1   = p1;
            customerPaymentCommand.p2   = p2;
            customerPaymentCommand.p3   = p3;
            customerPaymentCommand.p4   = p4;
            customerPaymentCommand.lang = lang;

            EPaymentStatus paymentStatus;

            try
            {
                // Vytvorime providera pro komunikaci s WS
                AxisEPaymentProviderV2Service provider = new AxisEPaymentProviderV2Service(GopayConfig.Ws);

                /*
                 * Vytvareni platby na strane GoPay prostrednictvim providera
                 */
                paymentStatus = provider.createPayment(customerPaymentCommand);

                /*
                 * Kontrola stavu platby - musi byt ve stavu CREATED, kontrola parametru platby
                 */
                if (paymentStatus.result == GopayHelper.CALL_COMPLETED &&
                    paymentStatus.sessionState == GopayHelper.SessionState.CREATED.ToString() &&
                    paymentStatus.paymentSessionId > 0)
                {
                    return((long)paymentStatus.paymentSessionId);
                }
                else
                {
                    throw new GopayException("Create payment failed: " + paymentStatus.resultDescription);
                }
            }
            catch (Exception ex)
            {
                /*
                 * Chyba pri komunikaci s WS
                 */
                throw new GopayException(ex.ToString());
            }
        }