Пример #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
        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;
        }