public ChargeCreditCardTokenRequest(CreditCard card)
        {
            CreditCardToken = card.GetToken();
            CvcCode         = card.CVV;

            BillingName     = card.NameOnCard;
            BillingAddress  = card.BillingAddress.AddressDisplay;
            BillingCity     = card.BillingAddress.City;
            BillingState    = card.BillingAddress.State;
            BillingZip      = card.BillingAddress.Zip;
            BillingCountry  = card.BillingAddress.Country;
        }
        /// <summary>
        /// Sets up SetAccountCreditCardTokenRequest api request. NOTE: This automatically sets the credit card type as Primary by default.
        /// </summary>
        /// <param name="card">ExigoService.CreditCard</param>
        /// <returns>SetAccountCreditCardTokenRequest</returns>
        public SetAccountCreditCardTokenRequest(CreditCard card)
        {
            CreditCardToken       = card.GetToken();
            ExpirationMonth       = card.ExpirationMonth;
            ExpirationYear        = card.ExpirationYear;
            CreditCardAccountType = AccountCreditCardType.Primary;

            BillingName           = card.NameOnCard;
            BillingAddress        = card.BillingAddress.AddressDisplay;
            BillingCity           = card.BillingAddress.City;
            BillingState          = card.BillingAddress.State;
            BillingZip            = card.BillingAddress.Zip;
            BillingCountry        = card.BillingAddress.Country;
        }
        public ActionResult SaveCreditCard(CreditCard card)
        {
            try
            {
                card = Exigo.SetCustomerCreditCard(Identity.Customer.CustomerID, card);

                return RedirectToAction("PaymentMethods");
            }
            catch (Exception ex)
            {
                return RedirectToAction("PaymentMethods", new { error = ex.Message.ToString() });
            }
        }
        public ActionResult AddCreditCard()
        {
            var model = new CreditCard();
            model.Type = CreditCardType.New;
            model.BillingAddress = new Address()
            {
                Country = GlobalSettings.Company.Address.Country
            };

            return View("ManageCreditCard", model);
        }
Ejemplo n.º 5
0
        public static CreditCard SetCustomerCreditCard(int customerID, CreditCard card, CreditCardType type)
        {
            // New credit cards
            if (type == CreditCardType.New)
            {
                return SaveNewCustomerCreditCard(customerID, card);
            }

            // Validate that we have a token
            var token = card.GetToken();
            if (token.IsNullOrEmpty()) return card;

            // Save the credit card
            var request = new SetAccountCreditCardTokenRequest
            {
                CustomerID = customerID,

                CreditCardAccountType = (card.Type == CreditCardType.Primary) ? AccountCreditCardType.Primary : AccountCreditCardType.Secondary,
                CreditCardToken = token,
                ExpirationMonth = card.ExpirationMonth,
                ExpirationYear = card.ExpirationYear,

                BillingName = card.NameOnCard,
                BillingAddress = card.BillingAddress.AddressDisplay,
                BillingCity = card.BillingAddress.City,
                BillingState = card.BillingAddress.State,
                BillingZip = card.BillingAddress.Zip,
                BillingCountry = card.BillingAddress.Country
            };
            var response = Exigo.WebService().SetAccountCreditCardToken(request);

            return card;
        }
Ejemplo n.º 6
0
 public static CreditCard SetCustomerCreditCard(int customerID, CreditCard card)
 {
     return SetCustomerCreditCard(customerID, card, card.Type);
 }
Ejemplo n.º 7
0
        public static CreditCard SaveNewCustomerCreditCard(int customerID, CreditCard card)
        {
            // Get the credit cards on file
            var creditCardsOnFile = GetCustomerPaymentMethods(new GetCustomerPaymentMethodsRequest
            {
                CustomerID = customerID,
                ExcludeInvalidMethods = true
            }).Where(c => c is CreditCard).Select(c => (CreditCard)c);

            // Do we have any empty slots? If so, save this card to the next available slot
            if (!creditCardsOnFile.Any(c => c.Type == CreditCardType.Primary))
            {
                card.Type = CreditCardType.Primary;
                return SetCustomerCreditCard(customerID, card);
            }
            if (!creditCardsOnFile.Any(c => c.Type == CreditCardType.Secondary))
            {
                card.Type = CreditCardType.Secondary;
                return SetCustomerCreditCard(customerID, card);
            }

            // If not, try to save it to a card slot that does not have any autoOrder bound to it.
            if (!creditCardsOnFile.Where(c => c.Type == CreditCardType.Primary).Single().IsUsedInAutoOrders)
            {
                card.Type = CreditCardType.Primary;
                return SetCustomerCreditCard(customerID, card);
            }
            if (!creditCardsOnFile.Where(c => c.Type == CreditCardType.Secondary).Single().IsUsedInAutoOrders)
            {
                card.Type = CreditCardType.Secondary;
                return SetCustomerCreditCard(customerID, card);
            }

            // If no autoOrder-free slots exist, don't save it.
            return card;
        }
        public ActionResult UseCreditCard(CreditCard newCard)
        {
            try
            {
                var billingAddress = PropertyBag.BillingAddress;

                newCard.BillingAddress = new Address
                {
                    Address1 = billingAddress.Address1,
                    Address2 = billingAddress.Address2,
                    City = billingAddress.City,
                    State = billingAddress.State,
                    Zip = billingAddress.Zip,
                    Country = billingAddress.Country
                };

                // Verify that the card is valid
                if (!newCard.IsValid)
                {
                    return new JsonNetResult(new
                    {
                        success = false
                    });
                }
                else
                {
                    // Save the credit card to the customer's account if applicableB
                    if (LogicProvider.IsAuthenticated())
                    {
                        var paymentMethodsOnFile = Exigo.GetCustomerPaymentMethods(new GetCustomerPaymentMethodsRequest
                        {
                            CustomerID = Identity.Customer.CustomerID,
                            ExcludeIncompleteMethods = true,
                            ExcludeInvalidMethods = true
                        }).Where(c => c is CreditCard).Select(c => c as CreditCard);

                        var firstPayment = paymentMethodsOnFile.Where(c => c.Type == CreditCardType.Primary).FirstOrDefault();
                        var secondPayment = paymentMethodsOnFile.Where(c => c.Type == CreditCardType.Secondary).FirstOrDefault();

                        if (firstPayment == null)
                        {
                            Exigo.SetCustomerCreditCard(Identity.Customer.CustomerID, newCard, CreditCardType.Primary);
                        }

                        else if (secondPayment == null && firstPayment.CardNumber != newCard.CardNumber)
                        {
                            Exigo.SetCustomerCreditCard(Identity.Customer.CustomerID, newCard, CreditCardType.Secondary);
                        }
                    }

                    PropertyBag.IsRedirectPayment = false;

                    return UsePaymentMethod(newCard);
                }
            }
            catch (Exception ex)
            {
                return new JsonNetResult(new
                {
                    success = false,
                    message = ex.Message
                });

            }
        }