private SetAccountCreditCardTokenRequest SetAccountCreditCard() { // DEVELOPER NOTE: This method charges the credit card using tokenization, // which is PCI-Compliant. This is the default method to use when charging credit cards. // Fetch our credit card token. var token = ExigoApiContext.CreatePaymentContext().FetchCreditCardToken("4111111111111111", 9, 2018); var request = new SetAccountCreditCardTokenRequest(); request.CreditCardType = (int)AccountCreditCardType.Primary; request.CreditCardToken = token; request.BillingName = "andrewm"; request.CustomerID = 68342; //request.BillingAddress = "707 e main st"; //request.BillingCity = "LEHI"; request.BillingState = "Ut"; //request.BillingZip = "84043"; request.BillingCountry = "US"; request.ExpirationMonth = 5; request.ExpirationYear = 2019; return(request); }
public static void DeleteCustomerCreditCard(int customerID, CreditCardType type) { // If this is a new credit card, don't delete it - we have nothing to delete if (type == CreditCardType.New) { return; } // Save the a blank copy of the credit card // Passing a blank token will do the trick var request = new SetAccountCreditCardTokenRequest { CustomerID = customerID, CreditCardAccountType = (type == CreditCardType.Primary) ? AccountCreditCardType.Primary : AccountCreditCardType.Secondary, CreditCardToken = string.Empty, ExpirationMonth = 1, ExpirationYear = DateTime.Now.Year + 1, BillingName = string.Empty, BillingAddress = string.Empty, BillingCity = string.Empty, BillingState = string.Empty, BillingZip = string.Empty, BillingCountry = string.Empty }; var response = Exigo.WebService().SetAccountCreditCardToken(request); }
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); }
public ActionResult ManageAutoOrder(int id, ManageAutoOrderViewModel viewModel) { var customerID = Identity.Customer.CustomerID; var apiRequests = new List <ApiRequest>(); var customer = Exigo.GetCustomer(customerID); var market = GlobalSettings.Markets.AvailableMarkets.Where(c => c.Countries.Contains(Identity.Customer.Country)).FirstOrDefault(); var configuration = market.GetConfiguration().AutoOrders; var warehouseID = configuration.WarehouseID; var isExistingAutoOrder = id != 0; var paymentMethods = Exigo.GetCustomerPaymentMethods(new GetCustomerPaymentMethodsRequest() { CustomerID = Identity.Customer.CustomerID, ExcludeIncompleteMethods = true }); // Remove all items that have no quantity. viewModel.AutoOrder.Details = viewModel.AutoOrder.Details.Where(d => d.Quantity > 0).ToList(); if (!viewModel.AutoOrder.Details.Any()) { ModelState.AddModelError("Result", "Please select at least one product for your Auto Order."); } if (ModelState.Keys.Contains("Result")) { InflateManageAutoOrderViewModel(customerID, market, configuration, ref viewModel); return(View(viewModel)); } // Save New Credit Card var isUsingNewCard = viewModel.AutoOrder.AutoOrderPaymentTypeID == 0; var hasPrimaryCard = paymentMethods.Where(v => v.IsComplete).Count() > 0; if (isUsingNewCard) { var saveCCRequest = new SetAccountCreditCardTokenRequest(viewModel.NewCreditCard); // If there is one or more available payment type, save the card in the secondary card slot if (hasPrimaryCard) { saveCCRequest.CreditCardAccountType = AccountCreditCardType.Secondary; viewModel.AutoOrder.AutoOrderPaymentTypeID = AutoOrderPaymentTypes.SecondaryCreditCardOnFile; } else { viewModel.AutoOrder.AutoOrderPaymentTypeID = AutoOrderPaymentTypes.PrimaryCreditCardOnFile; } saveCCRequest.CustomerID = customerID; apiRequests.Add(saveCCRequest); } // Prepare the auto order var autoOrder = viewModel.AutoOrder; var createAutoOrderRequest = new CreateAutoOrderRequest(autoOrder) { PriceType = configuration.PriceTypeID, WarehouseID = warehouseID, Notes = !string.IsNullOrEmpty(autoOrder.Notes) ? autoOrder.Notes : string.Format("Created with the API Auto-Delivery manager at \"{0}\" on {1:u} at IP {2} using {3} {4} ({5}).", Request.Url.AbsoluteUri, DateTime.Now.ToUniversalTime(), GlobalUtilities.GetClientIP(), HttpContext.Request.Browser.Browser, HttpContext.Request.Browser.Version, HttpContext.Request.Browser.Platform), CustomerID = customerID }; apiRequests.Add(createAutoOrderRequest); try { // Process the transaction var transaction = new TransactionalRequest { TransactionRequests = apiRequests.ToArray() }; var response = Exigo.WebService().ProcessTransaction(transaction); return(RedirectToAction("AutoOrderList", new { success = "1" })); } catch (Exception ex) { ModelState.AddModelError("Result", "We were unable to save your Auto-Delivery: " + ex.Message); InflateManageAutoOrderViewModel(customerID, market, configuration, ref viewModel); return(View(viewModel)); } }
// Handling credit cards private SetAccountCreditCardTokenRequest Request_SaveNewCreditCardToAccount(AccountCreditCardType creditCardType) { SetAccountCreditCardTokenRequest request = new SetAccountCreditCardTokenRequest(); request.CustomerID = Identity.Current.CustomerID; request.CreditCardToken = NewCreditCardPaymentToken; request.CreditCardAccountType = creditCardType; request.ExpirationMonth = Autoship.PropertyBag.CreditCardExpirationDate.Month; request.ExpirationYear = Autoship.PropertyBag.CreditCardExpirationDate.Year; request.BillingName = Autoship.PropertyBag.CreditCardNameOnCard; request.BillingAddress = Autoship.PropertyBag.CreditCardBillingAddress; request.BillingCity = Autoship.PropertyBag.CreditCardBillingCity; request.BillingState = Autoship.PropertyBag.CreditCardBillingState; request.BillingZip = Autoship.PropertyBag.CreditCardBillingZip; request.BillingCountry = Autoship.PropertyBag.CreditCardBillingCountry; return request; }
/// <remarks/> public void SetAccountCreditCardTokenAsync(SetAccountCreditCardTokenRequest SetAccountCreditCardTokenRequest, object userState) { if ((this.SetAccountCreditCardTokenOperationCompleted == null)) { this.SetAccountCreditCardTokenOperationCompleted = new System.Threading.SendOrPostCallback(this.OnSetAccountCreditCardTokenOperationCompleted); } this.InvokeAsync("SetAccountCreditCardToken", new object[] { SetAccountCreditCardTokenRequest}, this.SetAccountCreditCardTokenOperationCompleted, userState); }
/// <remarks/> public void SetAccountCreditCardTokenAsync(SetAccountCreditCardTokenRequest SetAccountCreditCardTokenRequest) { this.SetAccountCreditCardTokenAsync(SetAccountCreditCardTokenRequest, null); }
public ActionResult SubmitCheckout() { if (!PropertyBag.IsSubmitting) { PropertyBag.IsSubmitting = true; _propertyBag = ExigoDAL.PropertyBags.Update(PropertyBag); try { // Start creating the API requests var apiRequests = new List <ApiRequest>(); // Create the customer var customerRequest = new CreateCustomerRequest(PropertyBag.Customer) { InsertEnrollerTree = true, EnrollerID = PropertyBag.EnrollerID, CustomerType = CustomerTypes.Distributor, EntryDate = DateTime.Now.ToCST(), CustomerStatus = CustomerStatuses.Active, CanLogin = true, DefaultWarehouseID = OrderConfiguration.WarehouseID, Notes = "Distributor was entered by Distributor #{0}. Created by the API Enrollment at ".FormatWith(Identity.Owner.CustomerID) + HttpContext.Request.Url.Host + HttpContext.Request.Url.LocalPath + " on " + DateTime.Now.ToCST().ToString("dddd, MMMM d, yyyy h:mmtt") + " CST at IP " + Common.GlobalUtilities.GetClientIP() + " using " + HttpContext.Request.Browser.Browser + " " + HttpContext.Request.Browser.Version + " (" + HttpContext.Request.Browser.Platform + ")." }; ///IF Unilevel Place in Sponsor Tree Now, Binary will be placed post transactional envelope if (!GlobalSettings.Exigo.UseBinary) { customerRequest.InsertUnilevelTree = true; customerRequest.SponsorID = customerRequest.EnrollerID; } apiRequests.Add(customerRequest); // Set a few variables up for our shippping address, order/auto order items and the default auto order payment type var shippingAddress = PropertyBag.ShippingAddress; var orderItems = ShoppingCart.Items.Where(i => i.Type == ShoppingCartItemType.Order || i.Type == ShoppingCartItemType.EnrollmentPack).ToList(); var autoOrderItems = ShoppingCart.Items.Where(i => i.Type == ShoppingCartItemType.AutoOrder || i.Type == ShoppingCartItemType.EnrollmentAutoOrderPack).ToList(); var autoOrderPaymentType = AutoOrderPaymentType.PrimaryCreditCard; // Create initial order var orderRequest = new CreateOrderRequest(OrderConfiguration, PropertyBag.ShipMethodID, orderItems, shippingAddress); // Add order request now if we need to do any testing with the accepted functionality apiRequests.Add(orderRequest); if (PropertyBag.PaymentMethod.CanBeParsedAs <BankAccount>()) { var bankAccount = PropertyBag.PaymentMethod.As <BankAccount>(); if (bankAccount.Type == ExigoService.BankAccountType.New) { apiRequests.Add(new DebitBankAccountRequest(bankAccount)); } else { apiRequests.Add(new DebitBankAccountOnFileRequest(bankAccount)); } } // Create subscription autoorder if an autoorder has been chosen if (autoOrderItems != null && autoOrderItems.Count() > 0) { var autoOrderRequest = new CreateAutoOrderRequest(AutoOrderConfiguration, autoOrderPaymentType, DateTime.Now.AddMonths(1).ToCST(), PropertyBag.ShipMethodID, autoOrderItems, shippingAddress); autoOrderRequest.Frequency = FrequencyType.Monthly; apiRequests.Add(autoOrderRequest); } // Create customer site var customerSiteRequest = new SetCustomerSiteRequest(PropertyBag.Customer); apiRequests.Add(customerSiteRequest); // Add the new credit card to the customer's record and charge it for the current order if (PropertyBag.PaymentMethod.CanBeParsedAs <CreditCard>()) { var creditCard = PropertyBag.PaymentMethod.As <CreditCard>(); if (!creditCard.IsTestCreditCard && !Request.IsLocal) { var saveCCRequest = new SetAccountCreditCardTokenRequest(creditCard); apiRequests.Add(saveCCRequest); var chargeCCRequest = new ChargeCreditCardTokenRequest(creditCard); apiRequests.Add(chargeCCRequest); } else { orderRequest.OrderStatus = GlobalUtilities.GetDefaultOrderStatusType(); } } // Process the transaction var transaction = new TransactionalRequest { TransactionRequests = apiRequests.ToArray() }; var response = ExigoDAL.WebService().ProcessTransaction(transaction); var newcustomerid = 0; var neworderid = 0; var newautoorderid = 0; if (response.Result.Status == ResultStatus.Success) { foreach (var apiresponse in response.TransactionResponses) { if (apiresponse.CanBeParsedAs <CreateCustomerResponse>()) { newcustomerid = apiresponse.As <CreateCustomerResponse>().CustomerID; } if (apiresponse.CanBeParsedAs <CreateOrderResponse>()) { neworderid = apiresponse.As <CreateOrderResponse>().OrderID; } if (apiresponse.CanBeParsedAs <CreateAutoOrderResponse>()) { newautoorderid = apiresponse.As <CreateAutoOrderResponse>().AutoOrderID; } } } ///If Binary Place Node Now if (GlobalSettings.Exigo.UseBinary) { var placeNodeRequest = new PlaceBinaryNodeRequest { CustomerID = newcustomerid, ToParentID = PropertyBag.EnrollerID, PlacementType = BinaryPlacementType.EvenFill }; ExigoDAL.WebService().PlaceBinaryNode(placeNodeRequest); } PropertyBag.NewCustomerID = newcustomerid; PropertyBag.NewOrderID = neworderid; PropertyBag.NewAutoOrderID = newautoorderid; _propertyBag = ExigoDAL.PropertyBags.Update(PropertyBag); // If the transaction was successful, then send the customer an email that will allow them to confirm thier opt in choice if (PropertyBag.Customer.IsOptedIn) { ExigoDAL.SendEmailVerification(newcustomerid, PropertyBag.Customer.Email); } var token = Security.Encrypt(new { CustomerID = newcustomerid, OrderID = neworderid, AutoOrderID = newautoorderid }); // Enrollment complete, now delete the Property Bag ExigoDAL.PropertyBags.Delete(PropertyBag); ExigoDAL.PropertyBags.Delete(ShoppingCart); return(new JsonNetResult(new { success = true, token = token })); } catch (Exception exception) { PropertyBag.OrderException = exception.Message; PropertyBag.IsSubmitting = false; _propertyBag = ExigoDAL.PropertyBags.Update(PropertyBag); return(new JsonNetResult(new { success = false, message = exception.Message })); } } else { if (PropertyBag.NewCustomerID > 0) { var token = Security.Encrypt(new { CustomerID = PropertyBag.NewCustomerID, OrderID = PropertyBag.NewOrderID, AutoOrderID = PropertyBag.NewAutoOrderID }); return(new JsonNetResult(new { success = true, token = token })); } else { return(new JsonNetResult(new { success = false, message = Resources.Common.YourOrderIsSubmitting })); } } }