Atomia Billing System developer guide

Atomia Billing - Developer guide

159 views 0

Obtaining Atomia Billing SDK

Atomia Billing SDK can be downloaded as a compiled set of dlls. The main SDK dll is Atomia.Billing.Core.Sdk.dll. Other dlls in the package are dependencies of the Atomia Billing SDK.

Here you can download the full Atomia Billing SDK: Atomia Billing Core SDK.

Set up a Visual Studio project

Here you can find basic steps for starting the development of custom plug-ins to use with the Atomia Billing API. The same procedure can be used for creating event handlers.

  1. Create a folder on your hard drive where all code will be placed (e.g. AtomiaBillingSdkExample ). It will be referenced later as the root folder.
  2. Create in root folder subfolder named Solution where solution items will be placed.
  3. Create another subfolder, lib for placing all needed libraries.
  4. Copy the contents of the downloaded Atomia Billing SDK package ( Atomia.Billing.Core.Sdk folder) to lib folder.
  5. Open Visual Studio 2010 and create a blank solution named AtomiaBillingSdkExample and place it in the Solution folder.
  6. Create a new class library project named Plugins and change its assembly name and default namespace toAtomiaBillingSdkExample.Plugins .
  7. Add references to Atomia.Billing.Core.Sdk.dll and Atomia.Billing.Core.DataLayer.dll for the projectPlugins .

You are now ready to start writing custom plug-ins by implementing the interfaces defined in the Atomia Billing SDK.

Example

Here is an example of a simple plug-in of type IScheduledEventHandler :

  1. Add a new class with the name NotificationHandler .
  2. Copy the following code as its definition:
    using System.Collections.Generic;
    using Atomia.Billing.Core.Sdk;
    using Atomia.Billing.Core.Sdk.Plugins;
    using Atomia.Billing.Core.Sdk.Utils.Email;
    
    namespace AtomiaBillingSdkExample.Plugins
    {
     /// <summary>
     /// Custom implementation of IScheduledEventHandler.
     /// </summary>
     public class NotificationHandler : IScheduledEventHandler
     {
       /// <summary>
       /// Initializes a new instance of the <see cref="NotificationHandler"/> class.
       /// </summary>
       public NotificationHandler()
       {
         this.SenderAddress = "[email protected]";
       }   
       
       /// <summary>
       /// Gets or sets plugin name.
       /// </summary>
       public string Name
       {
         get
         {
           return "NotificationHandler";
         }
         
         set
         {
         }
       }
       
       /// <summary>
       /// Gets or sets IAtomiaBillingApi instance.
       /// </summary>
       public IAtomiaBillingApi AtomiaBillingApi
       {
         get;
         set;
       }
       
       /// <summary>
       /// Gets or sets SenderAddress.
       /// </summary>
       public string SenderAddress
       {
         get;
         set;
       }
       
       /// <summary>
       /// Handles scheduled event.
       /// </summary>
       public void HandleEvent()
       {
         IList<MyNotification> notifications = this.GetNotifications();
         foreach (MyNotification notification in notifications)
         {
           this.SendEmail(this.SenderAddress, notification.To, notification.Subject, notification.Body);
         }
       }
       
       /// <summary>
       /// Send email to recipient.
       /// </summary>
       /// <param name="senderAddress">The sender address.</param>
       /// <param name="recipient">The recipient.</param>
       /// <param name="subject">The subject.</param>
       /// <param name="body">The email body.</param>
       private void SendEmail(string senderAddress, string recipient, string subject, string body)
       {
         this.AtomiaBillingApi.SendMail(senderAddress, recipient, subject, body, new List<MailAttachment>());
       }
       
       /// <summary>
       /// Gets notifications.
       /// </summary>
       /// <returns>
       /// List of notifications.
       /// </returns>
       private IList<MyNotification> GetNotifications()
       {
         IList<MyNotification> notifications = new List<MyNotification>();
         
         // Here should be placed logic for retrieving notifications (using helper class, repository, etc.).
         // For this example, one notification is hardcoded.
         notifications.Add(new MyNotification
         {
           Body = "Test notification body.",
           Subject = "Test notification",
           To = "[email protected]"
         });
         return notifications;
       }
     }             
    
    /// <summary>
     /// Notification class.
     /// </summary>
     internal class MyNotification
     {
       /// <summary>
       /// Gets or sets the body.
       /// </summary>
       public string Body { get; set; }
    
       /// <summary>
       /// Gets or sets the subject.
       /// </summary>
       public string Subject { get; set; }            
    
       /// <summary>
       /// Gets or sets recipient.
       /// </summary>
       public string To { get; set; }
     }
    }
    
  3. You should now be able to build the project.
  4. To test the created class, add a new Test project named UnitTests and change its assembly name and default namespace toAtomiaBillingSdkExample.UnitTests .
  5. Add a unit test class for NotificationHandler (you can name it NotificationHandlerTest ) and add following code:
    using System.Collections.Generic;
    using Atomia.Billing.Core.Sdk;
    using Atomia.Billing.Core.Sdk.Utils.Email;
    using AtomiaBillingSdkExample.Plugins;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Rhino.Mocks;
    
    namespace AtomiaBillingSdkExample.UnitTests
    {
     /// <summary>
     /// NotificationHandler test fixture.
     /// </summary>
     [TestClass]
     public class NotificationHandlerTest
     {
       /// <summary>
       /// Rhino Mocks Repository.
       /// </summary>
       private readonly MockRepository mocks;
       
       /// <summary>
       /// Atomia Billing Api mock.
       /// </summary>
       private readonly IAtomiaBillingApi atomiaBillingApiMock;
       
       /// <summary>
       /// Initializes a new instance of the <see cref="NotificationHandlerTest"/> class.
       /// </summary>
       public NotificationHandlerTest()
       {
         this.mocks = new MockRepository();
         this.atomiaBillingApiMock = this.mocks.StrictMock<IAtomiaBillingApi>();
       }
       
       /// <summary>
       /// Gets or sets the test context which provides
       /// information about and functionality for the current test run.
       /// </summary>
       public TestContext TestContext { get; set; }
       
       #region Additional test attributes
       /// <summary>
       /// Use ClassInitialize to run code before running the first test in the class.
       /// </summary>
       /// <param name="testContext">The test context.</param>
       [ClassInitialize]
       public static void MyClassInitialize(TestContext testContext)
       {
       }
       
       /// <summary>
       /// Use ClassCleanup to run code after all tests in a class have run.
       /// </summary>
       [ClassCleanup]
       public static void MyClassCleanup()
       {
       }
       
       /// <summary>
       /// Use TestInitialize to run code before running each test.
       /// </summary>
       [TestInitialize]
       public void MyTestInitialize()
       {
         this.mocks.BackToRecordAll();
       }
       
       /// <summary>
       /// Use TestCleanup to run code after each test has run.
       /// </summary>
       [TestCleanup]
       public void MyTestCleanup()
       {
         this.mocks.VerifyAll();
       }
       #endregion
       
       /// <summary>
       /// A test for HandleEvent
       /// </summary>
       [TestMethod]
       public void HandleEventTest()
       {
         NotificationHandler notificationHandler = new NotificationHandler
         {
           AtomiaBillingApi = this.atomiaBillingApiMock
         };
         
         Expect.Call(
         () =>
         this.atomiaBillingApiMock.SendMail("[email protected]", "[email protected]", "Test notification", "Test notification body.", new List<MailAttachment>()))
         .Repeat.Once();
         this.mocks.ReplayAll();
         
         notificationHandler.HandleEvent();
       }
     }
    }
    
  6. In order to compile the project and run the test you will need Rhino Mocks library for creating the Atomia Billing API mock. You can download Rhino Mocks for free and add a reference to it for your UnitTests project.

You can download the complete example here: Atomia Billing SDK Example.

Was this helpful?