public CrayonApiClient(HttpClient httpClient) { _httpClient = httpClient; _jsonSerializerSettings = new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Ignore, NullValueHandling = NullValueHandling.Include, DefaultValueHandling = DefaultValueHandling.Include, Formatting = Formatting.Indented }; _assemblyVersion = typeof(CrayonApiClient).GetTypeInfo().Assembly.GetName().Version.ToString(); Addresses = new AddressResource(this); AgreementProducts = new AgreementProductResource(this); Agreements = new AgreementResource(this); BillingStatements = new BillingStatementResource(this); BlogItems = new BlogItemResource(this); Clients = new ClientResource(this); CustomerTenants = new CustomerTenantResource(this); InvoiceProfiles = new InvoiceProfileResource(this); Me = new MeResource(this); OrganizationAccess = new OrganizationAccessResource(this); Organizations = new OrganizationResource(this); Publishers = new PublisherResource(this); Programs = new ProgramResource(this); Regions = new RegionResource(this); Secrets = new SecretResource(this); Subscriptions = new SubscriptionResource(this); Tokens = new TokenResource(this); UsageRecords = new UsageRecordResource(this); Users = new UserResource(this); }
/// <summary> /// Creates Address based on EA location. If the data is not there, default to customer data. /// </summary> /// <param name="magentoRegion"></param> /// <param name="eaLocation"></param> /// <param name="customer"></param> public AddressResource(RegionResource magentoRegion, LocationResource eaLocation, CustomerResource customer) { var customerAddress = customer.addresses.First(); region = magentoRegion.name; regionId = int.Parse(magentoRegion.id); regionCode = magentoRegion.code; countryId = eaLocation.Address.CountryCode; street = new List <string>(); if (eaLocation.Address.AddressLine1 != null) { street.Add(eaLocation.Address.AddressLine1); } if (eaLocation.Address.AddressLine2 != null) { street.Add(eaLocation.Address.AddressLine2); } if (!street.Any()) { street = customerAddress.street; } telephone = eaLocation.StorePhoneNumbers.FirstOrDefault()?.Number ?? customerAddress.telephone; postcode = eaLocation.Address.Zip ?? customerAddress.postcode; city = eaLocation.Address.City; firstname = customer.firstname; lastname = customer.lastname; email = customer.email; }
/// <summary> /// Sets the shipping and billing information on a Magento cart. /// Shipping address used is based on the EA location unless the data needed is not available. In this case, data is pulled from the customer. /// Shipping method used will be the one set in App.config. If that shipping method cannot be used for the cart specified, an exception will occur. /// </summary> /// <param name="cartId">Identifier for cart to set information on.</param> /// <param name="magentoRegion">Region information for address</param> /// <param name="eaLocation">Location information for address</param> /// <param name="customer">Customer for address information</param> public void SetShippingAndBillingInformationForCart(int cartId, RegionResource magentoRegion, LocationResource eaLocation, CustomerResource customer) { AddressResource shippingAddress; if (magentoRegion != null) { shippingAddress = new AddressResource(magentoRegion, eaLocation, customer); } else { shippingAddress = new AddressResource(customer); } //Verfiy that shipping code matches App.config file var shippingInformation = new CartSetShippingInformationResource(ConfigReader.MagentoShippingCode, shippingAddress); _magentoCartController.SetShippingInformation(cartId, shippingInformation); if (_magentoCartController.GetShippingMethods(cartId).FirstOrDefault(x => x.method_code == ConfigReader.MagentoShippingCode) == null) { throw new Exception(string.Format("Unable to add shipping information to cart {0}. Ensure that shipping code {1} is valid for this cart.", cartId, ConfigReader.MagentoShippingCode)); } }