Beispiel #1
0
        public eGatewayResponse SubmitTransaction(string username, TransactionDetails details,
                                                  string description)
        {
            string requestID = PayflowUtility.RequestId;

            string user = PayflowUtility.AppSettings("PayflowUser"); 
            string vendor = PayflowUtility.AppSettings("PayflowVendor");
            string partner = PayflowUtility.AppSettings("PayflowPartner");
            string password = PayflowUtility.AppSettings("PayflowPassword");

            UserInfo userInfo = new UserInfo(user, vendor, partner, password);
            
            bool testServer;
            if (!Boolean.TryParse(PayflowUtility.AppSettings("PayflowTestServer"), out testServer))
                return eGatewayResponse.Error;
            
            string certPath = AppDomain.CurrentDomain.BaseDirectory;
            certPath += testServer ? @"bin\testcerts" : @"bin\certs";

            string host = PayflowUtility.AppSettings("PAYFLOW_HOST");

            PayflowConnectionData connection = new PayflowConnectionData(host, certPath);

            Invoice inv = new Invoice();

            string currency = PayflowUtility.AppSettings("PayflowCurrency");
            Currency amt = new Currency(details.Amount, currency);
            amt.Round = true;
            
            inv.Amt = amt;
            inv.CustRef = username;
            inv.Comment1 = username;

            BillTo bill = new BillTo();

            bill.FirstName = details.FirstName;
            bill.LastName = details.LastName;
            bill.Zip = details.Zip;
            bill.City = details.City;
            bill.State = details.State;
            bill.Street = details.Address;
            bill.PhoneNum = details.Phone;
            bill.BillToCountry = details.Country;
            
            inv.BillTo = bill;

            string cardNumber = details.CardNumber.Replace("-", String.Empty);
            
            string expMonth = details.CardExpirationMonth.ToString();
            if (expMonth.Length == 1)
                expMonth = "0" + expMonth;
            
            string expYear = details.CardExpirationYear.ToString();
            expYear = expYear.Substring(expYear.Length - 2);
            
            CreditCard cc = new CreditCard(cardNumber, expMonth + expYear);
            CardTender card = new CardTender(cc);

            SaleTransaction trans = new SaleTransaction(userInfo, connection, inv, card, requestID);

            trans.Verbosity = "MEDIUM";

            Response resp = trans.SubmitTransaction();
            if (resp != null)
            {
                Global.Logger.LogInfo("PayflowPro_SubmitTransaction_Request", resp.RequestString);
                Global.Logger.LogInfo("PayflowPro_SubmitTransaction_Response", resp.ResponseString);
                Global.Logger.LogInfo("PayflowPro_SubmitTransaction_Response_Normalized", resp.TransactionResponse.RespMsg);
                
                if (resp.TransactionResponse.Result == 0)
                {
                    int paymentHistoryID = Payments.SavePaymentHistory(username, "PayflowPro", details.Amount, description, resp.TransactionResponse.RespMsg, 1);

                    AffiliateCommission.ApplyCommission(username, paymentHistoryID, details.Amount, resp.TransactionResponse.RespMsg);

                    return eGatewayResponse.Approved;
                }
                else
                {
                    Payments.SavePaymentHistory(username, "PayflowPro", details.Amount, description, resp.TransactionResponse.RespMsg, 2);
                    return eGatewayResponse.Error;
                }
            }
            
            return eGatewayResponse.Error;
        }
Beispiel #2
0
        public eGatewayResponse SubmitTransaction(string username, TransactionDetails details,
                                                  string description)
        {
            String result = "";
            string strPost;
            strPost = String.Format("x_login={0}&x_tran_key={1}&x_method=CC&x_type=AUTH_CAPTURE"
                                    + "&x_amount={2}&x_delim_data=TRUE&x_delim_char=|&x_relay_response=FALSE"
                                    + "&x_card_num={3}&x_exp_date={4}&x_test_request={5}&x_version=3.1",
                                    Properties.Settings.Default.AuthorizeNetLogin,
                                    Properties.Settings.Default.AuthorizeNetTranKey,
                                    details.Amount, details.CardNumber,
                                    details.CardExpirationMonth.ToString() + details.CardExpirationYear.ToString(),
                                    Properties.Settings.Default.AuthorizeNetTest.ToString().ToUpper());

            Global.Logger.LogInfo("AuthorizeNet_SubmitTransaction", strPost);

            StreamWriter myWriter = null;

            HttpWebRequest objRequest = (HttpWebRequest) WebRequest.Create(
                                                             Properties.Settings.Default.AuthorizeNetTest.ToString()
                                                                 .ToUpper() == "TRUE"
                                                                 ? GATEWAY_URL_TEST
                                                                 : GATEWAY_URL);
            objRequest.Method = "POST";
            objRequest.ContentLength = strPost.Length;
            objRequest.ContentType = "application/x-www-form-urlencoded";

            try
            {
                myWriter = new StreamWriter(objRequest.GetRequestStream());
                myWriter.Write(strPost);
            }
            catch (Exception err)
            {
                Global.Logger.LogError("AuthorizeNet_SubmitTransaction", err);
                return eGatewayResponse.Error;
            }
            finally
            {
                myWriter.Close();
            }

            HttpWebResponse objResponse = (HttpWebResponse) objRequest.GetResponse();
            using (StreamReader sr =
                new StreamReader(objResponse.GetResponseStream()))
            {
                result = sr.ReadToEnd();
                sr.Close();
            }

            Global.Logger.LogInfo("AuthorizeNet_SubmitTransaction", result);

            string[] results = result.Split('|');
            int status = -1;
            try
            {
                status = Convert.ToInt32(results[0]);
            }
            catch (FormatException)
            {
            }

            int paymentHistoryID =
                Payments.SavePaymentHistory(username, "AuthorizeNet", details.Amount, description, result, status);
            
            if (status == 1)
            {
                AffiliateCommission.ApplyCommission(username, paymentHistoryID, details.Amount, result);
            }

            switch (status)
            {
                case 1:
                    return eGatewayResponse.Approved;
                case 2:
                    return eGatewayResponse.Declined;
                default:
                    return eGatewayResponse.Error;
            }
        }
Beispiel #3
0
        public eGatewayResponse SubmitTransaction(string username, TransactionDetails details, string description)
        {
            int status = 1; //Approved

            Payments.SavePaymentHistory(username, Name, details.Amount, description, String.Empty, status);

            return eGatewayResponse.Approved;
        }
Beispiel #4
0
 public static TransactionDetails FromBillingDetails(BillingDetails billingDetails)
 {
     TransactionDetails transactionDetails = new TransactionDetails();
     transactionDetails.FirstName = billingDetails.FirstName;
     transactionDetails.LastName = billingDetails.LastName;
     transactionDetails.Address = billingDetails.Address;
     transactionDetails.City = billingDetails.City;
     transactionDetails.State = billingDetails.State;
     transactionDetails.Zip = billingDetails.Zip;
     transactionDetails.Country = billingDetails.Country;
     transactionDetails.Phone = billingDetails.Phone;
     transactionDetails.CardNumber = billingDetails.CardNumber;
     transactionDetails.CardExpirationMonth = billingDetails.CardExpirationMonth;
     transactionDetails.CardExpirationYear = billingDetails.CardExpirationYear;
     return transactionDetails;
 }