Placing an order using the Atomia Billing API
To place an order, create an order object and then pass it to the CreateOrder
API method. The following code demonstrates both steps.
Creating an order object
To create an order set all customer’s details, create lists of order lines and custom attributes.
// Fetch customer and desired product to be purchased Account customer = AccountsHelper.GetAccount(customerId); Item item = ItemHelper.GetItem(itemId); Currency currency = CurrencyHelper.GetAccountDefaultCurrency(customerId) Order order = new Order { // specify customer's details CustomerId = customerId, CustomerFirstName = "John", // continue and add all customer details //... Currency = currency.Code, OrderDate = DateTime.Today, OrderType = Order.OrderTypeNormal, OrderLines = new List<OrderLine> { new OrderLine { ItemId = item.Id, ItemNumber = item.ArticleNumber, ItemName = item.Name, Price = item.Prices.Where(price => price.CurrencyId == currency.Id).First.Value, Discount = 0.00, Quantity = 1.00, Taxes = new List<OrderLineTax> { new OrderLineTax { Name = "VAT 25%", Percent = 25.00, ApplyToAmountOnly = true } }, CustomAttributes = new List<OrderLineCustomAttribute> { new OrderLineCustomAttribute { Name = "attribute_name", Value = "attribute_value" } } } }, CustomAttributes = new List<OrderCustomAttribute> { new OrderCustomAttribute { Name = "attribute_name", Value = "attribute_value" } } };
Placing an order
To place an order simply call the CreateOrder API method with an order object.
public Order PlaceOrder(Order order) { using (IAtomiaBillingApi atomiaBillingApi = GetAtomiaBillingApiChannel()) { order = atomiaBillingApi.CalculateTotals(order); return atomiaBillingApi.CreateOrder(order); } } public IAtomiaBillingApi GetAtomiaBillingApiChannel() { // add logic to obtain channel }
Process an order
The following code shows how to initiate order processing. The resulting order’s status contains information on whether the processing was successful or not.
using (IAtomiaBillingApi atomiaBillingApi = GetAtomiaBillingApiChannel()) { return atomiaBillingApi.ProcessOrder(order); // returns processed order }
Define a new product
The following code shows how to add a new product to the system:
Item item = new Item { Category = @"item's category", ArticleNumber = "ITEM_1", // unique name (or number) of the product Name = "article name", // Recurring = true, // true if the product is recurring, otherwise false RenewalPeriod = 1, // period of renewal (number of months or years - defined by RenewalPeriodUnit) RenewalPeriodUnit = "Year", // "Month" or "Year" RenewalItemId = Guid.Empty, // if Guid.Empty, product will be renewed with the same product, otherwise product with the given id will be used for renewal ReProvision = false, // if true, reprovisioning should be done DeliveryDate = 0, // indicating whether this product should be delivered (when invoiced (0), or when invoiced + renewal period (1)) AllowToSubresellers = true, // indicating whether this product should be allowed to subresellers ProvisioningAllowedType = 1, // should this product be provisioned without payment (refer to SDK reference for possible values) RenewingAllowedType = 1, // should this product be renewed without payment (refer to SDK reference for possible values) ProvisioningService = "BasePackage", // name of the service used for provisioning Tax1 = "Swedish Tax", // name of the tax plug-in used to get tax rules Tax2 = null, // name of the tax plug-in used to get tax rules Tax2Mode = 0, // indicates whether tax2 is cumulative RenewalInvoiceSendingPeriod = 30, // number of days prior to renewal when invoice should be sent }; Guid englishLang = Guid.Empty; Guid swedishLang = Guid.Empty; using (AtomiaAccountApiClient accountApi = new AtomiaAccountApiClient()) { englishLang = accountApi.GetLanguageByCode("EN").Id; swedishLang = accountApi.GetLanguageByCode("SV").Id; } item.MultilanguageNames = new Dictionary<Guid, string> { new KeyValuePair(new Guid(englishLang), "ITEM_1_EN"), new KeyValuePair(new Guid(swedishLang), "ITEM_1_SV") }; item.MultilanguageDescriptions = new Dictionary<Guid, string> { new KeyValuePair(new Guid(englishLang), "Description of ITEM_1_EN"), new KeyValuePair(new Guid(swedishLang), "Description of ITEM_1_SV") }; decimal defaultCurrencyPrice = 100; item.Prices = new List<ItemPrice> { new ItemPrice { ItemId = item.Id, CurrencyId = this.GetDefaultCurrency().Id, // GetDefaultCurrency should implement logic for getting currency for logged reseller Description = string.Empty, ResellerId = this.GetCurrentReseller().Id, // GetCurrentReseller should implement logic for getting currently logged in reseller Value = defaultCurrencyPrice; }, new ItemPrice { ItemId = item.Id, CurrencyId = this.GetAdditionalCurrency().Id, // GetAdditionalCurrency should implement logic for getting additional (secondary) currency for logged reseller Description = string.Empty, ResellerId = this.GetCurrentReseller().Id, // GetCurrentReseller should implement logic for getting currently logged in reseller Value = this.CurrencyConverter(this.GetDefaultCurrency(), this.GetAdditionalCurrency(), defaultCurrencyPrice); // Implement conversion of amount from one currency to another } } using (IAtomiaBillingApi atomiaBillingApi = GetAtomiaBillingApiChannel()) { return atomiaBillingApi.CreateItem(item, this.GetCurrentReseller()); // returns created item }