Exemplo n.º 1
0
        /// <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());
            }
        }
Exemplo n.º 2
0
        /// <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);
        }