Thursday, July 24, 2014

Recurly Credit Card Processing - True Metered Billing

Overview:  I have a client that wants to simply bill a transaction fee at the end of each month.  After doing my due diligence, Recruly appeared to be the best solution for the problem as they assured me that what was i doing was not only possible but simple.

To make a long story short, technical support couldn't provide me with an example nor would they tell me anything but "look at our website" which was less then helpful as it contradicted itself.  Sometimes it would say to modify the plan subscription itself, sometimes it would say to create an addon.  None of this is correct.

The correct way to do metered billing with Recurly using is to use the following procedure:


  1. Create an account without a subscription plan
  2. At the end of each month simple add an adjustment to the account and invoice the pending charges.

Code (C#):

private void CreateAccount(RecurlyAccount recurlyAccount)
        {

            var account = new Account(recurlyAccount.AccountCode)
            {
                FirstName = recurlyAccount.FirstName,
                LastName = recurlyAccount.LastName,
                Email = recurlyAccount.Email,
                CompanyName = recurlyAccount.CompanyName,
            };

            account.BillingInfo = new BillingInfo(account)
            {
                LastName = recurlyAccount.RecurlyBillingInfo.FirstName,
                FirstName = recurlyAccount.RecurlyBillingInfo.LastName,
                Address1 = recurlyAccount.RecurlyBillingInfo.Address1,
                Address2 = recurlyAccount.RecurlyBillingInfo.Address2,
                City = recurlyAccount.RecurlyBillingInfo.City,
                State = recurlyAccount.RecurlyBillingInfo.State,
                Country = "US",
                PostalCode = recurlyAccount.RecurlyBillingInfo.PostalCode,
                CreditCardNumber = recurlyAccount.RecurlyBillingInfo.CreditCardNumber,
                CardType = recurlyAccount.RecurlyBillingInfo.CardType,
                ExpirationMonth = recurlyAccount.RecurlyBillingInfo.ExpirationMonth,
                ExpirationYear = recurlyAccount.RecurlyBillingInfo.ExpirationYear,
                Company = recurlyAccount.RecurlyBillingInfo.Company
            };

            account.Create();
        }

 
public virtual void BillCreditCard(Account account, int quantity, int amountInCents)
        {

            account.NewAdjustment("USD", amountInCents, "Orders", quantity).Create();
            account.InvoicePendingCharges();
            
        }

Phoenix

I am resurrecting this tech blog for notes related to Azure Logic Apps with SAP.