コード例 #1
0
ファイル: SagePayments.cs プロジェクト: rossspoon/bvcms
        public TransactionResponse createCheckTransactionRequest(int PeopleId, decimal amt,
			string routing, string acct, string description, int tranid,
			string email, string first, string middle, string last, string suffix,
			string addr, string city, string state, string zip, string phone)
        {
            try
            {

                var wc = new WebClient();
                wc.BaseAddress = "https://www.sagepayments.net/web_services/vterm_extensions/transaction_processing.asmx/";
                var coll = new NameValueCollection();
                coll["M_ID"] = login;
                coll["M_KEY"] = key;
                coll["C_ORIGINATOR_ID"] = Db.Setting("SageOriginatorId", ""); // 1031360711, 1031412710
                coll["C_FIRST_NAME"] = first;
                coll["C_MIDDLE_INITIAL"] = middle.Truncate(1) ?? "";
                coll["C_LAST_NAME"] = last;
                coll["C_SUFFIX"] = suffix;
                coll["C_ADDRESS"] = addr;
                coll["C_CITY"] = city;
                coll["C_STATE"] = state;
                coll["C_ZIP"] = zip;
                coll["C_COUNTRY"] = "";
                coll["C_EMAIL"] = email;
                coll["C_RTE"] = routing;
                coll["C_ACCT"] = acct;
                coll["C_ACCT_TYPE"] = "DDA";
                coll["T_AMT"] = amt.ToString("n2");
                coll["T_ORDERNUM"] = tranid.ToString();
                coll["C_TELEPHONE"] = phone;
                AddShipping(coll);

                var b = wc.UploadValues("VIRTUAL_CHECK_PPD_SALE", "POST", coll);
                var ret = Encoding.ASCII.GetString(b);
                var resp = getResponse(ret);
                var tr = new TransactionResponse
                {
                    Approved = resp.Element("APPROVAL_INDICATOR").Value == "A",
                    AuthCode = resp.Element("CODE").Value,
                    Message = resp.Element("MESSAGE").Value,
                    TransactionId = resp.Element("REFERENCE").Value
                };
                return tr;
            }
            catch (Exception ex)
            {
                return new TransactionResponse { Approved = false, Message = ex.Message, };
            }
        }
コード例 #2
0
ファイル: SagePayments.cs プロジェクト: rossspoon/bvcms
        public TransactionResponse createVaultTransactionRequest(int PeopleId, decimal amt, string description, int tranid, string type)
        {
            var p = Db.LoadPersonById(PeopleId);
            var pi = p.PaymentInfo();
            if (pi == null)
                return new TransactionResponse
                {
                    Approved = false,
                    Message = "missing payment info",
                };

            XElement resp = null;
            if ((type ?? "B") == "B" && pi.SageBankGuid.HasValue) // Bank Account (check)
            {
                var wc = new WebClient();
                wc.BaseAddress = "https://www.sagepayments.net/web_services/wsVault/wsVaultVirtualCheck.asmx/";
                var coll = new NameValueCollection();

                coll["M_ID"] = login;
                coll["M_KEY"] = key;
                var guid = pi.SageBankGuid.ToString().Replace("-", "");
                coll["GUID"] = guid;
                coll["C_ORIGINATOR_ID"] = Db.Setting("SageOriginatorId", "");
                coll["C_FIRST_NAME"] = pi.FirstName ?? p.FirstName;
                coll["C_MIDDLE_INITIAL"] = (pi.MiddleInitial ?? p.MiddleName).Truncate(1) ?? "";
                coll["C_LAST_NAME"] = pi.LastName ?? p.LastName;
                coll["C_SUFFIX"] = pi.Suffix ?? p.SuffixCode;
                coll["C_ADDRESS"] = pi.Address ?? p.PrimaryAddress;
                coll["C_CITY"] = pi.City ?? p.PrimaryCity;
                coll["C_STATE"] = pi.State ?? p.PrimaryState;
                coll["C_ZIP"] = pi.Zip ?? p.PrimaryZip;
                coll["C_COUNTRY"] = p.PrimaryCountry;
                coll["C_EMAIL"] = p.EmailAddress;
                coll["T_AMT"] = amt.ToString("n2");
                coll["T_ORDERNUM"] = tranid.ToString();
                coll["C_TELEPHONE"] = pi.Phone;
                AddShipping(coll);

                var b = wc.UploadValues("VIRTUAL_CHECK_PPD_SALE", "POST", coll);
                var ret = Encoding.ASCII.GetString(b);
                resp = getResponse(ret);
            }
            else
            {
                var wc = new WebClient();
                wc.BaseAddress = "https://www.sagepayments.net/web_services/wsVault/wsVaultBankcard.asmx/";
                var coll = new NameValueCollection();

                coll["M_ID"] = login;
                coll["M_KEY"] = key;
                var guid = pi.SageCardGuid.ToString().Replace("-", "");
                coll["GUID"] = guid;
                coll["C_NAME"] = (pi.FirstName ?? p.FirstName) + (pi.MiddleInitial ?? p.MiddleName).Truncate(1) + (p.LastName ?? pi.LastName);
                coll["C_ADDRESS"] = pi.Address ?? p.PrimaryAddress;
                coll["C_CITY"] = pi.City ?? p.PrimaryCity;
                coll["C_STATE"] = pi.State ?? p.PrimaryState;
                coll["C_ZIP"] = pi.Zip ?? p.PrimaryZip;
                coll["C_COUNTRY"] = p.PrimaryCountry;
                coll["C_EMAIL"] = p.EmailAddress;
                coll["T_AMT"] = amt.ToString("n2");
                coll["T_ORDERNUM"] = tranid.ToString();
                coll["C_TELEPHONE"] = p.HomePhone;
                coll["T_CUSTOMER_NUMBER"] = p.PeopleId.ToString();
                coll["C_CVV"] = pi.Ccv;
                AddShipping(coll);

                var b = wc.UploadValues("VAULT_BANKCARD_SALE_CVV", "POST", coll);
                var ret = Encoding.ASCII.GetString(b);
                resp = getResponse(ret);
            }
            var tr = new TransactionResponse
            {
                Approved = resp.Element("APPROVAL_INDICATOR").Value == "A",
                AuthCode = resp.Element("CODE").Value,
                Message = resp.Element("MESSAGE").Value,
                TransactionId = resp.Element("REFERENCE").Value
            };
            return tr;
        }
コード例 #3
0
ファイル: SagePayments.cs プロジェクト: rossspoon/bvcms
 public TransactionResponse voidTransactionRequest(string reference)
 {
     var wc = new WebClient();
     wc.BaseAddress = "https://www.sagepayments.net/web_services/vterm_extensions/transaction_processing.asmx/";
     var coll = new NameValueCollection();
     coll["M_ID"] = login;
     coll["M_KEY"] = key;
     coll["T_REFERENCE"] = reference;
     var b = wc.UploadValues("BANKCARD_VOID", "POST", coll);
     var ret = Encoding.ASCII.GetString(b);
     var resp = getResponse(ret);
     var tr = new TransactionResponse
     {
         Approved = resp.Element("APPROVAL_INDICATOR").Value == "A",
         AuthCode = resp.Element("CODE").Value,
         Message = resp.Element("MESSAGE").Value,
         TransactionId = resp.Element("REFERENCE").Value
     };
     return tr;
 }
コード例 #4
0
ファイル: SagePayments.cs プロジェクト: rossspoon/bvcms
        public TransactionResponse createTransactionRequest(int PeopleId, decimal amt,
			string cardnumber, string expires, string description, int tranid, string cardcode,
			string email, string first, string last,
			string addr, string city, string state, string zip, string phone)
        {
            var wc = new WebClient();
            wc.BaseAddress = "https://www.sagepayments.net/web_services/vterm_extensions/transaction_processing.asmx/";
            var coll = new NameValueCollection();
            coll["M_ID"] = login;
            coll["M_KEY"] = key;
            coll["T_AMT"] = amt.ToString("n2");
            coll["C_NAME"] = first + " " + last;
            coll["C_ADDRESS"] = addr;
            coll["C_CITY"] = city;
            coll["C_STATE"] = state;
            coll["C_ZIP"] = zip;
            coll["C_COUNTRY"] = "";
            coll["C_EMAIL"] = email;
            coll["C_CARDNUMBER"] = cardnumber;
            coll["C_EXP"] = expires;
            coll["C_CVV"] = cardcode;
            coll["T_CUSTOMER_NUMBER"] = PeopleId.ToString();
            coll["T_ORDERNUM"] = tranid.ToString();
            coll["C_TELEPHONE"] = phone;
            AddShipping(coll);

            var b = wc.UploadValues("BANKCARD_SALE", "POST", coll);
            var ret = Encoding.ASCII.GetString(b);
            var resp = getResponse(ret);
            var tr = new TransactionResponse
            {
                Approved = resp.Element("APPROVAL_INDICATOR").Value == "A",
                AuthCode = resp.Element("CODE").Value,
                Message = resp.Element("MESSAGE").Value,
                TransactionId = resp.Element("REFERENCE").Value
            };
            return tr;
        }
コード例 #5
0
ファイル: AuthorizeNet.cs プロジェクト: hkouns/bvcms
        public TransactionResponse createTransactionRequest(int PeopleId, decimal amt, string cardnumber, string expires, string description, int tranid, string cardcode)
        {
            var p = Db.LoadPersonById(PeopleId);
            var request = new XDocument(new XDeclaration("1.0", "utf-8", null),
            Element("createTransactionRequest",
                Element("merchantAuthentication",
                    Element("name", login),
                    Element("transactionKey", key)
                    ),
                Element("transactionRequest",
                    Element("transactionType", "authCaptureTransaction"), // or refundTransaction or voidTransaction
                    Element("amount", amt),
                    Element("payment",
                        Element("creditCard",
                            Element("cardNumber", cardnumber),
                            Element("expirationDate", expires),
                            Element("cardCode", cardcode)
                            )
                        ),
                    Element("order",
                        Element("invoiceNumber", tranid),
                        Element("description", description)
                        ),
                    Element("customer",
                        Element("id", PeopleId),
                        Element("email", p.EmailAddress)
                        ),
                    Element("billTo",
                        Element("firstName", p.FirstName),
                        Element("lastName", p.LastName),
                        Element("address", p.PrimaryAddress),
                        Element("city", p.PrimaryCity),
                        Element("state", p.PrimaryState),
                        Element("zip", p.PrimaryZip),
                        Element("phoneNumber", p.HomePhone)
                        ),
                    Element("customerIP", Util.GetIPAddress())
                    )
                )
            );

            var x = getResponse(request.ToString());
            var resp = x.Descendants(ns + "transactionResponse").First();
            var tr = new TransactionResponse
            {
                Approved = resp.Element(ns + "responseCode").Value == "1",
                AuthCode = resp.Element(ns + "authCode").Value,
                Message = resp.Descendants(ns + "message").First().Element(ns + "description").Value,
                TransactionId = resp.Element(ns + "transId").Value
            };
            return tr;
        }
コード例 #6
0
ファイル: AuthorizeNet.cs プロジェクト: hkouns/bvcms
        public TransactionResponse createCustomerProfileTransactionRequest(int PeopleId, decimal amt, string description, int tranid)
        {
            var pi = Db.PaymentInfos.Single(pp => pp.PeopleId == PeopleId);
            if (pi == null)
                return new TransactionResponse
                {
                    Approved = false,
                    Message = "missing payment info",
                };
            var request = new XDocument(new XDeclaration("1.0", "utf-8", null),
            Element("createCustomerProfileTransactionRequest",
                Element("merchantAuthentication",
                    Element("name", login),
                    Element("transactionKey", key)
                    ),
                Element("refId", PeopleId),
                Element("transaction",
                    Element("profileTransAuthCapture",
                        Element("amount", amt),
                        Element("customerProfileId", pi.AuNetCustId),
                        Element("customerPaymentProfileId", pi.AuNetCustPayId),
                        Element("order",
                            Element("invoiceNumber", tranid),
                            Element("description", description)
                            ),
                        Element("cardCode", pi.Ccv)
                        )
                    )
                )
            );
            var x = getResponse(request.ToString());

            var resp = x.Descendants(ns + "directResponse").First().Value;
            var a = resp.Split('|');
            var tr = new TransactionResponse
            {
                Approved = a[0] == "1",
                Message = a[3],
                AuthCode = a[4],
                TransactionId = a[6]
            };
            return tr;
        }
コード例 #7
0
        public int DoGiving(CMSDataContext Db)
        {
            var          gateway = Db.Setting("TransactionGateway", "");
            AuthorizeNet anet    = null;
            SagePayments sage    = null;

            if (gateway == "AuthorizeNet")
            {
                anet = new AuthorizeNet(Db, testing: false);
            }
            else if (gateway == "Sage")
            {
                sage = new SagePayments(Db, testing: false);
            }
            else
            {
                return(0);
            }

            TransactionResponse ret = null;
            var total = (from a in Db.RecurringAmounts
                         where a.PeopleId == PeopleId
                         where a.ContributionFund.FundStatusId == 1
                         select a.Amt).Sum();

            if (!total.HasValue || total == 0)
            {
                return(0);
            }

            var preferredtype = (from pi in Db.PaymentInfos
                                 where pi.PeopleId == PeopleId
                                 select pi.PreferredGivingType).Single();

            var t = new Transaction
            {
                TransactionDate    = DateTime.Now,
                TransactionId      = "started",
                First              = Person.FirstName,
                MiddleInitial      = Person.MiddleName.Truncate(1) ?? "",
                Last               = Person.LastName,
                Suffix             = Person.SuffixCode,
                Amt                = total,
                Description        = "Recurring Giving",
                Testing            = false,
                TransactionGateway = gateway,
                Financeonly        = true
            };

            Db.Transactions.InsertOnSubmit(t);
            Db.SubmitChanges();

            if (gateway == "AuthorizeNet")
            {
                ret = anet.createCustomerProfileTransactionRequest(PeopleId, total ?? 0, "Recurring Giving", t.Id);
            }
            else
            {
                ret = sage.createVaultTransactionRequest(PeopleId, total ?? 0, "Recurring Giving", t.Id, preferredtype);
            }

            t.Message       = ret.Message;
            t.AuthCode      = ret.AuthCode;
            t.Approved      = ret.Approved;
            t.TransactionId = ret.TransactionId;
            var systemEmail = Db.Setting("SystemEmailAddress", "*****@*****.**");

            var contributionemail = (from ex in Person.PeopleExtras
                                     where ex.Field == "ContributionEmail"
                                     select ex.Data).SingleOrDefault();

            if (contributionemail.HasValue())
            {
                contributionemail = contributionemail.Trim();
            }
            if (!Util.ValidEmail(contributionemail))
            {
                contributionemail = Person.FromEmail;
            }
            var gift   = Db.Setting("NameForPayment", "gift");
            var church = Db.Setting("NameOfChurch", Db.CmsHost);

            if (ret.Approved)
            {
                var q = from a in Db.RecurringAmounts
                        where a.PeopleId == PeopleId
                        select a;

                foreach (var a in q)
                {
                    if (a.ContributionFund.FundStatusId == 1 && a.Amt > 0)
                    {
                        Person.PostUnattendedContribution(Db, a.Amt ?? 0, a.FundId, "Recurring Giving", tranid: t.Id);
                    }
                }
                var tot = q.Where(aa => aa.ContributionFund.FundStatusId == 1).Sum(aa => aa.Amt);
                t.TransactionPeople.Add(new TransactionPerson
                {
                    PeopleId = Person.PeopleId,
                    Amt      = tot,
                });
                NextDate = FindNextDate(Util.Now.Date.AddDays(1));
                Db.SubmitChanges();
                if (tot > 0)
                {
                    Util.SendMsg(systemEmail, Db.CmsHost, Util.TryGetMailAddress(contributionemail),
                                 "Recurring {0} for {1}".Fmt(gift, church),
                                 "Your payment of ${0:N2} was processed this morning.".Fmt(tot),
                                 Util.ToMailAddressList(contributionemail), 0, null);
                }
            }
            else
            {
                Db.SubmitChanges();
                var failedGivingMessage = Db.ContentHtml("FailedGivingMessage", Resources.ManagedGiving_FailedGivingMessage);
                var adminEmail          = Db.Setting("AdminMail", systemEmail);
                Util.SendMsg(systemEmail, Db.CmsHost, Util.TryGetMailAddress(contributionemail),
                             "Recurring {0} failed for {1}".Fmt(gift, church),
                             failedGivingMessage.Replace("{first}", Person.PreferredName),
                             Util.ToMailAddressList(contributionemail), 0, null);
                foreach (var p in Db.FinancePeople())
                {
                    Util.SendMsg(systemEmail, Db.CmsHost, Util.TryGetMailAddress(adminEmail),
                                 "Recurring Giving Failed on " + Db.CmsHost,
                                 "<a href='{0}Transactions/{2}'>message: {1}, tranid:{2}</a>".Fmt(Db.CmsHost, ret.Message, t.Id),
                                 Util.ToMailAddressList(p.EmailAddress), 0, null);
                }
            }
            return(1);
        }
コード例 #8
0
ファイル: SagePayments.cs プロジェクト: davidbwire/bvcms
        public TransactionResponse createVaultTransactionRequest(int PeopleId, decimal amt, string description, int tranid, string type)
        {
            var p  = Db.LoadPersonById(PeopleId);
            var pi = p.PaymentInfo();

            if (pi == null)
            {
                return new TransactionResponse
                       {
                           Approved = false,
                           Message  = "missing payment info",
                       }
            }
            ;

            XElement resp = null;

            if ((type ?? "B") == "B" && pi.SageBankGuid.HasValue)             // Bank Account (check)
            {
                var wc = new WebClient();

                wc.BaseAddress = "https://www.sagepayments.net/web_services/wsVault/wsVaultVirtualCheck.asmx/";
                var coll = new NameValueCollection();

                coll["M_ID"]  = login;
                coll["M_KEY"] = key;
                var guid = pi.SageBankGuid.ToString().Replace("-", "");
                coll["GUID"]             = guid;
                coll["C_ORIGINATOR_ID"]  = Db.Setting("SageOriginatorId", "");
                coll["C_FIRST_NAME"]     = pi.FirstName ?? p.FirstName;
                coll["C_MIDDLE_INITIAL"] = (pi.MiddleInitial ?? p.MiddleName).Truncate(1) ?? "";
                coll["C_LAST_NAME"]      = pi.LastName ?? p.LastName;
                coll["C_SUFFIX"]         = pi.Suffix ?? p.SuffixCode;
                coll["C_ADDRESS"]        = pi.Address ?? p.PrimaryAddress;
                coll["C_CITY"]           = pi.City ?? p.PrimaryCity;
                coll["C_STATE"]          = pi.State ?? p.PrimaryState;
                coll["C_ZIP"]            = pi.Zip ?? p.PrimaryZip;
                coll["C_COUNTRY"]        = p.PrimaryCountry;
                coll["C_EMAIL"]          = p.EmailAddress;
                coll["T_AMT"]            = amt.ToString("n2");
                coll["T_ORDERNUM"]       = tranid.ToString();
                coll["C_TELEPHONE"]      = pi.Phone;
                AddShipping(coll);

                var b   = wc.UploadValues("VIRTUAL_CHECK_PPD_SALE", "POST", coll);
                var ret = Encoding.ASCII.GetString(b);
                resp = getResponse(ret);
            }
            else
            {
                var wc = new WebClient();
                wc.BaseAddress = "https://www.sagepayments.net/web_services/wsVault/wsVaultBankcard.asmx/";
                var coll = new NameValueCollection();

                coll["M_ID"]  = login;
                coll["M_KEY"] = key;
                var guid = pi.SageCardGuid.ToString().Replace("-", "");
                coll["GUID"]              = guid;
                coll["C_NAME"]            = (pi.FirstName ?? p.FirstName) + (pi.MiddleInitial ?? p.MiddleName).Truncate(1) + (p.LastName ?? pi.LastName);
                coll["C_ADDRESS"]         = pi.Address ?? p.PrimaryAddress;
                coll["C_CITY"]            = pi.City ?? p.PrimaryCity;
                coll["C_STATE"]           = pi.State ?? p.PrimaryState;
                coll["C_ZIP"]             = pi.Zip ?? p.PrimaryZip;
                coll["C_COUNTRY"]         = p.PrimaryCountry;
                coll["C_EMAIL"]           = p.EmailAddress;
                coll["T_AMT"]             = amt.ToString("n2");
                coll["T_ORDERNUM"]        = tranid.ToString();
                coll["C_TELEPHONE"]       = p.HomePhone;
                coll["T_CUSTOMER_NUMBER"] = p.PeopleId.ToString();
                coll["C_CVV"]             = pi.Ccv;
                AddShipping(coll);

                var b   = wc.UploadValues("VAULT_BANKCARD_SALE_CVV", "POST", coll);
                var ret = Encoding.ASCII.GetString(b);
                resp = getResponse(ret);
            }
            var tr = new TransactionResponse
            {
                Approved      = resp.Element("APPROVAL_INDICATOR").Value == "A",
                AuthCode      = resp.Element("CODE").Value,
                Message       = resp.Element("MESSAGE").Value,
                TransactionId = resp.Element("REFERENCE").Value
            };

            return(tr);
        }