コード例 #1
0
        public static PaymentGatewayResponse Create(bool logTheResponse)
        {
            PaymentGatewayResponse response = null;

            if (HLConfigManager.Configurations.PaymentsConfiguration.HasPaymentGateway)
            {
                var handlers = GetPaymentGatewayResponseList();

                foreach (PaymentGatewayResponse handler in handlers)
                {
                    if (handler.CanProcess)
                    {
                        response = handler;
                        response.CanSubmitIfApproved = response.DetermineSubmitStatus();
                        if (handler.LogResponses(logTheResponse))
                        {
                            if (string.IsNullOrEmpty(response.errorMessage))
                            {
                                if (response.AuthResultMissing)
                                {
                                    response.errorMessage = string.Format(NoAuthResultInResponse, response.GatewayName);
                                }
                            }
                            if (string.IsNullOrEmpty(response.OrderNumber))
                            {
                                response.errorMessage = string.Format(NoOrderNumberInResponse, response.GatewayName);
                            }
                            string message = (!string.IsNullOrEmpty(response.errorMessage)) ? string.Format(ResponseHadError, response.errorMessage) : string.Empty;
                            if (!string.IsNullOrEmpty(response.errorMessage))
                            {
                                PaymentGatewayInvoker.LogBlindError(message);
                            }
                            else
                            {
                                var statusType = PaymentGatewayRecordStatusType.Unknown;
                                if (response.IsReturning)
                                {
                                    statusType = response.Status;
                                    if (statusType != PaymentGatewayRecordStatusType.OrderSubmitted)
                                    {
                                        statusType = (response.IsApproved) ? PaymentGatewayRecordStatusType.Approved : PaymentGatewayRecordStatusType.Declined;
                                        statusType = (response.IsPendingTransaction) ? PaymentGatewayRecordStatusType.ApprovalPending : statusType;
                                        statusType = (response.IsCancelled) ? PaymentGatewayRecordStatusType.CancelledByUser : statusType;
                                    }
                                }
                                else
                                {
                                    statusType = (response.IsApproved) ? PaymentGatewayRecordStatusType.Approved : PaymentGatewayRecordStatusType.Declined;
                                    statusType = (response.IsPendingTransaction) ? PaymentGatewayRecordStatusType.ApprovalPending : statusType;
                                    statusType = (response.IsCancelled) ? PaymentGatewayRecordStatusType.CancelledByUser : statusType;
                                    statusType = (response.Status == PaymentGatewayRecordStatusType.OrderSubmitted) ? response.Status : statusType;
                                }
                                PaymentGatewayInvoker.LogMessageWithInfo(PaymentGatewayLogEntryType.Response, response.OrderNumber, string.Empty, response.GetType().Name.Replace("Response", string.Empty), statusType, response.WebResponse);
                            }
                        }
                    }
                }
            }

            return(response);
        }