예제 #1
0
        public string GetPostData(string authenticationId, string sessionId, Address contactAddress)
        {
            ISessionService sessionService = new SessionService();

            var sessionDataResponse = sessionService.GetSessionData(authenticationId, sessionId);
            if (sessionDataResponse == null || string.IsNullOrEmpty(sessionDataResponse.ErrorMessage) == false || sessionDataResponse.SessionData == null)
                return string.Empty;

            var loginService = new LoginService();
            GetAccountResponse getAccountResponse = loginService.GetAccount(sessionId, authenticationId);
            if (getAccountResponse == null || getAccountResponse.UserAccount == null)
                return string.Empty;

            var userAccount = getAccountResponse.UserAccount;

            using (new ApplicationContextScope(new ApplicationContext()))
            {
                ApplicationContext.Current.Items["SessionId"] = sessionId;
                try
                {
                    var channelFactory =
                        new WebChannelFactory<IPaymentServiceRest>(Configuration.PaymentServiceConfigurationName);
                    IPaymentServiceRest channel = channelFactory.CreateChannel();

                    if (channel is IContextChannel)
                        using (new OperationContextScope(channel as IContextChannel))
                        {
                            var referenceNumber = Guid.NewGuid().ToString().Substring(10);
                            var voucherCode = string.Empty;
                            if (sessionDataResponse.SessionData.PaymentTransaction != null)
                            {
                                referenceNumber =
                                    sessionDataResponse.SessionData.PaymentTransaction.InternalReferenceNumber;
                            }
                            voucherCode = sessionDataResponse.SessionData.VoucherCode;

                            WebOperationContext.Current.OutgoingRequest.Headers.Add("X-MethodName", "GetPostData");
                            return channel.GetPostData(referenceNumber,
                                                       sessionDataResponse.SessionData.ToPayAmount.ToString(),
                                                       "Air", sessionId, userAccount, contactAddress, voucherCode);
                        }
                }
                catch (Exception exception)
                {
                    Logger.LogException(exception, Source, "GetPostData", Severity.Critical);
                }
            }
            return null;
        }
예제 #2
0
 private static bool SetOfflineParametersInSession(string sessionId, string authenticationId, Token token, string voucherCode)
 {
     ISessionService sessionService = new SessionService();
     var sessionDataResponse = sessionService.GetSessionData(authenticationId, sessionId);
     if (sessionDataResponse != null && string.IsNullOrEmpty(sessionDataResponse.ErrorMessage) && sessionDataResponse.SessionData != null)
     {
         var paymentService = new PaymentService();
         var voucherRedemptionAmount = paymentService.GetVoucherAmount(sessionId, voucherCode);
         var amount = token.PayableAmount - voucherRedemptionAmount;
         sessionDataResponse.SessionData.ToPayAmount = amount;
         sessionDataResponse.SessionData.PaymentTransaction = new PaymentTransaction(token.PaymentReferenceNumber);
         sessionDataResponse.SessionData.Token = token;
         sessionDataResponse.SessionData.VoucherCode = voucherCode;
         sessionService.UpdateSessionData(sessionId, sessionDataResponse.SessionData);
         return true;
     }
     return false;
 }
예제 #3
0
 protected void Page_Load(object sender, EventArgs e)
 {
     try
     {
         var clientCookie = new RequestCookieManager(Request.Cookies);
         string oldSessionId = clientCookie.GetSessionId();
         var service = new SessionService();
         string newSessionId = service.CreateSession(oldSessionId);
         if (!string.Equals(newSessionId, oldSessionId)) // if its new session then reset cookie.
         {
             var session = new Session { SessionId = newSessionId };
             var cookieManager = new ResponseCookieManager(Response.Cookies);
             cookieManager.SetSessionData(session);
         }
     }
     catch (Exception ex)
     {
         Logger.LogException(ex, "MasterPage", "Page_Load", Severity.Critical);
     }
 }
예제 #4
0
        public bool ValidateResponse(string response, string provider, string authenticationId,
            string sessionId, NameValueCollection variables, string voucherCode, out string errorMessage)
        {
            var nameValueCollection = new List<KeyValue>();

            foreach (var variable in variables.AllKeys)
            {
                nameValueCollection.Add(new KeyValue { Key = variable, Value = variables[variable] });
            }
            var sessionService = new SessionService();
            var sessionDataResponse = sessionService.GetSessionData(authenticationId, sessionId);
            if (sessionDataResponse == null)
            {
                errorMessage = "No session found. Aborting.";
                return false;
            }

            var loginService = new LoginService();
            GetAccountResponse getAccountResponse = loginService.GetAccount(sessionId, authenticationId);
            if (getAccountResponse == null || getAccountResponse.UserAccount == null)
            {
                errorMessage = "Authentication failed. Aborting.";
                return false;
            }

            using (new ApplicationContextScope(new ApplicationContext()))
            {
                ApplicationContext.Current.Items["SessionId"] = sessionId;
                try
                {
                    var channelFactory =
                        new WebChannelFactory<IPaymentServiceRest>(Configuration.PaymentServiceConfigurationName);
                    IPaymentServiceRest channel = channelFactory.CreateChannel();

                    if (channel is IContextChannel)
                        using (new OperationContextScope(channel as IContextChannel))
                        {
                            WebOperationContext.Current.OutgoingRequest.Headers.Add("X-MethodName", "ValidateResponse");
                            var paymentResponse = channel.ValidatePaymentResponse(sessionDataResponse.SessionData.ToPayAmount.ToString(),
                                provider, sessionId, nameValueCollection, getAccountResponse.UserAccount, authenticationId, voucherCode);
                            errorMessage = paymentResponse.ErrorMessage;
                            if (paymentResponse.IsSuccess)
                            {
                                sessionDataResponse.SessionData.Charges = sessionDataResponse.SessionData.Charges ?? new List<Charge>();
                                sessionDataResponse.SessionData.Charges.Add(paymentResponse.Charge);

                                sessionService.UpdateSessionData(sessionId, sessionDataResponse.SessionData);
                            }
                            return paymentResponse.IsSuccess;
                        }
                }
                catch (Exception exception)
                {
                    Logger.LogException(exception, Source, "ValidateResponse", Severity.Critical);
                }
            }
            errorMessage = "Invalid Request. Aborting.";
            return false;
        }