/// <summary> /// Updates info about a Customer. If The Customer's Address is not specified, one is created. Otherwise, it is updated /// </summary> /// <param name="updatedCustomer">Reference to a new info about the Customer</param> /// <param name="customerId">ID of the Customer to Update</param> /// <param name="format">Format of the Response</param> /// <returns></returns> public CustomerResponse UpdateCustomer(CustomerRequest updatedCustomer, string customerId, string format = ContentFormat.XML) { return _service.Put<CustomerRequest, CustomerResponse>(string.Format("{0}/{1}.{2}", _gatewayURL, customerId, format), updatedCustomer); }
public ActionResult Register(RegisterModel model) { string message = ""; if (ModelState.IsValid) { // Attempt to register the user MembershipCreateStatus createStatus; Membership.CreateUser(model.UserName, model.Password, model.Email, passwordQuestion: null, passwordAnswer: null, isApproved: true, providerUserKey: null, status: out createStatus); //if the registration process was successful, //add the newly registered user to your Customers and subscribe him to the Selected Plan if (createStatus == MembershipCreateStatus.Success) { FormsAuthentication.SetAuthCookie(model.UserName, createPersistentCookie: false); try { //get your Site data through Billing Gateway var mySite = _dynabicBillingGateway.Sites.GetSiteBySubdomain(Config.MySiteSubdomain); //get the selected plan var selectedPlan = _dynabicBillingGateway.Products.GetProductById(model.Plans.SelectedPlan.ToString()); //generate a random Customer Reference Id //CustomerReferenceId does not permit the usage of any other special characters except "-" and //it isn't allowed to begin or end with this character nor it can be consecutive Random r = new Random(); long value = (long)((r.NextDouble() * 2.0 - 1.0) * long.MaxValue); string newCustomerReferenceId = string.Format("{0}-{1}", mySite.Id, Math.Abs(value)); //create a new CustomerRequest CustomerRequest newCustomer = new CustomerRequest() { //this fields are required FirstName = model.UserName, LastName = model.UserName, Email = model.Email, ReferenceId = newCustomerReferenceId }; //create a new Subscription Request SubscriptionRequest newSubscription = new SubscriptionRequest() { Customer = newCustomer, ProductId = selectedPlan.Id, ProductPricingPlanId = selectedPlan.PricingPlans[0].Id, }; //if the Credit Card is required at Signup //create a new Credit Card Request and add it to your Subscription //isCreditCardAtSignupRequired may be "No", "Yes", "YesOptional" if (selectedPlan.isCreditCardAtSignupRequired != BoolOptional.No) { CreditCardRequest newCreditCard = new CreditCardRequest() { Cvv = model.CreditCard.Cvv, ExpirationDate = model.CreditCard.ExpirationDate, FirstNameOnCard = model.CreditCard.FirstNameOnCard, LastNameOnCard = model.CreditCard.LastNameOnCard, Number = model.CreditCard.Number }; newSubscription.CreditCard = newCreditCard; } //if the Billing Address is required at Signup //create a new Billing Address Request and add it to your Subscription //isBillingAddressAtSignupRequired may be "No", "Yes", "YesOptional" if (selectedPlan.isBillingAddressAtSignupRequired != BoolOptional.No) { AddressRequest billingAddress = new AddressRequest() { Address1 = model.BillingAddress.BillingAddress1, City = model.BillingAddress.BillingCity, Country = model.BillingAddress.BillingCountry, StateProvince = model.BillingAddress.BillingProvince, ZipPostalCode = model.BillingAddress.BillingZipPostalCode, FirstName = model.BillingAddress.BillingFirstName, LastName = model.BillingAddress.BillingLastName }; newSubscription.BillingAddress = billingAddress; } //subscribe the newly created Customer to selected Plan _dynabicBillingGateway.Subscription.AddSubscription(mySite.Subdomain, newSubscription); //create a User Profile and save some data that we may need later ProfileCommon profile = ProfileCommon.GetUserProfile(model.UserName); profile.CurrentPlanId = model.Plans.SelectedPlan; profile.CustomerReferenceId = newCustomerReferenceId; //redirect to Home page return RedirectToAction("Index", "Home"); } catch (Exception) { message = "Something went wrong. Please try again later."; } } else { message = ErrorCodeToString(createStatus); } } //provide an error message in case something went wrong model.PageMessage = new PageMessageModel { Type = PageMessageModel.MessageType.Error, Message = message }; model.Plans.MyPlans = model.Plans.GetAllPlans(_dynabicBillingGateway); // If we got this far, something failed, redisplay form return View(model); }
/// <summary> /// Create and Add a new Customer /// </summary> /// <param name="siteSubdomain"> The name of the Site to which the Customer will belong </param> /// <param name="newCustomer">Reference to a new Customer to create</param> /// <param name="format">Format of the passed Customer (XML or JSON)</param> /// <returns>ID of the new Customer created, otherwise Error</returns> public CustomerResponse AddCustomer(string siteSubdomain, CustomerRequest newCustomer, string format = ContentFormat.XML) { return _service.Post<CustomerRequest, CustomerResponse>(string.Format("{0}/{1}.{2}", _gatewayURL, siteSubdomain, format), newCustomer); }