Exemplo n.º 1
0
        public HttpResponseMessage OnAuthorization()
        {
            AmexAuthRequest  request  = ParseRequest();
            AmexAuthResponse response = new AmexAuthResponse();
            CommerceContext  context  = CommerceContext.BuildSynchronousContext("Amex payment authorization request", request, response);

            context.Log.Verbose("Amex payment authorization payload : \r\n\"{0}\".", Request.Content.ReadAsStringAsync().Result);

            if (IsAuthorized(context))
            {
                Stopwatch      callTimer      = Stopwatch.StartNew();
                HttpStatusCode httpStatusCode = ProcessAmexAuthCall(context, callTimer, () =>
                {
                    AmexAuthorizationExecutor amexAuthorizationExecutor = new AmexAuthorizationExecutor(context);
                    return(amexAuthorizationExecutor.Execute());
                });

                if (httpStatusCode != HttpStatusCode.OK)
                {
                    response.ResponseCode = AmexAuthResponseCode.AmexAuthInternalError;
                    context.Log.Warning("Amex payment authorization processing error. Request : {0} ", request.ToString());
                }

                HttpResponseMessage message = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new ObjectContent <AmexAuthResponse>(response, new XmlMediaTypeFormatter())
                };

                return(message);
            }

            return(new HttpResponseMessage(HttpStatusCode.Unauthorized));
        }
        /// <summary>
        /// Redeems the deal specified in the request.
        /// </summary>
        /// <param name="request">
        /// The deal redemption request.
        /// </param>
        /// <returns>
        /// A deal redemption response.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// Parameter request cannot be null.
        /// </exception>
        public pubRedemptionResponse1 pubRedemption(pubRedemptionRequest1 request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request", "Parameter request cannot be null.");
            }

            Stopwatch callTimer = Stopwatch.StartNew();

            pubRedemptionResponse1 result = new pubRedemptionResponse1(new pubRedemptionResponse
            {
                reqID = request.pubRedemptionRequest.reqID
            });

            // Build a context object to pass down the pipeline.
            CommerceContext context = CommerceContext.BuildSynchronousContext("First Data Redeem deal",
                                                                              request.pubRedemptionRequest,
                                                                              result.pubRedemptionResponse);

            // Process the call.
            HttpStatusCode httpStatusCode = ProcessFirstDataCall(context, callTimer, () =>
            {
                FirstDataRedeemDealExecutor firstDataRedeemDealExecutor = new FirstDataRedeemDealExecutor(context);
                return(firstDataRedeemDealExecutor.Execute());
            });

            // Throw exception if the operation did not succeed.
            if (httpStatusCode != HttpStatusCode.OK)
            {
                throw new WebFaultException <pubRedemptionResponse1>(result, httpStatusCode);
            }

            return(result);
        }
        /// <summary>
        /// Reverses a previous deal redemption.
        /// </summary>
        /// <param name="request">
        /// The deal redemption reversal request.
        /// </param>
        /// <returns>
        /// A deal redemption reversal response.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// Parameter request cannot be null.
        /// </exception>
        public pubReversalResponse1 pubReversal(pubReversalRequest1 request)
        {
            Stopwatch callTimer = Stopwatch.StartNew();

            if (request == null)
            {
                throw new ArgumentNullException("request", "Parameter request cannot be null.");
            }

            pubReversalResponse1 result = new pubReversalResponse1(new pubReversalResponse()
            {
                reqID = request.pubReversalRequest.reqID
            });

            // Split processing of timeout and non-timeout reversals.
            HttpStatusCode httpStatusCode;

            if (request.pubReversalRequest.revReason == FirstDataConstants.ReverseRedeemedDealIndicator)
            {
                // Build a context object to pass down the pipeline.
                CommerceContext context = CommerceContext.BuildSynchronousContext("First Data Reverse redeemed deal",
                                                                                  request.pubReversalRequest,
                                                                                  result.pubReversalResponse);

                // Process the call.
                httpStatusCode = ProcessFirstDataCall(context, callTimer, () =>
                {
                    FirstDataReverseRedeemedDealExecutor executor = new FirstDataReverseRedeemedDealExecutor(context);
                    return(executor.Execute());
                });
            }
            else
            {
                // Build a context object to pass down the pipeline.
                CommerceContext context = CommerceContext.BuildSynchronousContext("First Data process redemption timeout",
                                                                                  request.pubReversalRequest,
                                                                                  result.pubReversalResponse);

                // Process the call.
                httpStatusCode = ProcessFirstDataCall(context, callTimer, () =>
                {
                    FirstDataProcessRedemptionTimeoutExecutor executor = new FirstDataProcessRedemptionTimeoutExecutor(context);
                    return(executor.Execute());
                });
            }

            // Throw exception if the operation did not succeed.
            if (httpStatusCode != HttpStatusCode.OK)
            {
                throw new WebFaultException <pubReversalResponse1>(result, httpStatusCode);
            }

            return(result);
        }
Exemplo n.º 4
0
        private HttpResponseMessage ProcessVisaEndpointMessage(VisaEPMRequestType type)
        {
            VisaEpmResponse response = new VisaEpmResponse {
                StatusCode = "0", ErrorMessage = ""
            };
            CommerceContext context = null;
            string          message = null;

            try
            {
                EndPointMessageRequest request = ParseRequest();

                context = CommerceContext.BuildSynchronousContext("Incoming Visa Request",
                                                                  request,
                                                                  response);

                message = Request.Content.ReadAsStringAsync().Result;
                context.Log.Verbose("Incoming POST payload from Visa : \r\n\"{0}\".", message);


                //If Visa do not send StatementCredit message on a new endpoint then we have to detect from the message if it is StatementCredit message
                if (request.MessageName != null && request.MessageName.IndexOf("StatementCreditEndPoint", StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    type = VisaEPMRequestType.OnStatementCredit;
                }

                //if (IsAuthorized(context))
                {
                    Stopwatch callTimer      = Stopwatch.StartNew();
                    var       httpStatusCode = HttpStatusCode.OK;

                    if (type == VisaEPMRequestType.OnClear)
                    {
                        httpStatusCode = ProcessVisaEndpointMessage(context, callTimer, () =>
                        {
                            VisaRedeemDealExecutor visaEndpointMessageProcessor =
                                new VisaRedeemDealExecutor(context);
                            return(visaEndpointMessageProcessor.Execute());
                        });
                    }
                    else if (type == VisaEPMRequestType.OnAuth)
                    {
                        httpStatusCode = ProcessVisaEndpointMessage(context, callTimer, () =>
                        {
                            VisaAuthorizationExecutor visaEndpointMessageProcessor =
                                new VisaAuthorizationExecutor(context);
                            return(visaEndpointMessageProcessor.Execute());
                        });
                    }
                    else if (type == VisaEPMRequestType.OnStatementCredit)
                    {
                        httpStatusCode = ProcessVisaEndpointMessage(context, callTimer, () =>
                        {
                            VisaStatementCreditExecutor visaEndpointMessageProcessor =
                                new VisaStatementCreditExecutor(context);
                            return(visaEndpointMessageProcessor.Execute());
                        });
                    }
                    else
                    {
                        httpStatusCode = HttpStatusCode.BadRequest;
                        context.Log.Warning("Incoming request message is not of type auth, clearing or statementCredit. Request : {0} ", request.ToString());
                    }

                    if (httpStatusCode != HttpStatusCode.OK)
                    {
                        response.StatusCode   = "100";
                        response.ErrorMessage = "General Input Error";
                        context.Log.Warning("Incoming {0} request processing error. Request : {1} ", type,
                                            request.ToString());
                    }
                    return(ComposeResponseMessage(response, context, request.MessageId));
                }

                //return new HttpResponseMessage(HttpStatusCode.Unauthorized);
            }
            catch (Exception ex)
            {
                try
                {
                    if (context == null)
                    {
                        context = CommerceContext.BuildSynchronousContext("Incoming Visa Request", Request, response);
                    }

                    if (message == null)
                    {
                        try
                        {
                            message = Request.Content.ReadAsStringAsync().Result;
                        }
                        catch
                        {
                        }
                    }

                    context.Log.Error("{0} call ended with an error. Message:{1}", ex, context.ApiCallDescription, message);
                }
                catch
                {
                }

                response.StatusCode   = "100";
                response.ErrorMessage = "General Input Error";
                return(ComposeResponseMessage(response));
            }
        }