Ejemplo n.º 1
0
        private string ProcessOrderThroughGateway(int OrderNumber, int CustomerID, Decimal OrderTotal, TransactionModeEnum TransactionMode, Address UseBillingAddress, String CardExtraCode, ref String AuthorizationResult, ref String AuthorizationCode, ref String AuthorizationTransID, ref String TransactionCommandOut, ref String TransactionResponse, Customer customer, GatewayMoneybookers.IPaymentType paymentType, string customerIpAddress, string cardType)
        {
            GatewayMoneybookers.PaymentRequestBuilder requestBuilder = new GatewayMoneybookers.PaymentRequestBuilder();
            var paymentRequest = requestBuilder.BuildCreditCardPaymentRequest(
                paymentType,
                OrderNumber,
                null,
                CustomerID,
                customer.EMail,
                UseBillingAddress.FirstName,
                UseBillingAddress.LastName,
                UseBillingAddress.Address1,
                UseBillingAddress.City,
                CommonLogic.IIF(String.IsNullOrEmpty(UseBillingAddress.State), null, UseBillingAddress.State),
                UseBillingAddress.Zip,
                UseBillingAddress.Country,
                customerIpAddress,
                OrderTotal,
                cardType,
                UseBillingAddress.CardNumber,
                UseBillingAddress.CardExpirationMonth.PadLeft(2, '0'),
                UseBillingAddress.CardExpirationYear,
                CommonLogic.IIF(String.IsNullOrEmpty(UseBillingAddress.CardIssueNumber), null, UseBillingAddress.CardIssueNumber),
                CardExtraCode);

            GatewayMoneybookers.PaymentXmlTransformer <GatewayMoneybookers.CreditCardPaymentMethod> paymentTransformer = new GatewayMoneybookers.PaymentXmlTransformer <GatewayMoneybookers.CreditCardPaymentMethod>();
            GatewayMoneybookers.CreditCardPaymentMethodXmlTransformer paymentMethodTransformer = new GatewayMoneybookers.CreditCardPaymentMethodXmlTransformer();
            var paymentRequestData = paymentTransformer.TransformRequest(paymentRequest, paymentMethodTransformer);

            // Submit request and get response
            string paymentResponseData = null;
            string result      = String.Empty;
            int    maxAttempts = AppLogic.AppConfigUSInt("GatewayRetries") + 1;

            for (int attemptCount = 0; attemptCount < maxAttempts; attemptCount++)
            {
                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(RequestUri);
                request.Method      = "POST";
                request.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";

                try
                {
                    using (var requestStream = request.GetRequestStream())
                    {
                        using (StreamWriter requestWriter = new StreamWriter(requestStream))
                        {
                            requestWriter.Write("load={0}", Uri.EscapeDataString(paymentRequestData));
                            requestWriter.Close();
                        }

                        requestStream.Close();
                    }

                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                    using (var responseStream = response.GetResponseStream())
                    {
                        using (StreamReader responseReader = new StreamReader(responseStream))
                        {
                            paymentResponseData = responseReader.ReadToEnd();
                            responseReader.Close();
                        }

                        responseStream.Close();
                    }

                    break;
                }
#if DEBUG
                catch (WebException exception)
                {
                    using (var responseStream = exception.Response.GetResponseStream())
                    {
                        using (StreamReader responseReader = new StreamReader(responseStream))
                        {
                            result = String.Format("Error calling Moneybookers payment gateway. {0}{1}", exception.Message, responseReader.ReadToEnd());
                            responseReader.Close();
                        }
                        responseStream.Close();
                    }
                }
#endif
                catch (Exception exception)
                {
                    result = String.Format("Error calling Moneybookers payment gateway. {0}", exception.Message);
                }
            }

            // Process response
            if (paymentResponseData != null)
            {
                GatewayMoneybookers.PaymentResponse paymentResponse = paymentTransformer.TransformResponse(paymentResponseData);
                AuthorizationCode    = paymentResponse.ProcessingCode;
                AuthorizationResult  = paymentResponse.Return;
                AuthorizationTransID = CommonLogic.IIF(TransactionMode == TransactionModeEnum.auth, "AUTH=", "CAPTURE=") + paymentResponse.TransactionUniqueId;

                TransactionCommandOut = paymentRequestData;
                TransactionResponse   = paymentResponseData;

                if (paymentResponse.Result.ToUpperInvariant() == "ACK")
                {
                    if (paymentResponse.ResponseMode == GatewayMoneybookers.ResponseMode.Async)
                    {
                        string redirectUrl = paymentResponse.RedirectUrl;

                        string parameterKeys = String.Join(";", paymentResponse.RedirectParameters.Keys.Select(s => "Moneybookers_3DSecure_Parameter_" + s).ToArray());

                        CustomerSession customerSession = new CustomerSession(CustomerID);
                        customerSession["Moneybookers_3DSecure_OrderNumber"]   = OrderNumber.ToString();
                        customerSession["Moneybookers_3DSecure_RedirectUrl"]   = paymentResponse.RedirectUrl;
                        customerSession["Moneybookers_3DSecure_ParameterKeys"] = parameterKeys;

                        foreach (var kvp in paymentResponse.RedirectParameters)
                        {
                            customerSession["Moneybookers_3DSecure_Parameter_" + kvp.Key] = kvp.Value;
                        }

                        result = AppLogic.ro_3DSecure;
                    }
                    else
                    {
                        result = AppLogic.ro_OK;
                    }
                }
                else
                {
                    result = String.Format("{0} - {1} - {2} - {3}", paymentResponse.Result, paymentResponse.Status, paymentResponse.Reason, paymentResponse.Return);
                    if (result.Length == 0)
                    {
                        result = "Unspecified Error";
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
        private string ProcessOrderThrough3DSecure(int OrderNumber, int CustomerID, Decimal OrderTotal, TransactionModeEnum TransactionMode, Address UseBillingAddress, String CardExtraCode, ref String AuthorizationResult, ref String AuthorizationCode, ref String AuthorizationTransID, ref String TransactionCommandOut, ref String TransactionResponse, Customer customer, GatewayMoneybookers.IPaymentType paymentType, string customerIpAddress, string cardType, CustomerSession customerSession)
        {
            string originalResponseData  = customerSession["Moneybookers_3DSecure_Response"];
            var    paymentXmlTransformer = new GatewayMoneybookers.PaymentXmlTransformer <GatewayMoneybookers.CreditCardPaymentMethod>();
            var    paymentResponse       = paymentXmlTransformer.TransformResponse(originalResponseData);

            AuthorizationCode    = paymentResponse.ProcessingCode;
            AuthorizationResult  = paymentResponse.Return;
            AuthorizationTransID = CommonLogic.IIF(TransactionMode == TransactionModeEnum.auth, "AUTH=", "CAPTURE=") + paymentResponse.TransactionUniqueId;

            TransactionResponse = originalResponseData;

            // Check for timeout
            if (paymentResponse.ReturnCode == "100.380.501")
            {
                return("3D Secure payment verification timed out.");
            }

            // Verify 3D secure response
            string verificationRequestUri = ThreeDSecureRequestUri + customerSession["Moneybookers_3DSecure_VerificationPath"];

            // Submit request and get response
            string responseData = null;
            string result       = String.Empty;
            int    maxAttempts  = AppLogic.AppConfigUSInt("GatewayRetries") + 1;

            for (int attemptCount = 0; attemptCount < maxAttempts; attemptCount++)
            {
                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(verificationRequestUri);
                request.Method      = "POST";
                request.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";

                try
                {
                    using (var requestStream = request.GetRequestStream())
                    {
                        using (StreamWriter requestWriter = new StreamWriter(requestStream))
                        {
                            requestWriter.Write("response={0}", Uri.EscapeDataString(originalResponseData));
                            requestWriter.Close();
                        }

                        requestStream.Close();
                    }

                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                    using (var responseStream = response.GetResponseStream())
                    {
                        using (StreamReader responseReader = new StreamReader(responseStream))
                        {
                            responseData = responseReader.ReadToEnd();
                            responseReader.Close();
                        }

                        responseStream.Close();
                    }

                    break;
                }
#if DEBUG
                catch (WebException exception)
                {
                    using (var responseStream = exception.Response.GetResponseStream())
                    {
                        using (StreamReader responseReader = new StreamReader(responseStream))
                        {
                            result = String.Format("Error calling Skrill (Moneybookers) payment gateway. {0}{1}", exception.Message, responseReader.ReadToEnd());
                            responseReader.Close();
                        }
                        responseStream.Close();
                    }
                }
#endif
                catch (Exception exception)
                {
                    result = String.Format("Error calling Skrill (Moneybookers) payment gateway. {0}", exception.Message);
                }
            }

            // Process response
            if (String.IsNullOrEmpty(responseData))
            {
                result = "Empty response from 3D Secure validation call.";
            }
            else if (responseData == "VERIFIED")
            {
                result = AppLogic.ro_OK;
            }
            else
            {
                result = "Payment method was not validated. Please try submitting your payment again";
            }

            return(result);
        }