Esempio n. 1
0
		public MobilePaymentInfo populate(PaymentInfo pi, int newType )
		{
			type = newType;

			switch( newType )
			{
				case TYPE_BANK_ACCOUNT:
					masked = pi.MaskedAccount;
					break;

				case TYPE_CREDIT_CARD:
					masked = pi.MaskedCard;
					break;
			}

			return this;
		}
Esempio n. 2
0
        private IGateway GetGateway(CMSDataContext db, PaymentInfo pi)
        {
            var tempgateway = db.Setting("TemporaryGateway", "");

            if (!tempgateway.HasValue())
                return db.Gateway();

            var gateway = db.Setting("TransactionGateway", "");
            switch (gateway.ToLower()) // Check to see if standard gateway is set up
            {
                case "sage":
                    if ((pi.PreferredGivingType == "B" && pi.SageBankGuid.HasValue) ||
                        (pi.PreferredGivingType == "C" && pi.SageCardGuid.HasValue))
                        return db.Gateway();
                    break;
                case "transnational":
                    if ((pi.PreferredGivingType == "B" && pi.TbnBankVaultId.HasValue) ||
                        (pi.PreferredGivingType == "C" && pi.TbnCardVaultId.HasValue))
                        return db.Gateway();
                    break;
            }

            // fall back to temporary gateway because the user hasn't migrated their payments off of the temporary gateway yet
            return db.Gateway(usegateway: tempgateway);
        }
Esempio n. 3
0
        public static PaymentForm CreatePaymentFormForBalanceDue(Transaction ti)
        {
            PaymentInfo pi = null;
            if (ti.Person != null && string.Equals(OnlineRegModel.GetTransactionGateway(),
                        "Sage", StringComparison.InvariantCultureIgnoreCase))
                pi = ti.Person.PaymentInfos.FirstOrDefault();
            if (pi == null)
                pi = new PaymentInfo();
            var pf = new PaymentForm
                     {
                         PayBalance = true,
                         AmtToPay = ti.Amtdue ?? 0,
                         Amtdue = ti.Amtdue ?? 0,
                         AllowCoupon = true,
                         AskDonation = false,
                         Description = ti.Description,
                         OrgId = ti.OrgId,
                         OriginalId = ti.OriginalId,
                         Email = Util.FirstAddress(ti.Emails).Address,

                         First = ti.First,
                         MiddleInitial = ti.MiddleInitial.Truncate(1) ?? "",
                         Last = ti.Last,
                         Suffix = ti.Suffix,

                         Phone = ti.Phone,
                         Address = ti.Address,
                         City = ti.City,
                         State = ti.State,
                         Zip = ti.Zip,
                         timeout = 6000000,
                         testing = ti.Testing ?? false,
                         TranId = ti.Id,
            #if DEBUG2
                         CreditCard = "4111111111111111",
                         CCV = "123",
                         Expires = "1015",
                         Routing = "056008849",
                         Account = "12345678901234"
            #else
                         CreditCard = pi.MaskedCard,
                         MaskedCCV = Util.Mask(new StringBuilder(pi.Ccv), 0),
                         CCV = pi.Ccv,
                         Expires = pi.Expires,
                         Account = pi.MaskedAccount,
                         Routing = pi.Routing,
                         SavePayInfo =
                            (pi.MaskedAccount != null && pi.MaskedAccount.StartsWith("X"))
                            || (pi.MaskedCard != null && pi.MaskedCard.StartsWith("X")),
            #endif
                     };
            pf.Type = pf.NoEChecksAllowed ? "C" : "";
            return pf;
        }
Esempio n. 4
0
		private void detach_PaymentInfos(PaymentInfo entity)
		{
			this.SendPropertyChanging();
			entity.Person = null;
		}
Esempio n. 5
0
        public void storeVault(int PeopleId, 
			string type, string cardnumber, string expires, string cardcode,
			string routing, string account, bool giving)
        {
            var p = Db.LoadPersonById(PeopleId);
            var pi = p.PaymentInfo();
            if (pi == null)
            {
                pi = new PaymentInfo();
                p.PaymentInfos.Add(pi);
            }
            var wc = new WebClient();
            wc.BaseAddress = "https://www.sagepayments.net/web_services/wsVault/wsVault.asmx/";
            var coll = new NameValueCollection();
            coll["M_ID"] = login;
            coll["M_KEY"] = key;

            XElement resp = null;
            if (type == "C")
            {
                coll["CARDNUMBER"] = cardnumber;
                coll["EXPIRATION_DATE"] = expires;

                if (pi.SageCardGuid == null)
                {
                    var b = wc.UploadValues("INSERT_CREDIT_CARD_DATA", "POST", coll);
                    var ret = Encoding.ASCII.GetString(b);
                    resp = getResponse(ret);
                    pi.SageCardGuid = Guid.Parse(resp.Element("GUID").Value);
                }
                else
                {
                    coll["GUID"] = pi.SageCardGuid.ToString().Replace("-", "");
                    if (!cardnumber.StartsWith("X"))
                    {
                        var b = wc.UploadValues("UPDATE_CREDIT_CARD_DATA", "POST", coll);
                        var ret = Encoding.ASCII.GetString(b);
                        resp = getResponse(ret);
                    }
                    else
                    {
                        var b = wc.UploadValues("UPDATE_CREDIT_CARD_EXPIRATION_DATE", "POST", coll);
                        var ret = Encoding.ASCII.GetString(b);
                        resp = getResponse(ret);
                    }
                }
            }
            else
            {
                coll["ROUTING_NUMBER"] = routing; // 064000020
                coll["ACCOUNT_NUMBER"] = account; // my account number
                coll["C_ACCT_TYPE"] = "DDA";

                if (pi.SageBankGuid == null)
                {
                    var b = wc.UploadValues("INSERT_VIRTUAL_CHECK_DATA", "POST", coll);
                    var ret = Encoding.ASCII.GetString(b);
                    resp = getResponse(ret);
                    pi.SageBankGuid = Guid.Parse(resp.Element("GUID").Value);
                }
                else
                {
                    if (!account.StartsWith("X"))
                    {
                        coll["GUID"] = pi.SageBankGuid.ToString().Replace("-", "");
                        var b = wc.UploadValues("UPDATE_VIRTUAL_CHECK_DATA", "POST", coll);
                        var ret = Encoding.ASCII.GetString(b);
                        resp = getResponse(ret);
                    }
                }
            }
            pi.MaskedAccount = Util.MaskAccount(account);
            pi.Routing = Util.Mask(new StringBuilder(routing), 2);
            pi.MaskedCard = Util.MaskCC(cardnumber);
            pi.Ccv = cardcode;
            pi.Expires = expires;
            pi.Testing = testing;
            if (giving)
                pi.PreferredGivingType = type;
            else
                pi.PreferredPaymentType = type;
            Db.SubmitChanges();
            //var sw =new StringWriter();
            //ObjectDumper.Write(pi, 0, sw);

            //Util.SendMsg(DbUtil.AdminMail, Db.CmsHost, Util.TryGetMailAddress("*****@*****.**"), "Sage Vault",
            //	"<a href='{0}{1}'>{2}</a><br>{3},{4}<br><pre>{5}</pre>".Fmt(
            //	Db.CmsHost, p.PeopleId, p.Name, type, giving ? "giving" : "regular", sw.ToString()),
            //	Util.ToMailAddressList("*****@*****.**"), 0, null);
        }
Esempio n. 6
0
 private void PopulateBillingName(PaymentInfo pi)
 {
     FirstName = pi.FirstName ?? person.FirstName;
     Middle = (pi.MiddleInitial ?? person.MiddleName).Truncate(1);
     LastName = pi.LastName ?? person.LastName;
     Suffix = pi.Suffix ?? person.SuffixCode;
 }
Esempio n. 7
0
        public ManageGivingModel(int pid, int orgid = 0)
            : this()
        {
            this.pid = pid;
            this.orgid = orgid;
            var rg = person.ManagedGiving();
            var pi = person.PaymentInfo();
            if (rg != null && pi != null)
            {
                SemiEvery = rg.SemiEvery;
                StartWhen = rg.StartWhen;
                StopWhen = null; //rg.StopWhen;
                Day1 = rg.Day1;
                Day2 = rg.Day2;
                EveryN = rg.EveryN;
                Period = rg.Period;
                foreach (var ra in person.RecurringAmounts.AsEnumerable())
                    FundItem.Add(ra.FundId, ra.Amt);
                Cardnumber = pi.MaskedCard;
                Account = pi.MaskedAccount;
                Expires = pi.Expires;
                Cardcode = Util.Mask(new StringBuilder(pi.Ccv), 0);
                Routing = Util.Mask(new StringBuilder(pi.Routing), 2);
                NextDate = rg.NextDate;
                NoCreditCardsAllowed = DbUtil.Db.Setting("NoCreditCardGiving", "false").ToBool();
                Type = pi.PreferredGivingType;
                if (NoCreditCardsAllowed)
                    Type = "B"; // bank account only
                else if (NoEChecksAllowed)
                    Type = "C"; // credit card only
                Type = NoEChecksAllowed ? "C" : Type;
            }
            else if (setting.ExtraValueFeeName.HasValue())
            {
                var f = CmsWeb.Models.OnlineRegPersonModel.Funds().SingleOrDefault(ff => ff.Text == setting.ExtraValueFeeName);
                // reasonable defaults
                Period = "M";
                SemiEvery = "E";
                EveryN = 1;
                var evamt = person.GetExtra(setting.ExtraValueFeeName).ToDecimal();
                if (f != null && evamt > 0)
                    FundItem.Add(f.Value.ToInt(), evamt);
            }
            if (pi == null)
                pi = new PaymentInfo();
            firstname = pi.FirstName ?? person.FirstName;
            middleinitial = (pi.MiddleInitial ?? person.MiddleName).Truncate(1);
            lastname = pi.LastName ?? person.LastName;
            suffix = pi.Suffix ?? person.SuffixCode;
            address = pi.Address ?? person.PrimaryAddress;
            city = pi.City ?? person.PrimaryCity;
            state = pi.State ?? person.PrimaryState;
            zip = pi.Zip ?? person.PrimaryZip;
            phone = pi.Phone ?? person.HomePhone ?? person.CellPhone;

            total = FundItem.Sum(ff => ff.Value) ?? 0;
        }
Esempio n. 8
0
        private void ClearMaskedNumbers(PaymentInfo pi)
        {
            var gateway = DbUtil.Db.Setting("TransactionGateway", "");

            var clearBankDetails = false;
            var clearCreditCardDetails = false;

            switch (gateway.ToLower())
            {
                case "sage":
                    clearBankDetails = !pi.SageBankGuid.HasValue;
                    clearCreditCardDetails = !pi.SageCardGuid.HasValue;
                    break;
                case "transnational":
                    clearBankDetails = !pi.TbnBankVaultId.HasValue;
                    clearCreditCardDetails = !pi.TbnCardVaultId.HasValue;
                    break;
                case "authorizenet":
                    clearBankDetails = !pi.AuNetCustPayBankId.HasValue;
                    clearCreditCardDetails = !pi.AuNetCustPayId.HasValue;
                    break;
                case "bluepay":
                    clearCreditCardDetails = !String.IsNullOrEmpty(pi.BluePayCardVaultId);
                    //TODO: Handle bank account too.
                    break;
            }

            if (clearBankDetails)
            {
                Account = string.Empty;
                Routing = string.Empty;
            }

            if (clearCreditCardDetails)
            {
                CreditCard = string.Empty;
                CVV = string.Empty;
                Expires = string.Empty;
            }
        }
Esempio n. 9
0
 private void PopulateBillingAddress(PaymentInfo pi)
 {
     Address = pi.Address ?? person.PrimaryAddress;
     Address2 = pi.Address2 ?? person.PrimaryAddress2;
     City = pi.City ?? person.PrimaryCity;
     State = pi.State ?? person.PrimaryState;
     Country = pi.Country ?? person.PrimaryCountry;
     Zip = pi.Zip ?? person.PrimaryZip;
     Phone = pi.Phone ?? person.HomePhone ?? person.CellPhone;
 }
Esempio n. 10
0
        public void AddUpdateCustomerProfile(int PeopleId,
			string type,
			string cardnumber,
			string expires,
			string cardcode,
			string routing,
			string account)
        {
            var exp = expires;
            if (exp.HasValue())
                exp = "20" + expires.Substring(2, 2) + "-" + expires.Substring(0, 2);
            var p = Db.LoadPersonById(PeopleId);
            var pi = p.PaymentInfo();
            if (pi == null)
            {
                pi = new PaymentInfo();
                p.PaymentInfos.Add(pi);
            }
            if (pi.AuNetCustId == null) // create a new profilein Authorize.NET CIM
            {
                XDocument request = null;
                if (type == "B")
                {
                    request = new XDocument(new XDeclaration("1.0", "utf-8", null),
                        Element("createCustomerProfileRequest",
                            Element("merchantAuthentication",
                                Element("name", login),
                                Element("transactionKey", key)
                                ),
                            Element("profile",
                                Element("merchantCustomerId", PeopleId),
                                Element("email", p.EmailAddress),
                                Element("paymentProfiles",
                                    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("payment",
                                        Element("bankAccount",
                                            Element("routingNumber", routing),
                                            Element("accountNumber", account),
                                            Element("nameOnAccount", p.Name)
                                            )
                                        )
                                    )
                                )
                            )
                        );
                }
                else
                {
                    request = new XDocument(new XDeclaration("1.0", "utf-8", null),
                    Element("createCustomerProfileRequest",
                        Element("merchantAuthentication",
                            Element("name", login),
                            Element("transactionKey", key)
                            ),
                        Element("profile",
                            Element("merchantCustomerId", PeopleId),
                            Element("email", p.EmailAddress),
                            Element("paymentProfiles",
                                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("payment",
                                    Element("creditCard",
                                        Element("cardNumber", cardnumber),
                                        Element("expirationDate", exp),
                                        Element("cardCode", cardcode)
                                        )
                                    )
                                )
                            )
                        )
                    );
                }
                var s = request.ToString();
                var x = getResponse(s);
                var id = x.Descendants(ns + "customerProfileId").First().Value.ToInt();
                var pid = x.Descendants(ns + "customerPaymentProfileIdList")
                            .Descendants(ns + "numericString").First().Value.ToInt();
                pi.AuNetCustId = id;
                pi.AuNetCustPayId = pid;
            }
            else
            {
                if (account.HasValue() && account.StartsWith("X"))
                {
                    var xe = getCustomerPaymentProfile(PeopleId);
                    var xba = xe.Descendants(ns + "bankAccount").Single();
                    routing = xba.Element(ns + "routingNumber").Value;
                    account = xba.Element(ns + "accountNumber").Value;
                }

                var request = new XDocument(new XDeclaration("1.0", "utf-8", null),
                    Element("updateCustomerProfileRequest",
                        Element("merchantAuthentication",
                            Element("name", login),
                            Element("transactionKey", key)
                            ),
                        Element("profile",
                            Element("merchantCustomerId", PeopleId),
                            Element("email", p.EmailAddress),
                            Element("customerProfileId", pi.AuNetCustId)
                            )
                    )
                );
                var x = getResponse(request.ToString());
                if (type == "B")
                    request = new XDocument(new XDeclaration("1.0", "utf-8", null),
                        Element("updateCustomerPaymentProfileRequest",
                            Element("merchantAuthentication",
                                Element("name", login),
                                Element("transactionKey", key)
                                ),
                            Element("customerProfileId", pi.AuNetCustId),
                            Element("paymentProfile",
                                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("payment",
                                    Element("bankAccount",
                                        Element("routingNumber", routing),
                                        Element("accountNumber", account),
                                        Element("nameOnAccount", p.Name)
                                        )
                                    ),
                                Element("customerPaymentProfileId", pi.AuNetCustPayId)
                            )
                        )
                    );
                else
                    request = new XDocument(new XDeclaration("1.0", "utf-8", null),
                        Element("updateCustomerPaymentProfileRequest",
                            Element("merchantAuthentication",
                                Element("name", login),
                                Element("transactionKey", key)
                                ),
                            Element("customerProfileId", pi.AuNetCustId),
                            Element("paymentProfile",
                                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("payment",
                                    Element("creditCard",
                                        Element("cardNumber", cardnumber),
                                        Element("expirationDate", exp),
                                        Element("cardCode", cardcode)
                                        )
                                    ),
                                Element("customerPaymentProfileId", pi.AuNetCustPayId)
                            )
                        )
                    );
                x = getResponse(request.ToString());
            }
            pi.MaskedAccount = Util.MaskAccount(account);
            pi.MaskedCard = Util.MaskCC(cardnumber);
            pi.Ccv = cardcode;
            pi.Expires = expires;
            Db.SubmitChanges();
        }
Esempio n. 11
0
        public void Update()
        {
            // first check for total amount greater than zero.
            // if so we skip everything except updating the amounts.
            var chosenFunds = FundItemsChosen().ToList();
            if (chosenFunds.Sum(f => f.amt) > 0)
            {
                var pi = person.PaymentInfo();
                if (pi == null)
                {
                    pi = new PaymentInfo();
                    person.PaymentInfos.Add(pi);
                }
                pi.SetBillingAddress(FirstName, Middle, LastName, Suffix, Address, Address2, City, State, Country, Zip, Phone);

                // first need to do a $1 auth if it's a credit card and throw any errors we get back
                // from the gateway.
                var vaultSaved = false;
                var gateway = DbUtil.Db.Gateway(testing);
                if (Type == PaymentType.CreditCard)
                {
                    // perform $1 auth.
                    // need to randomize the $1 amount because some gateways will reject same auth amount
                    // subsequent times per user.
                    var random = new Random();
                    var dollarAmt = (decimal)random.Next(100, 199) / 100;

                    TransactionResponse transactionResponse;
                    if (CreditCard.StartsWith("X"))
                    {
                        // store payment method in the gateway vault first before doing the auth.
                        gateway.StoreInVault(pid, Type, CreditCard, Expires, CVV, Routing, Account, giving: true);
                        vaultSaved = true;
                        transactionResponse = gateway.AuthCreditCardVault(pid, dollarAmt, "Recurring Giving Auth", 0);
                    }
                    else
                        transactionResponse = gateway.AuthCreditCard(pid, dollarAmt, CreditCard, Expires,
                            "Recurring Giving Auth", 0, CVV, string.Empty,
                            FirstName, LastName, Address, Address2, City, State, Country, Zip, Phone);

                    if (!transactionResponse.Approved)
                        throw new Exception(transactionResponse.Message);

                    // if we got this far that means the auth worked so now let's do a void for that auth.
                    var voidResponse = gateway.VoidCreditCardTransaction(transactionResponse.TransactionId);
                }

                // store payment method in the gateway vault if not already saved.
                if (!vaultSaved)
                    gateway.StoreInVault(pid, Type, CreditCard, Expires, CVV, Routing, Account, giving: true);

                // save all the managed giving data.
                var mg = person.ManagedGiving();
                if (mg == null)
                {
                    mg = new ManagedGiving();
                    person.ManagedGivings.Add(mg);
                }
                mg.SemiEvery = SemiEvery;
                mg.Day1 = Day1;
                mg.Day2 = Day2;
                mg.EveryN = EveryN;
                mg.Period = Period;
                mg.StartWhen = StartWhen;
                mg.StopWhen = StopWhen;
                mg.NextDate = mg.FindNextDate(DateTime.Today);
            }

            DbUtil.Db.RecurringAmounts.DeleteAllOnSubmit(person.RecurringAmounts);
            DbUtil.Db.SubmitChanges();

            person.RecurringAmounts.AddRange(chosenFunds.Select(c => new RecurringAmount { FundId = c.fundid, Amt = c.amt }));
            DbUtil.Db.SubmitChanges();
        }
Esempio n. 12
0
 private void InitializePaymentInfo(int peopleId)
 {
     var person = DbUtil.Db.LoadPersonById(peopleId);
     var pi = person.PaymentInfo();
     if (pi == null)
     {
         pi = new PaymentInfo();
         person.PaymentInfos.Add(pi);
     }
     pi.SetBillingAddress(First, MiddleInitial, Last, Suffix, Address, Address2, City,
         State, Country, Zip, Phone);
 }
Esempio n. 13
0
        private static void ClearMaskedNumbers(PaymentForm pf, PaymentInfo pi)
        {
            var gateway = DbUtil.Db.Setting("TransactionGateway", "");

            var clearBankDetails = false;
            var clearCreditCardDetails = false;

            switch (gateway.ToLower())
            {
                case "sage":
                    clearBankDetails = !pi.SageBankGuid.HasValue;
                    clearCreditCardDetails = !pi.SageCardGuid.HasValue;
                    break;
                case "transnational":
                    clearBankDetails = !pi.TbnBankVaultId.HasValue;
                    clearCreditCardDetails = !pi.TbnCardVaultId.HasValue;
                    break;
                case "authorizenet":
                    clearBankDetails = !pi.AuNetCustPayBankId.HasValue;
                    clearCreditCardDetails = !pi.AuNetCustPayId.HasValue;
                    break;
            }

            if (clearBankDetails)
            {
                pf.Account = string.Empty;
                pf.Routing = string.Empty;
            }

            if (clearCreditCardDetails)
            {
                pf.CreditCard = string.Empty;
                pf.CVV = string.Empty;
                pf.Expires = string.Empty;
            }
        }
Esempio n. 14
0
        public static PaymentForm CreatePaymentFormForBalanceDue(Transaction ti, decimal amtdue, string email)
        {
            PaymentInfo pi = null;
            if (ti.Person != null)
                pi = ti.Person.PaymentInfos.FirstOrDefault();
            if (pi == null)
                pi = new PaymentInfo();

            var pf = new PaymentForm
            {
                URL = ti.Url,
                PayBalance = true,
                AmtToPay = amtdue,
                Amtdue = 0,
                AllowCoupon = true,
                AskDonation = false,
                Description = ti.Description,
                OrgId = ti.OrgId,
                OriginalId = ti.OriginalId,
                Email = Util.FirstAddress(ti.Emails ?? email).Address,
                FormId = Guid.NewGuid(),
                First = ti.First,
                MiddleInitial = ti.MiddleInitial.Truncate(1) ?? "",
                Last = ti.Last,
                Suffix = ti.Suffix,
                Phone = ti.Phone,
                Address = ti.Address,
                Address2 = ti.Address2,
                City = ti.City,
                State = ti.State,
                Country = ti.Country,
                Zip = ti.Zip,
                testing = ti.Testing ?? false,
                TranId = ti.Id
            };

            if (pi.PeopleId == Util.UserPeopleId) // Is this the logged in user?
            {
                pf.CreditCard = pi.MaskedCard;
                pf.Expires = pi.Expires;
                pf.Account = pi.MaskedAccount;
                pf.Routing = pi.Routing;
                pf.SavePayInfo =
                    (pi.MaskedAccount != null && pi.MaskedAccount.StartsWith("X"))
                    || (pi.MaskedCard != null && pi.MaskedCard.StartsWith("X"));
            }

            ClearMaskedNumbers(pf, pi);

            pf.Type = pf.NoEChecksAllowed ? PaymentType.CreditCard : "";
            var org = DbUtil.Db.LoadOrganizationById(ti.OrgId);
            return pf;
        }
Esempio n. 15
0
        public void AddUpdateCustomerProfile(int PeopleId,
                                             string type,
                                             string cardnumber,
                                             string expires,
                                             string cardcode,
                                             string routing,
                                             string account)
        {
            var exp = expires;

            if (exp.HasValue())
            {
                exp = "20" + expires.Substring(2, 2) + "-" + expires.Substring(0, 2);
            }
            var p  = Db.LoadPersonById(PeopleId);
            var pi = p.PaymentInfo();

            if (pi == null)
            {
                pi = new PaymentInfo();
                p.PaymentInfos.Add(pi);
            }
            if (pi.AuNetCustId == null)             // create a new profilein Authorize.NET CIM
            {
                XDocument request = null;
                if (type == "B")
                {
                    request = new XDocument(new XDeclaration("1.0", "utf-8", null),
                                            Element("createCustomerProfileRequest",
                                                    Element("merchantAuthentication",
                                                            Element("name", login),
                                                            Element("transactionKey", key)
                                                            ),
                                                    Element("profile",
                                                            Element("merchantCustomerId", PeopleId),
                                                            Element("email", p.EmailAddress),
                                                            Element("paymentProfiles",
                                                                    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("payment",
                                                                            Element("bankAccount",
                                                                                    Element("routingNumber", routing),
                                                                                    Element("accountNumber", account),
                                                                                    Element("nameOnAccount", p.Name)
                                                                                    )
                                                                            )
                                                                    )
                                                            )
                                                    )
                                            );
                }
                else
                {
                    request = new XDocument(new XDeclaration("1.0", "utf-8", null),
                                            Element("createCustomerProfileRequest",
                                                    Element("merchantAuthentication",
                                                            Element("name", login),
                                                            Element("transactionKey", key)
                                                            ),
                                                    Element("profile",
                                                            Element("merchantCustomerId", PeopleId),
                                                            Element("email", p.EmailAddress),
                                                            Element("paymentProfiles",
                                                                    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("payment",
                                                                            Element("creditCard",
                                                                                    Element("cardNumber", cardnumber),
                                                                                    Element("expirationDate", exp),
                                                                                    Element("cardCode", cardcode)
                                                                                    )
                                                                            )
                                                                    )
                                                            )
                                                    )
                                            );
                }
                var s   = request.ToString();
                var x   = getResponse(s);
                var id  = x.Descendants(ns + "customerProfileId").First().Value.ToInt();
                var pid = x.Descendants(ns + "customerPaymentProfileIdList")
                          .Descendants(ns + "numericString").First().Value.ToInt();
                pi.AuNetCustId    = id;
                pi.AuNetCustPayId = pid;
            }
            else
            {
                if (account.HasValue() && account.StartsWith("X"))
                {
                    var xe  = getCustomerPaymentProfile(PeopleId);
                    var xba = xe.Descendants(ns + "bankAccount").Single();
                    routing = xba.Element(ns + "routingNumber").Value;
                    account = xba.Element(ns + "accountNumber").Value;
                }

                var request = new XDocument(new XDeclaration("1.0", "utf-8", null),
                                            Element("updateCustomerProfileRequest",
                                                    Element("merchantAuthentication",
                                                            Element("name", login),
                                                            Element("transactionKey", key)
                                                            ),
                                                    Element("profile",
                                                            Element("merchantCustomerId", PeopleId),
                                                            Element("email", p.EmailAddress),
                                                            Element("customerProfileId", pi.AuNetCustId)
                                                            )
                                                    )
                                            );
                var x = getResponse(request.ToString());
                if (type == "B")
                {
                    request = new XDocument(new XDeclaration("1.0", "utf-8", null),
                                            Element("updateCustomerPaymentProfileRequest",
                                                    Element("merchantAuthentication",
                                                            Element("name", login),
                                                            Element("transactionKey", key)
                                                            ),
                                                    Element("customerProfileId", pi.AuNetCustId),
                                                    Element("paymentProfile",
                                                            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("payment",
                                                                    Element("bankAccount",
                                                                            Element("routingNumber", routing),
                                                                            Element("accountNumber", account),
                                                                            Element("nameOnAccount", p.Name)
                                                                            )
                                                                    ),
                                                            Element("customerPaymentProfileId", pi.AuNetCustPayId)
                                                            )
                                                    )
                                            );
                }
                else
                {
                    request = new XDocument(new XDeclaration("1.0", "utf-8", null),
                                            Element("updateCustomerPaymentProfileRequest",
                                                    Element("merchantAuthentication",
                                                            Element("name", login),
                                                            Element("transactionKey", key)
                                                            ),
                                                    Element("customerProfileId", pi.AuNetCustId),
                                                    Element("paymentProfile",
                                                            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("payment",
                                                                    Element("creditCard",
                                                                            Element("cardNumber", cardnumber),
                                                                            Element("expirationDate", exp),
                                                                            Element("cardCode", cardcode)
                                                                            )
                                                                    ),
                                                            Element("customerPaymentProfileId", pi.AuNetCustPayId)
                                                            )
                                                    )
                                            );
                }
                x = getResponse(request.ToString());
            }
            pi.MaskedAccount = Util.MaskAccount(account);
            pi.MaskedCard    = Util.MaskCC(cardnumber);
            pi.Ccv           = cardcode;
            pi.Expires       = expires;
            Db.SubmitChanges();
        }
Esempio n. 16
0
        public void storeVault(int PeopleId,
                               string type, string cardnumber, string expires, string cardcode,
                               string routing, string account, bool giving)
        {
            var p  = Db.LoadPersonById(PeopleId);
            var pi = p.PaymentInfo();

            if (pi == null)
            {
                pi = new PaymentInfo();
                p.PaymentInfos.Add(pi);
            }
            var wc = new WebClient();

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

            coll["M_ID"]  = login;
            coll["M_KEY"] = key;

            XElement resp = null;

            if (type == "C")
            {
                coll["CARDNUMBER"]      = cardnumber;
                coll["EXPIRATION_DATE"] = expires;

                if (pi.SageCardGuid == null)
                {
                    var b   = wc.UploadValues("INSERT_CREDIT_CARD_DATA", "POST", coll);
                    var ret = Encoding.ASCII.GetString(b);
                    resp            = getResponse(ret);
                    pi.SageCardGuid = Guid.Parse(resp.Element("GUID").Value);
                }
                else
                {
                    coll["GUID"] = pi.SageCardGuid.ToString().Replace("-", "");
                    if (!cardnumber.StartsWith("X"))
                    {
                        var b   = wc.UploadValues("UPDATE_CREDIT_CARD_DATA", "POST", coll);
                        var ret = Encoding.ASCII.GetString(b);
                        resp = getResponse(ret);
                    }
                    else
                    {
                        var b   = wc.UploadValues("UPDATE_CREDIT_CARD_EXPIRATION_DATE", "POST", coll);
                        var ret = Encoding.ASCII.GetString(b);
                        resp = getResponse(ret);
                    }
                }
            }
            else
            {
                coll["ROUTING_NUMBER"] = routing;                 // 064000020
                coll["ACCOUNT_NUMBER"] = account;                 // my account number
                coll["C_ACCT_TYPE"]    = "DDA";

                if (pi.SageBankGuid == null)
                {
                    var b   = wc.UploadValues("INSERT_VIRTUAL_CHECK_DATA", "POST", coll);
                    var ret = Encoding.ASCII.GetString(b);
                    resp            = getResponse(ret);
                    pi.SageBankGuid = Guid.Parse(resp.Element("GUID").Value);
                }
                else
                {
                    if (!account.StartsWith("X"))
                    {
                        coll["GUID"] = pi.SageBankGuid.ToString().Replace("-", "");
                        var b   = wc.UploadValues("UPDATE_VIRTUAL_CHECK_DATA", "POST", coll);
                        var ret = Encoding.ASCII.GetString(b);
                        resp = getResponse(ret);
                    }
                }
            }
            pi.MaskedAccount = Util.MaskAccount(account);
            pi.Routing       = Util.Mask(new StringBuilder(routing), 2);
            pi.MaskedCard    = Util.MaskCC(cardnumber);
            pi.Ccv           = cardcode;
            pi.Expires       = expires;
            pi.Testing       = testing;
            if (giving)
            {
                pi.PreferredGivingType = type;
            }
            else
            {
                pi.PreferredPaymentType = type;
            }
            Db.SubmitChanges();
            //var sw =new StringWriter();
            //ObjectDumper.Write(pi, 0, sw);

            //Util.SendMsg(DbUtil.AdminMail, Db.CmsHost, Util.TryGetMailAddress("*****@*****.**"), "Sage Vault",
            //	"<a href='{0}{1}'>{2}</a><br>{3},{4}<br><pre>{5}</pre>".Fmt(
            //	Db.CmsHost, p.PeopleId, p.Name, type, giving ? "giving" : "regular", sw.ToString()),
            //	Util.ToMailAddressList("*****@*****.**"), 0, null);
        }