-
BillingCycle has a period, frequency, anniversary, time_unit_measure, periodicity, next_payment_date, etc.
-
CurrentState holds a set of profiles and can iterate through them or return current_products or active_products
-
PaymentCommandBuilder, initialized with an array of products, generates commands for creating recurring payments for those products; also takes a set of profile_ids and generates commands for canceling their recurring payments
-
[Base|IndependentPayment|SinglePaymentStrategy], initialized with a current state, desired state and builder class, calculates how to achieve the desired state
-
ProrationCalculator, initialized with a hash of billing_cycle, price and date, calculates a prorated price
-
BillingEngine::Client::Product, arrays of these are manipulated via Billing Logic. “Product” in Billing Logic generally refers to BillingEngine::Client::Products
module BillingLogic class BillingCycle module CommandBuilders module BuilderHelpers class ProductList class ProductStub class ActionObject class BasicBuilder class WordBuilder < BasicBuilder class AggregateWordBuilder < BasicBuilder class CurrentState module CurrentStateMixin class PaymentCommandBuilder class ProrationCalculator module Strategies class BaseStrategy class IndependentPaymentStrategy class SinglePaymentStrategy
You create a BillingLogic::Strategy by passing in a hash with your current state, desired state and builder class:
strategy = <strategy class>.new(:payment_command_builder_class => <your builder class>, :current_state => <an array of payment profiles> :desired_state => <an array of products>)
You then ask the strategy to return you an array of commands:
strategy.command_list => An Array of commands provided by the command builder class
There are three strategies available:
-
BaseStrategy:
-
Contains most of the methods
-
-
IndependentPaymentStrategy:
-
Each product gets its own PaymentProfile
-
Default payment_command_builder_class: BillingLogic::CommandBuilders::WordBuilder
-
-
SinglePaymentStrategy:
-
All products share a single PaymentProfile
-
Default payment_command_builder_class: BillingLogic::CommandBuilders::AggregateWordBuilder
-
BaseStrategy also has these public methods:
#command_list #products_to_be_added #products_to_be_added_grouped_by_date #products_to_be_removed #inactive_products #active_products #active_profiles #profiles_by_status(active_or_pending)
constants:
TIME_UNITS = { :day => 1, :week => 7, :month => 365/12.0, :semimonth=> 365/24, :year => 365 }
fields:
:frequency (e.g., 1 or 45) :period (e.g., :day, :week, :semimonth, :month, :year) :anniversary (a date)
methods include:
#days_in_billing_cycle_including(date) #next_payment_date #closest_anniversary_date_including(date) #periodicity ( TIME_UNITS[self.period] * frequency )
instance methods:
#group_products_by_billing_cycle
class methods:
.create_recurring_payment_commands(products, next_payment_date = Date.current) .cancel_recurring_payment_commands(*profile_ids)