Exemple #1
0
        /// <summary>
        /// Processes the callback.
        /// </summary>
        /// <param name="order">The order.</param>
        /// <param name="request">The request.</param>
        /// <param name="settings">The settings.</param>
        /// <returns></returns>
        public override CallbackInfo ProcessCallback(Api.Models.Order order, System.Web.HttpRequest request, IDictionary <string, string> settings)
        {
            CallbackInfo callbackInfo = null;

            try
            {
                order.MustNotBeNull("order");
                request.MustNotBeNull("request");
                settings.MustNotBeNull("settings");
                settings.MustContainKey("PartnerId", "settings");
                settings.MustContainKey("RoundingMode", "settings");

                // Call the validation URL to check this order
                IdealCheck idealCheck = new IdealCheck(settings["PartnerId"], settings["TestMode"] == "1", request["transaction_id"]);

                decimal orderAmount = order.TotalPrice.Value.WithVat;
                if (idealCheck.Payed)
                {
                    decimal mollieAmount = idealCheck.Amount;

                    // Check if amount that mollie received is equal to the orders amount
                    if (Math.Round(mollieAmount, 0) == Math.Round(orderAmount, Convert.ToInt32(settings["RoundingMode"])))
                    {
                        callbackInfo = new CallbackInfo(orderAmount, request["transaction_id"], PaymentState.Captured);
                        LoggingService.Instance.Info <MollieiDeal>(string.Format("Mollie: Saved and finalized orderId {0}", order.Id));
                    }
                    else
                    {
                        callbackInfo = new CallbackInfo(orderAmount, request["transaction_id"], PaymentState.Error);
                        LoggingService.Instance.Info <MollieiDeal>(string.Format("Mollie: Controle: MollieAmount:{0} OrderAmount: {1} do not match!", mollieAmount, orderAmount));
                    }
                }
                else
                {
                    LoggingService.Instance.Info <MollieiDeal>(string.Format("Mollie: Controle: iDeal status not payed, for cartId {0}!", order.Id));
                }
            }
            catch (Exception exp)
            {
                LoggingService.Instance.Error <MollieiDeal>("ProcessCallback exception", exp);
            }

            return(callbackInfo);
        }
Exemple #2
0
        public override CallbackInfo ProcessCallback( Order order, HttpRequest request, IDictionary<string, string> settings )
        {
            CallbackInfo callbackInfo = null;

              try {
            order.MustNotBeNull( "order" );
            request.MustNotBeNull( "request" );
            settings.MustNotBeNull( "settings" );

            //Write data when testing
            if ( settings.ContainsKey( "testMode" ) && settings[ "testMode" ] == "1" ) {
              LogRequest<ePay>( request, logGetData: true );
            }

            string transaction = request.QueryString[ "txnid" ];
            string strAmount = request.QueryString[ "amount" ];
            string hash = request.QueryString[ "hash" ];

            string md5CheckValue = string.Empty;

            foreach ( string k in request.QueryString.Keys ) {
              if ( k != "hash" ) {
            md5CheckValue += request.QueryString[ k ];
              }
            }
            if ( settings.ContainsKey( "md5securitykey" ) ) {
              md5CheckValue += settings[ "md5securitykey" ];
            }

            if ( order.CartNumber == request.QueryString[ "orderid" ] && GenerateMD5Hash( md5CheckValue ) == hash ) {
              string fee = request.QueryString[ "txnfee" ];
              string cardid = request.QueryString[ "paymenttype" ];
              string cardnopostfix = request.QueryString[ "cardno" ];

              decimal totalAmount = ( decimal.Parse( strAmount, CultureInfo.InvariantCulture ) + decimal.Parse( fee, CultureInfo.InvariantCulture ) );

              bool autoCaptured = settings.ContainsKey( "instantcapture" ) && settings[ "instantcapture" ] == "1";

              callbackInfo = new CallbackInfo( totalAmount / 100M, transaction, !autoCaptured ? PaymentState.Authorized : PaymentState.Captured, cardid, cardnopostfix );
            } else {
              LoggingService.Instance.Warn<ePay>( "ePay(" + order.CartNumber + ") - MD5Sum security check failed" );
            }
              } catch ( Exception exp ) {
            LoggingService.Instance.Error<ePay>( "ePay(" + order.CartNumber + ") - Process callback", exp );
              }

              return callbackInfo;
        }
Exemple #3
0
        public override CallbackInfo ProcessCallback( Order order, HttpRequest request, IDictionary<string, string> settings )
        {
            CallbackInfo callbackInfo = null;

              try {
            order.MustNotBeNull( "order" );
            request.MustNotBeNull( "request" );
            settings.MustNotBeNull( "settings" );
            settings.MustContainKey( "paymentResponsePassword", "settings" );

            //Write data when testing
            if ( settings.ContainsKey( "testMode" ) && settings[ "testMode" ] == "100" ) {
              LogRequest<WorldPay>( request, logPostData: true );
            }

            string paymentResponsePassword = settings[ "paymentResponsePassword" ];
            string callbackPw = request.Form[ "callbackPW" ];

            if ( callbackPw == paymentResponsePassword ) {
              if ( request.Form[ "transStatus" ] == "Y" ) {
            decimal totalAmount = decimal.Parse( request.Form[ "authAmount" ], CultureInfo.InvariantCulture );
            string transaction = request.Form[ "transId" ];
            PaymentState paymentState = request.Form[ "authMode" ] == "E" ? PaymentState.Authorized : PaymentState.Captured;
            string cardtype = request.Form[ "cardtype" ];

            callbackInfo = new CallbackInfo( totalAmount, transaction, paymentState, cardtype );
              } else {
            LoggingService.Instance.Warn<WorldPay>( "WorldPay(" + order.CartNumber + ") - Cancelled transaction" );
              }
            } else {
              LoggingService.Instance.Warn<WorldPay>( "WorldPay(" + order.CartNumber + ") - Payment response password check failed - callbackPW: " + callbackPw + " - paymentResponsePassword: "******"WorldPay(" + order.CartNumber + ") - Process callback", exp );
              }

              return callbackInfo;
        }
Exemple #4
0
        public override string GetCartNumber( HttpRequest request, IDictionary<string, string> settings )
        {
            string cartNumber = "";

              try {
            request.MustNotBeNull( "request" );
            settings.MustNotBeNull( "settings" );
            settings.MustContainKey( "paymentResponsePassword", "settings" );

            //Write data when testing
            if ( settings.ContainsKey( "testMode" ) && settings[ "testMode" ] == "100" ) {
              LogRequest<WorldPay>( request, logPostData: true );
            }

            string paymentResponsePassword = settings[ "paymentResponsePassword" ];
            string callbackPw = request.Form[ "callbackPW" ];

            if ( callbackPw == paymentResponsePassword ) {
              cartNumber = request.Form[ "cartId" ];
            } else {
              LoggingService.Instance.Warn<WorldPay>( "WorldPay - Payment response password check failed - callbackPW: " + callbackPw + " - paymentResponsePassword: "******"WorldPay - Get cart number", exp );
              }

              return cartNumber;
        }
        public override CallbackInfo ProcessCallback( Order order, HttpRequest request, IDictionary<string, string> settings )
        {
            CallbackInfo callbackInfo = null;

              try {
            order.MustNotBeNull( "order" );
            request.MustNotBeNull( "request" );
            settings.MustNotBeNull( "settings" );
            settings.MustContainKey( "secretWord", "settings" );

            //Write data when testing
            if ( settings.ContainsKey( "demo" ) && settings[ "demo" ] == "Y" ) {
              LogRequest( request, logGetData: true );
            }

            string accountNumber = request.QueryString[ "sid" ];
            string transaction = request.QueryString[ "order_number" ];
            string strAmount = request.QueryString[ "total" ];
            string key = request.QueryString[ "key" ];

            string md5CheckValue = string.Empty;
            md5CheckValue += settings[ "secretWord" ];
            md5CheckValue += accountNumber;
            md5CheckValue += settings.ContainsKey( "demo" ) && settings[ "demo" ] == "Y" ? "1" : transaction;
            md5CheckValue += strAmount;

            string calculatedMd5 = GenerateMD5Hash( md5CheckValue ).ToUpperInvariant();

            if ( calculatedMd5 == key ) {
              decimal totalAmount = decimal.Parse( strAmount, CultureInfo.InvariantCulture );

              callbackInfo = new CallbackInfo( totalAmount, transaction, PaymentState.Authorized );
            } else {
              LoggingService.Instance.Log( "2CheckOut(" + order.CartNumber + ") - MD5Sum security check failed - key: " + key + " - calculatedMD5: " + calculatedMd5 );
            }
              } catch ( Exception exp ) {
            LoggingService.Instance.Log( exp, "2CheckOut(" + order.CartNumber + ") - Process callback" );
              }

              return callbackInfo;
        }
Exemple #6
0
        public override CallbackInfo ProcessCallback( Order order, HttpRequest request, IDictionary<string, string> settings )
        {
            CallbackInfo callbackInfo = null;

              try {
            order.MustNotBeNull( "order" );
            request.MustNotBeNull( "request" );
            settings.MustNotBeNull( "settings" );
            settings.MustContainKey( "md5secret", "settings" );

            //Write data when testing
            if ( settings.ContainsKey( "testmode" ) && settings[ "testmode" ] == "1" ) {
              LogRequest( request, logPostData: true );
            }

            string md5CheckValue = string.Empty;
            md5CheckValue += request.Form[ "msgtype" ];
            md5CheckValue += request.Form[ "ordernumber" ];
            md5CheckValue += request.Form[ "amount" ];
            md5CheckValue += request.Form[ "currency" ];
            md5CheckValue += request.Form[ "time" ];
            md5CheckValue += request.Form[ "state" ];
            md5CheckValue += request.Form[ "qpstat" ];
            md5CheckValue += request.Form[ "qpstatmsg" ];
            md5CheckValue += request.Form[ "chstat" ];
            md5CheckValue += request.Form[ "chstatmsg" ];
            md5CheckValue += request.Form[ "merchant" ];
            md5CheckValue += request.Form[ "merchantemail" ];
            md5CheckValue += request.Form[ "transaction" ];
            md5CheckValue += request.Form[ "cardtype" ];
            md5CheckValue += request.Form[ "cardnumber" ];
            md5CheckValue += request.Form[ "cardhash" ];
            md5CheckValue += request.Form[ "cardexpire" ];
            md5CheckValue += request.Form[ "acquirer" ];
            md5CheckValue += request.Form[ "splitpayment" ];
            md5CheckValue += request.Form[ "fraudprobability" ];
            md5CheckValue += request.Form[ "fraudremarks" ];
            md5CheckValue += request.Form[ "fraudreport" ];
            md5CheckValue += request.Form[ "fee" ];
            md5CheckValue += settings[ "md5secret" ];

            string orderName = order.CartNumber;
            while ( orderName.Length < 4 )
              orderName = "0" + orderName;

            if ( orderName == request.Form[ "ordernumber" ] && GenerateMD5Hash( md5CheckValue ) == request.Form[ "md5check" ] ) {
              string qpstat = request.Form[ "qpstat" ];

              if ( qpstat == "000" ) {
            decimal amount = decimal.Parse( request.Form[ "amount" ], CultureInfo.InvariantCulture ) / 100M;
            string state = request.Form[ "state" ];
            string transaction = request.Form[ "transaction" ];

            callbackInfo = new CallbackInfo( amount, transaction, state == "1" ? PaymentState.Authorized : PaymentState.Captured, request.Form[ "cardtype" ], request.Form[ "cardnumber" ] );
              } else {
            LoggingService.Instance.Log( "Quickpay(" + order.CartNumber + ") - Error making API request - error code: " + qpstat + " | error message: " + request.Form[ "qpstatmsg" ] );
              }

            } else {
              LoggingService.Instance.Log( "QuickPay(" + order.CartNumber + ") - MD5Sum security check failed" );
            }
              } catch ( Exception exp ) {
            LoggingService.Instance.Log( exp, "QuickPay(" + order.CartNumber + ") - Process callback" );
              }

              return callbackInfo;
        }
Exemple #7
0
        public override CallbackInfo ProcessCallback( Order order, HttpRequest request, IDictionary<string, string> settings )
        {
            CallbackInfo callbackInfo = null;

              try {
            order.MustNotBeNull( "order" );
            request.MustNotBeNull( "request" );
            settings.MustNotBeNull( "settings" );
            settings.MustContainKey( "TRANSACTION.MODE", "settings" );

            //Write data when testing
            if ( settings[ "TRANSACTION.MODE" ] != "LIVE" ) {
              LogRequest( request, logPostData: true );
            }

            HttpContext.Current.Response.Clear();
            if ( request[ "PROCESSING.RESULT" ] == "ACK" ) {
              callbackInfo = new CallbackInfo( decimal.Parse( request.Form[ "PRESENTATION.AMOUNT" ], CultureInfo.InvariantCulture ), request.Form[ "IDENTIFICATION.UNIQUEID" ], request.Form[ "PAYMENT.CODE" ] != "CC.DB" ? PaymentState.Authorized : PaymentState.Captured );

              string continueUrl = GetContinueUrl( order, settings );
              if ( !continueUrl.StartsWith( "http" ) ) {
            Uri baseUrl = new UriBuilder( request.Url.Scheme, request.Url.Host, request.Url.Port ).Uri;
            continueUrl = new Uri( baseUrl, continueUrl ).AbsoluteUri;
              }

              HttpContext.Current.Response.Write( continueUrl );
            } else {
              LoggingService.Instance.Log( "Axcess(" + order.CartNumber + ") - Process callback - PROCESSING.CODE: " + request[ "PROCESSING.CODE" ] );

              string cancelUrl = GetCancelUrl( order, settings );
              if ( !cancelUrl.StartsWith( "http" ) ) {
            Uri baseUrl = new UriBuilder( request.Url.Scheme, request.Url.Host, request.Url.Port ).Uri;
            cancelUrl = new Uri( baseUrl, cancelUrl ).AbsoluteUri;
              }
              HttpContext.Current.Response.Write( cancelUrl );
            }
              } catch ( Exception exp ) {
            LoggingService.Instance.Log( exp, "Axcess(" + order.CartNumber + ") - Process callback" );
              }

              return callbackInfo;
        }
Exemple #8
0
        public override CallbackInfo ProcessCallback( Order order, HttpRequest request, IDictionary<string, string> settings )
        {
            CallbackInfo callbackInfo = null;

              try {
            order.MustNotBeNull( "order" );
            request.MustNotBeNull( "request" );
            settings.MustNotBeNull( "settings" );
            settings.MustContainKey( "Vendor", "settings" );

            //Write data when testing
            if ( settings.ContainsKey( "testMode" ) && ( settings[ "testMode" ] == "SIMULATOR" || settings[ "testMode" ] == "TEST" ) ) {
              LogRequest( request, logPostData: true );
            }

            string transaction = request.Form[ "VPSTxId" ];
            string status = request.Form[ "Status" ];
            string cartNumber = request.Form[ "VendorTxCode" ];
            string txAuthNo = request.Form[ "TxAuthNo" ];
            string cardType = request.Form[ "CardType" ];
            string last4Digits = request.Form[ "Last4Digits" ];

            string md5CheckValue = string.Empty;
            md5CheckValue += transaction;
            md5CheckValue += cartNumber;
            md5CheckValue += status;
            md5CheckValue += txAuthNo;
            md5CheckValue += settings[ "Vendor" ].ToLowerInvariant();
            md5CheckValue += HttpUtility.UrlDecode( request.Form[ "AVSCV2" ] );
            md5CheckValue += order.Properties[ "securityKey" ];
            md5CheckValue += HttpUtility.UrlDecode( request.Form[ "AddressResult" ] );
            md5CheckValue += HttpUtility.UrlDecode( request.Form[ "PostCodeResult" ] );
            md5CheckValue += HttpUtility.UrlDecode( request.Form[ "CV2Result" ] );
            md5CheckValue += request.Form[ "GiftAid" ];
            md5CheckValue += request.Form[ "3DSecureStatus" ];
            md5CheckValue += request.Form[ "CAVV" ];
            md5CheckValue += HttpUtility.UrlDecode( request.Form[ "AddressStatus" ] );
            md5CheckValue += HttpUtility.UrlDecode( request.Form[ "PayerStatus" ] );
            md5CheckValue += cardType;
            md5CheckValue += last4Digits;

            string calcedMd5Hash = GenerateMD5Hash( md5CheckValue ).ToUpperInvariant();
            string vpsSignature = request.Form[ "VPSSignature" ];

            if ( order.CartNumber == cartNumber && calcedMd5Hash == vpsSignature ) {

              Dictionary<string, string> inputFields = new Dictionary<string, string>();

              if ( status == "OK" || status == "AUTHENTICATED" || status == "REGISTERED" ) {
            callbackInfo = new CallbackInfo( order.TotalPrice.Value.WithVat, transaction, request.Form[ "TxType" ] != "PAYMENT" ? PaymentState.Authorized : PaymentState.Captured, cardType, last4Digits );

            if ( status == "OK" ) {
              order.Properties.AddOrUpdate( new CustomProperty( "txAuthNo", txAuthNo ) { ServerSideOnly = true } );
            }
            order.Properties.AddOrUpdate( new CustomProperty( "vendorTxCode", cartNumber ) { ServerSideOnly = true } );
            order.Save();

            inputFields[ "Status" ] = "OK";
            inputFields[ "RedirectURL" ] = order.Properties[ "teaCommerceContinueUrl" ];
            inputFields[ "StatusDetail" ] = "OK";

              } else {
            LoggingService.Instance.Log( "Sage Pay(" + order.CartNumber + ") - Error  in callback - status: " + status + " | status details: " + request.Form[ "StatusDetail" ] );

            if ( status == "ERROR" )
              inputFields[ "Status" ] = "INVALID";
            else
              inputFields[ "Status" ] = "OK";

            inputFields[ "RedirectURL" ] = order.Properties[ "teaCommerceCancelUrl" ];
            inputFields[ "StatusDetail" ] = "Error: " + status;
              }

              HttpContext.Current.Response.Clear();
              HttpContext.Current.Response.Write( string.Join( Environment.NewLine, inputFields.Select( i => string.Format( "{0}={1}", i.Key, i.Value ) ).ToArray() ) );
            } else {
              LoggingService.Instance.Log( "Sage Pay(" + order.CartNumber + ") - VPSSignature check isn't valid - Calculated signature: " + calcedMd5Hash + " | SagePay VPSSignature: " + vpsSignature );
            }
              } catch ( Exception exp ) {
            LoggingService.Instance.Log( exp, "Sage Pay(" + order.CartNumber + ") - Process callback" );
              }

              return callbackInfo;
        }
Exemple #9
0
        public override CallbackInfo ProcessCallback( Order order, HttpRequest request, IDictionary<string, string> settings )
        {
            CallbackInfo callbackInfo = null;

              try {
            order.MustNotBeNull( "order" );
            request.MustNotBeNull( "request" );
            settings.MustNotBeNull( "settings" );
            settings.MustContainKey( "accountNumber", "settings" );
            settings.MustContainKey( "encryptionKey", "settings" );

            long accountNumber = long.Parse( settings[ "accountNumber" ] );
            string orderRef = order.Properties.First( p => p.Alias.Equals( "orderRef" ) ).Value;
            string md5Hash = GenerateMD5Hash( accountNumber + orderRef + settings[ "encryptionKey" ] );

            string xmlReturn = GetPayExServiceClient( settings ).Complete( accountNumber, orderRef, md5Hash );

            //Write data when testing
            if ( settings.ContainsKey( "testing" ) && settings[ "testing" ] == "1" ) {
              using ( StreamWriter writer = new StreamWriter( File.Create( HostingEnvironment.MapPath( "~/payex-callback-data.txt" ) ) ) ) {
            writer.WriteLine( "Xml return:" );
            writer.WriteLine( xmlReturn );
            writer.Flush();
              }
            }

            XDocument xmlDoc = XDocument.Parse( xmlReturn, LoadOptions.PreserveWhitespace );
            string transactionStatus = xmlDoc.XPathSelectElement( "//transactionStatus" ).Value;
            string errorCode = xmlDoc.XPathSelectElement( "//status/errorCode" ).Value;

            //0 = Sale | 3 = Authorize
            if ( errorCode == "OK" && ( transactionStatus == "0" || transactionStatus == "3" ) && !bool.Parse( xmlDoc.XPathSelectElement( "//alreadyCompleted" ).Value ) ) {
              decimal amount = decimal.Parse( xmlDoc.XPathSelectElement( "//amount" ).Value, CultureInfo.InvariantCulture );
              string transactionNumber = xmlDoc.XPathSelectElement( "//transactionNumber" ).Value;
              PaymentState paymentState = transactionStatus.Equals( "3" ) ? PaymentState.Authorized : PaymentState.Captured;
              string paymentMethod = xmlDoc.XPathSelectElement( "//paymentMethod" ).Value;
              string maskedNumber = xmlDoc.XPathSelectElement( "//maskedNumber" ).Value;

              callbackInfo = new CallbackInfo( amount / 100M, transactionNumber, paymentState, paymentMethod, maskedNumber );
            } else {
              LoggingService.Instance.Log( "PayEx(" + order.CartNumber + ") - Callback failed - error code: " + errorCode + " - Description: " + xmlDoc.XPathSelectElement( "//status/description" ).Value );
            }
              } catch ( Exception exp ) {
            LoggingService.Instance.Log( exp, "PayEx(" + order.CartNumber + ") - Process callback" );
              }

              return callbackInfo;
        }
Exemple #10
0
        public override CallbackInfo ProcessCallback( Order order, HttpRequest request, IDictionary<string, string> settings )
        {
            CallbackInfo callbackInfo = null;

              try {
            order.MustNotBeNull( "order" );
            request.MustNotBeNull( "request" );
            settings.MustNotBeNull( "settings" );
            settings.MustContainKey( "sharedSecret", "settings" );

            IConnector connector = Connector.Create( settings[ "sharedSecret" ] );
            KlarnaOrder klarnaOrder = new KlarnaOrder( connector, new Uri( order.Properties[ "klarnaLocation" ] ) ) {
              ContentType = KlarnaApiRequestContentType
            };
            klarnaOrder.Fetch();

            if ( (string)klarnaOrder.GetValue( "status" ) == "checkout_complete" ) {

              //We need to populate the order with the information entered into Klarna.
              SaveOrderPropertiesFromKlarnaCallback( order, klarnaOrder );

              decimal amount = ( (JObject)klarnaOrder.GetValue( "cart" ) )[ "total_price_including_tax" ].Value<decimal>() / 100M;
              string klarnaId = klarnaOrder.GetValue( "id" ).ToString();

              callbackInfo = new CallbackInfo( amount, klarnaId, PaymentState.Authorized );

              klarnaOrder.Update( new Dictionary<string, object>() { { "status", "created" } } );
            } else {
              throw new Exception( "Trying to process a callback from Klarna with an order that isn't completed" );
            }
              } catch ( Exception exp ) {
            LoggingService.Instance.Error<Klarna>( "Klarna(" + order.CartNumber + ") - Process callback", exp );
              }

              return callbackInfo;
        }
Exemple #11
0
        public override CallbackInfo ProcessCallback( Order order, HttpRequest request, IDictionary<string, string> settings )
        {
            CallbackInfo callbackInfo = null;

              try {
            order.MustNotBeNull( "order" );
            request.MustNotBeNull( "request" );
            settings.MustNotBeNull( "settings" );
            settings.MustContainKey( "merchantId", "settings" );
            settings.MustContainKey( "token", "settings" );

            //Write data when testing
            if ( settings.ContainsKey( "testmode" ) && settings[ "testmode" ] == "1" ) {
              LogRequest( request, logGetData: true );
            }

            string responseCode = request.QueryString[ "responseCode" ];

            if ( responseCode != null && responseCode == "OK" ) {
              bool autoCapture = settings.ContainsKey( "instantcapture" ) && settings[ "instantcapture" ] == "1";
              string transactionId = request.QueryString[ "transactionId" ];

              Dictionary<string, string> inputFields = new Dictionary<string, string>();
              inputFields[ "merchantId" ] = settings[ "merchantId" ];
              inputFields[ "token" ] = settings[ "token" ];
              inputFields[ "operation" ] = !autoCapture ? "AUTH" : "SALE";
              inputFields[ "transactionId" ] = transactionId;

              XDocument xmlResponse = XDocument.Parse( MakePostRequest( settings.ContainsKey( "testMode" ) && settings[ "testMode" ] == "1" ? "https://epayment-test.bbs.no/Netaxept/Process.aspx" : "https://epayment.bbs.no/Netaxept/Process.aspx", inputFields ), LoadOptions.PreserveWhitespace );

              if ( xmlResponse.XPathSelectElement( "//ProcessResponse" ) != null && xmlResponse.XPathSelectElement( "//ProcessResponse/ResponseCode" ).Value == "OK" ) {

            //Get details from the transaction
            xmlResponse = QueryTransaction( transactionId, settings );

            if ( xmlResponse.XPathSelectElement( "//PaymentInfo" ) != null ) {
              decimal totalAmount = decimal.Parse( xmlResponse.XPathSelectElement( "//PaymentInfo/OrderInformation/Total" ).Value, CultureInfo.InvariantCulture ) / 100M;
              string cardType = xmlResponse.XPathSelectElement( "//PaymentInfo/CardInformation/PaymentMethod" ).Value;
              string cardNumber = xmlResponse.XPathSelectElement( "//PaymentInfo/CardInformation/MaskedPAN" ).Value;

              callbackInfo = new CallbackInfo( totalAmount, transactionId, !autoCapture ? PaymentState.Authorized : PaymentState.Captured, cardType, cardNumber );
            } else {
              LoggingService.Instance.Log( "Netaxept(" + order.CartNumber + ") - ProcessCallback error - " + xmlResponse.XPathSelectElement( "//Error/Message" ).Value );
            }
              } else {
            string errorMessage = "Netaxept(" + order.CartNumber + ") - ProcessCallback error - " + xmlResponse.XPathSelectElement( "//Error/Message" ).Value;
            if ( xmlResponse.XPathSelectElement( "//Error/Result" ) != null ) {
              errorMessage += " response code: " + xmlResponse.XPathSelectElement( "//Error/Result/ResponseCode" ).Value + " transactionId: " + xmlResponse.XPathSelectElement( "//Error/Result/TransactionId" ).Value;
            }
            LoggingService.Instance.Log( errorMessage );
              }

            } else {
              LoggingService.Instance.Log( "Netaxept(" + order.CartNumber + ") - Response code isn't valid - response code: " + responseCode );
            }
              } catch ( Exception exp ) {
            LoggingService.Instance.Log( exp, "Netaxept(" + order.CartNumber + ") - Process callback" );
              }

              HttpContext.Current.Response.Redirect( order.Properties[ callbackInfo != null ? "teaCommerceContinueUrl" : "teaCommerceCancelUrl" ], false );

              return callbackInfo;
        }
        public override string ProcessRequest( Order order, HttpRequest request, IDictionary<string, string> settings )
        {
            string response = "";

              try {
            order.MustNotBeNull( "order" );
            request.MustNotBeNull( "request" );
            settings.MustNotBeNull( "settings" );
            settings.MustContainKey( "profile_id", "settings" );
            settings.MustContainKey( "access_key", "settings" );
            settings.MustContainKey( "locale", "settings" );
            settings.MustContainKey( "transaction_type", "settings" );
            settings.MustContainKey( "phonePropertyAlias", "settings" );
            settings.MustContainKey( "streetAddressPropertyAlias", "settings" );
            settings.MustContainKey( "cityPropertyAlias", "settings" );
            order.Properties[ settings[ "phonePropertyAlias" ] ].MustNotBeNullOrEmpty( "phone" );
            order.Properties[ settings[ "streetAddressPropertyAlias" ] ].MustNotBeNullOrEmpty( "street address" );
            order.Properties[ settings[ "cityPropertyAlias" ] ].MustNotBeNullOrEmpty( "city" );
            order.PaymentInformation.FirstName.MustNotBeNull( "first name" );
            order.PaymentInformation.LastName.MustNotBeNull( "last name" );
            order.PaymentInformation.Email.MustNotBeNull( "email" );

            // If in test mode, write out the form data to a text file
            if ( settings.ContainsKey( "mode" ) && settings[ "mode" ] == "test" ) {
              LogRequest( request, logPostData: true );
            }

            //Generate input fields for the JavaScript post of the inline form
            IDictionary<string, string> inputFields = new Dictionary<string, string>();
            inputFields[ "profile_id" ] = settings[ "profile_id" ];
            inputFields[ "access_key" ] = settings[ "access_key" ];
            inputFields[ "override_custom_receipt_page" ] = order.Properties[ "teaCommerceCallBackUrl" ];
            inputFields[ "locale" ] = settings[ "locale" ];
            inputFields[ "payment_method" ] = "card";

            inputFields[ "reference_number" ] = order.CartNumber;
            inputFields[ "signed_date_time" ] = DateTime.UtcNow.ToString( "yyyy-MM-dd'T'HH:mm:ss'Z'" );
            inputFields[ "transaction_type" ] = settings[ "transaction_type" ];
            inputFields[ "transaction_uuid" ] = Guid.NewGuid().ToString();
            inputFields[ "amount" ] = order.TotalPrice.Value.WithVat.ToString( "0.00", CultureInfo.InvariantCulture );
            Currency currency = CurrencyService.Instance.Get( order.StoreId, order.CurrencyId );
            if ( !Iso4217CurrencyCodes.ContainsKey( currency.IsoCode ) ) {
              throw new Exception( "You must specify an ISO 4217 currency code for the " + currency.Name + " currency" );
            }
            inputFields[ "currency" ] = currency.IsoCode;

            inputFields[ "bill_to_forename" ] = order.PaymentInformation.FirstName;
            inputFields[ "bill_to_surname" ] = order.PaymentInformation.LastName;
            inputFields[ "bill_to_email" ] = order.PaymentInformation.Email;
            inputFields[ "bill_to_phone" ] = order.Properties[ settings[ "phonePropertyAlias" ] ];

            inputFields[ "bill_to_address_line1" ] = order.Properties[ settings[ "streetAddressPropertyAlias" ] ];
            inputFields[ "bill_to_address_city" ] = order.Properties[ settings[ "cityPropertyAlias" ] ];
            if ( settings.ContainsKey( "zipCodePropertyAlias" ) ) {
              inputFields[ "bill_to_address_postal_code" ] = order.Properties[ settings[ "zipCodePropertyAlias" ] ];
            }
            Country country = CountryService.Instance.Get( order.StoreId, order.PaymentInformation.CountryId );
            if ( !Iso3166CountryCodes.ContainsKey( country.RegionCode ) ) {
              throw new Exception( "You must specify an ISO 3166 country code for the " + country.Name + " country" );
            }
            inputFields[ "bill_to_address_country" ] = country.RegionCode;
            inputFields[ "bill_to_address_state" ] = order.PaymentInformation.CountryRegionId != null ? CountryRegionService.Instance.Get( order.StoreId, order.PaymentInformation.CountryRegionId.Value ).RegionCode : "";

            inputFields[ "card_type" ] = request.Form[ "card_type" ];
            inputFields[ "card_expiry_date" ] = request.Form[ "card_expiry_date" ];
            inputFields[ "card_cvn" ] = request.Form[ "card_cvn" ];
            inputFields[ "card_number" ] = request.Form[ "card_number" ];

            inputFields[ "unsigned_field_names" ] = "";
            inputFields[ "signed_field_names" ] = string.Join( ",", inputFields.Select( kvp => kvp.Key ) ) + ",signed_field_names";

            //Signature and card number should not be signed
            inputFields[ "signature" ] = CreateSignature( inputFields, settings );

            foreach ( KeyValuePair<string, string> kvp in inputFields ) {
              if ( request.Form[ kvp.Key ] != "" ) {
            response += "<input type=\"hidden\" name=\"" + kvp.Key + "\" value=\"" + kvp.Value + "\" />";
              }
            }

              } catch ( Exception exp ) {
            LoggingService.Instance.Log( exp, "CyberSource(" + order.CartNumber + ") - ProcessRequest" );
              }

              return response;
        }
        public override CallbackInfo ProcessCallback( Order order, HttpRequest request, IDictionary<string, string> settings )
        {
            CallbackInfo callbackInfo = null;

              try {
            order.MustNotBeNull( "order" );
            request.MustNotBeNull( "request" );
            settings.MustNotBeNull( "settings" );

            if ( settings.ContainsKey( "mode" ) && settings[ "mode" ] == "test" ) {
              LogRequest( request, logPostData: true );
            }

            string calculatedSignature = CreateSignature( request.Form[ "signed_field_names" ].Split( new[] { ',' }, StringSplitOptions.RemoveEmptyEntries ).ToDictionary( k => k, k => request.Form[ k ] ), settings );

            if ( order.CartNumber == request.Form[ "reference_number" ] && request.Form[ "signature" ] == calculatedSignature ) {
              //Both errors and successful callbacks will go here

              if ( request.Form[ "decision" ] == "ACCEPT" ) {
            callbackInfo = new CallbackInfo( decimal.Parse( request.Form[ "auth_amount" ], CultureInfo.InvariantCulture ), request.Form[ "transaction_id" ], request.Form[ "req_transaction_type" ] == "authorization" ? PaymentState.Authorized : PaymentState.Captured );

            HttpContext.Current.Response.Redirect( order.Properties[ "teaCommerceContinueUrl" ], false );
              } else {
            //Post interim form and auto submit it - act like the customer just clicked to the payment form page
            if ( order.PaymentInformation.PaymentMethodId != null ) {
              // Pass through request fields
              string requestFields = string.Join( "", request.Form.AllKeys.Select( k => "<input type=\"hidden\" name=\"" + k + "\" value=\"" + request.Form[ k ] + "\" />" ) );
              string paymentForm = PaymentMethodService.Instance.Get( order.StoreId, order.PaymentInformation.PaymentMethodId.Value ).GeneratePaymentForm( order, requestFields );

              //Force the form to auto submit
              paymentForm += "<script type=\"text/javascript\">document.forms[0].submit();</script>";

              //Write out the form
              HttpContext.Current.Response.Clear();
              HttpContext.Current.Response.Write( paymentForm );
            }
              }

            } else {
              LoggingService.Instance.Log( "CyberSource(" + order.CartNumber + ") - Signature security check failed" );
            }
              } catch ( Exception exp ) {
            LoggingService.Instance.Log( exp, "CyberSource(" + order.CartNumber + ") - ProcessCallback" );
              }

              return callbackInfo;
        }
        public override CallbackInfo ProcessCallback( Order order, HttpRequest request, IDictionary<string, string> settings )
        {
            CallbackInfo callbackInfo = null;

              try {
            order.MustNotBeNull( "order" );
            request.MustNotBeNull( "request" );
            settings.MustNotBeNull( "settings" );
            settings.MustContainKey( "md5HashKey", "settings" );
            settings.MustContainKey( "x_login", "settings" );

            //Write data when testing
            if ( settings.ContainsKey( "testing" ) && settings[ "testing" ] == "1" ) {
              LogRequest( request, logPostData: true );
            }

            string responseCode = request.Form[ "x_response_code" ];
            if ( responseCode == "1" ) {

              string amount = request.Form[ "x_amount" ];
              string transaction = request.Form[ "x_trans_id" ];

              string gatewayMd5Hash = request.Form[ "x_MD5_Hash" ];

              MD5CryptoServiceProvider x = new MD5CryptoServiceProvider();
              string calculatedMd5Hash = Regex.Replace( BitConverter.ToString( x.ComputeHash( Encoding.ASCII.GetBytes( settings[ "md5HashKey" ] + settings[ "x_login" ] + transaction + amount ) ) ), "-", string.Empty );

              if ( gatewayMd5Hash == calculatedMd5Hash ) {
            PaymentState paymentState = PaymentState.Authorized;
            if ( request.Form[ "x_type" ] == "auth_capture" ) {
              paymentState = PaymentState.Captured;
            }
            string cardType = request.Form[ "x_card_type" ];
            string cardNumber = request.Form[ "x_account_number" ];

            callbackInfo = new CallbackInfo( decimal.Parse( amount, CultureInfo.InvariantCulture ), transaction, paymentState, cardType, cardNumber );
              } else {
            LoggingService.Instance.Log( "Authorize.net(" + order.CartNumber + ") - MD5Sum security check failed - " + gatewayMd5Hash + " - " + calculatedMd5Hash + " - " + settings[ "md5HashKey" ] );
              }
            } else {
              LoggingService.Instance.Log( "Authorize.net(" + order.CartNumber + ") - Payment not approved: " + responseCode );
            }
              } catch ( Exception exp ) {
            LoggingService.Instance.Log( exp, "Authorize.net(" + order.CartNumber + ") - Process callback" );
              }

              return callbackInfo;
        }
Exemple #15
0
        public override CallbackInfo ProcessCallback( Order order, HttpRequest request, IDictionary<string, string> settings )
        {
            CallbackInfo callbackInfo = null;

              try {
            order.MustNotBeNull( "order" );
            request.MustNotBeNull( "request" );
            settings.MustNotBeNull( "settings" );
            settings.MustContainKey( "md5Key1", "settings" );
            settings.MustContainKey( "md5Key2", "settings" );

            //Write data when testing
            if ( settings.ContainsKey( "test_mode" ) && settings[ "test_mode" ] == "true" ) {
              LogRequest( request, logGetData: true );
            }

            //Check for payer IP addresses
            string remoteServerIpAddress = request.ServerVariables[ "REMOTE_ADDR" ];

            if ( remoteServerIpAddress == "217.151.207.84" || remoteServerIpAddress == "79.136.103.5" || remoteServerIpAddress == "79.136.103.9" || remoteServerIpAddress == "94.140.57.180" || remoteServerIpAddress == "94.140.57.181" || remoteServerIpAddress == "94.140.57.184" || remoteServerIpAddress == "192.168.100.1" ) {

              string url = request.Url.Scheme + "://" + request.Url.Host + request.ServerVariables[ "REQUEST_URI" ];
              string urlExceptMd5Sum = url.Substring( 0, url.IndexOf( "&md5sum", StringComparison.Ordinal ) );

              string md5CheckValue = GenerateMD5Hash( settings[ "md5Key1" ] + urlExceptMd5Sum + settings[ "md5Key2" ] ).ToUpperInvariant();

              if ( md5CheckValue == request.QueryString[ "md5sum" ] ) {
            HttpContext.Current.Response.Output.Write( "TRUE" );

            string transaction = request.QueryString[ "payread_payment_id" ];
            string paymentType = request.QueryString[ "payer_payment_type" ];
            string callbackType = request.QueryString[ "payer_callback_type" ];
            PaymentState paymentState = callbackType == "auth" ? PaymentState.Authorized : PaymentState.Captured;

            callbackInfo = new CallbackInfo( order.TotalPrice.Value.WithVat, transaction, paymentState, paymentType );
              } else {
            LoggingService.Instance.Log( "Payer(" + order.CartNumber + ") - MD5Sum security check failed" );
              }
            } else {
              LoggingService.Instance.Log( "Payer(" + order.CartNumber + ") - IP security check failed - IP: " + remoteServerIpAddress );
            }

            HttpContext.Current.Response.Output.Write( "FALSE" );
              } catch ( Exception exp ) {
            LoggingService.Instance.Log( exp, "QuickPay(" + order.CartNumber + ") - Process callback" );
              }

              return callbackInfo;
        }
        public override string GetCartNumber( HttpRequest request, IDictionary<string, string> settings )
        {
            string cartNumber = "";

              try {
            request.MustNotBeNull( "request" );
            settings.MustNotBeNull( "settings" );
            settings.MustContainKey( "md5HashKey", "settings" );
            settings.MustContainKey( "x_login", "settings" );

            //Write data when testing
            if ( settings.ContainsKey( "testing" ) && settings[ "testing" ] == "1" ) {
              LogRequest( request, logPostData: true );
            }

            string responseCode = request.Form[ "x_response_code" ];
            if ( responseCode == "1" ) {

              string amount = request.Form[ "x_amount" ];
              string transaction = request.Form[ "x_trans_id" ];

              string gatewayMd5Hash = request.Form[ "x_MD5_Hash" ];

              MD5CryptoServiceProvider x = new MD5CryptoServiceProvider();
              string calculatedMd5Hash = Regex.Replace( BitConverter.ToString( x.ComputeHash( Encoding.ASCII.GetBytes( settings[ "md5HashKey" ] + settings[ "x_login" ] + transaction + amount ) ) ), "-", string.Empty );

              if ( gatewayMd5Hash == calculatedMd5Hash ) {
            cartNumber = request.Form[ "x_invoice_num" ];
              } else {
            LoggingService.Instance.Log( "Authorize.net - MD5Sum security check failed - " + gatewayMd5Hash + " - " + calculatedMd5Hash + " - " + settings[ "md5HashKey" ] );
              }
            } else {
              LoggingService.Instance.Log( "Authorize.net - Payment not approved: " + responseCode );
            }
              } catch ( Exception exp ) {
            LoggingService.Instance.Log( exp, "Authorize.net - Get cart number" );
              }

              return cartNumber;
        }
Exemple #17
0
        public override CallbackInfo ProcessCallback( Order order, HttpRequest request, IDictionary<string, string> settings )
        {
            CallbackInfo callbackInfo = null;

              try {
            order.MustNotBeNull( "order" );
            request.MustNotBeNull( "request" );
            settings.MustNotBeNull( "settings" );
            settings.MustContainKey( "secretKey", "settings" );

            //Write data when testing
            if ( settings.ContainsKey( "testMode" ) && settings[ "testMode" ] == "1" ) {
              LogRequest<Paynova>( request, logPostData: true );
            }

            PostbackDigest postbackDigest = new PostbackDigest( settings[ "secretKey" ] );
            if ( order.CartNumber == request.Form[ "ORDER_NUMBER" ] && postbackDigest.Validate( request.Form ) ) {
              decimal amountAuthorized = decimal.Parse( request.Form[ "PAYMENT_1_AMOUNT" ], CultureInfo.InvariantCulture );
              string transaction = request.Form[ "PAYMENT_1_TRANSACTION_ID" ];
              string paymentType = request.Form[ "PAYMENT_1_PAYMENT_METHOD_NAME" ];
              string paymentIdentifier = request.Form[ "PAYMENT_1_CARD_LAST_FOUR" ];

              PaymentState? paymentState = null;
              switch ( request.Form[ "PAYMENT_1_STATUS" ] ) {
            case "Pending":
              paymentState = PaymentState.PendingExternalSystem;
              break;
            case "Completed":
            case "PartiallyCompleted":
              paymentState = PaymentState.Captured;
              break;
            case "Authorized":
              paymentState = PaymentState.Authorized;
              break;
              }

              if ( paymentState != null ) {
            callbackInfo = new CallbackInfo( amountAuthorized, transaction, paymentState.Value, paymentType, paymentIdentifier );
              }
            } else {
              LoggingService.Instance.Warn<Paynova>( "Paynova(" + order.CartNumber + ") - digest check failed" );
            }
              } catch ( Exception exp ) {
            LoggingService.Instance.Error<Paynova>( "Paynova(" + order.CartNumber + ") - Process callback", exp );
              }

              return callbackInfo;
        }
Exemple #18
0
        public override CallbackInfo ProcessCallback( Order order, HttpRequest request, IDictionary<string, string> settings )
        {
            CallbackInfo callbackInfo = null;

              try {
            order.MustNotBeNull( "order" );
            request.MustNotBeNull( "request" );
            settings.MustNotBeNull( "settings" );
            settings.MustContainKey( "SHAOUTPASSPHRASE", "settings" );

            //Write data when testing
            if ( settings.ContainsKey( "TESTMODE" ) && settings[ "TESTMODE" ] == "1" ) {
              LogRequest<Ogone>( request, logGetData: true );
            }

            Dictionary<string, string> inputFields = new Dictionary<string, string>();

            string shaSign = request.QueryString[ "SHASIGN" ];
            string strAmount = request.QueryString[ "AMOUNT" ];
            string transaction = request.QueryString[ "PAYID" ];
            string status = request.QueryString[ "STATUS" ];
            string cardType = request.QueryString[ "BRAND" ];
            string cardNo = request.QueryString[ "CARDNO" ];

            foreach ( string key in request.QueryString.Keys ) {
              if ( !key.Equals( "SHASIGN" ) )
            inputFields[ key ] = request.QueryString[ key ];
            }

            string strToHash = string.Join( "", inputFields.OrderBy( i => i.Key ).Select( i => i.Key.ToUpperInvariant() + "=" + i.Value + settings[ "SHAOUTPASSPHRASE" ] ) );
            string digest = new SHA512Managed().ComputeHash( Encoding.UTF8.GetBytes( strToHash ) ).ToHex().ToUpperInvariant();

            if ( order.CartNumber == request.QueryString[ "ORDERID" ] && digest.Equals( shaSign ) ) {
              callbackInfo = new CallbackInfo( decimal.Parse( strAmount, CultureInfo.InvariantCulture ), transaction, status == "5" || status == "51" ? PaymentState.Authorized : PaymentState.Captured, cardType, cardNo );
            } else {
              LoggingService.Instance.Warn<Ogone>( "Ogone(" + order.CartNumber + ") - SHASIGN check isn't valid - Calculated digest: " + digest + " - Ogone SHASIGN: " + shaSign );
            }
              } catch ( Exception exp ) {
            LoggingService.Instance.Error<Ogone>( "Ogone(" + order.CartNumber + ") - Process callback", exp );
              }

              return callbackInfo;
        }
Exemple #19
0
        public override CallbackInfo ProcessCallback( Order order, HttpRequest request, IDictionary<string, string> settings )
        {
            CallbackInfo callbackInfo = null;

              try {
            order.MustNotBeNull( "order" );
            request.MustNotBeNull( "request" );
            settings.MustNotBeNull( "settings" );
            settings.MustContainKey( "business", "settings" );

            //Write data when testing
            if ( settings.ContainsKey( "isSandbox" ) && settings[ "isSandbox" ] == "1" ) {
              LogRequest( request, logPostData: true );
            }

            //Verify callback
            string response = MakePostRequest( settings.ContainsKey( "isSandbox" ) && settings[ "isSandbox" ] == "1" ? "https://www.sandbox.paypal.com/cgi-bin/webscr" : "https://www.paypal.com/cgi-bin/webscr", Encoding.ASCII.GetString( request.BinaryRead( request.ContentLength ) ) + "&cmd=_notify-validate" );

            if ( settings.ContainsKey( "isSandbox" ) && settings[ "isSandbox" ] == "1" ) {
              using ( StreamWriter writer = new StreamWriter( File.Create( HostingEnvironment.MapPath( "~/paypal-callback-data-2.txt" ) ) ) ) {
            writer.WriteLine( response );
            writer.Flush();
              }
            }

            if ( response == "VERIFIED" ) {

              string receiverId = request.Form[ "receiver_id" ];
              string receiverEmail = request.Form[ "receiver_email" ];
              string transaction = request.Form[ "txn_id" ];
              decimal amount = decimal.Parse( request.Form[ "mc_gross" ], CultureInfo.InvariantCulture );
              string state = request.Form[ "payment_status" ];

              string businessSetting = settings[ "business" ];

              //Check if the business email is the same in the callback
              if ( !string.IsNullOrEmpty( transaction ) && ( ( !string.IsNullOrEmpty( receiverId ) && businessSetting == receiverId ) || ( !string.IsNullOrEmpty( receiverEmail ) && businessSetting == receiverEmail ) ) ) {

            //Pending
            if ( state == "Pending" ) {

              if ( request.Form[ "pending_reason" ] == "authorization" ) {
                if ( request.Form[ "transaction_entity" ] == "auth" ) {
                  callbackInfo = new CallbackInfo( amount, transaction, PaymentState.Authorized );
                }
              } else if ( request.Form[ "pending_reason" ] == "multi_currency" ) {
                callbackInfo = new CallbackInfo( amount, transaction, PaymentState.PendingExternalSystem );
              }

              //Completed - auto capture
            } else if ( state == "Completed" ) {
              callbackInfo = new CallbackInfo( amount, transaction, PaymentState.Captured );
            }
              } else {
            LoggingService.Instance.Log( "PayPal(" + order.CartNumber + ") - Business isn't identical - settings: " + businessSetting + " | request-receiverId: " + receiverId + " | request-receiverEmail: " + receiverEmail );
              }
            } else {
              LoggingService.Instance.Log( "PayPal(" + order.CartNumber + ") - Couldn't verify response: " + response );
            }
              } catch ( Exception exp ) {
            LoggingService.Instance.Log( exp, "PayPal(" + order.CartNumber + ") - Process callback" );
              }

              return callbackInfo;
        }