Module: UsageCredits
- Defined in:
- lib/usage_credits.rb,
lib/usage_credits.rb,
lib/usage_credits/engine.rb,
lib/usage_credits/railtie.rb,
lib/usage_credits/version.rb,
lib/usage_credits/cost/base.rb,
lib/usage_credits/cost/fixed.rb,
lib/usage_credits/configuration.rb,
lib/usage_credits/cost/compound.rb,
lib/usage_credits/cost/variable.rb,
lib/usage_credits/models/wallet.rb,
lib/usage_credits/models/operation.rb,
lib/usage_credits/models/allocation.rb,
lib/usage_credits/models/credit_pack.rb,
lib/usage_credits/models/fulfillment.rb,
lib/usage_credits/models/transaction.rb,
lib/usage_credits/jobs/fulfillment_job.rb,
lib/usage_credits/helpers/period_parser.rb,
lib/usage_credits/helpers/credits_helper.rb,
lib/usage_credits/helpers/credit_calculator.rb,
lib/usage_credits/models/concerns/has_wallet.rb,
lib/generators/usage_credits/install_generator.rb,
lib/usage_credits/services/fulfillment_service.rb,
lib/usage_credits/models/credit_subscription_plan.rb,
lib/usage_credits/models/concerns/pay_charge_extension.rb,
lib/usage_credits/models/concerns/pay_subscription_extension.rb
Overview
lib/usage_credits/services/fulfillment_service.rb
Defined Under Namespace
Modules: Cost, CreditCalculator, CreditsHelper, Generators, HasWallet, PayChargeExtension, PaySubscriptionExtension, PeriodParser
Classes: Allocation, ApplicationJob, ApplicationRecord, Configuration, CreditPack, CreditSubscriptionPlan, Engine, Error, Fulfillment, FulfillmentJob, FulfillmentService, InsufficientCredits, InvalidOperation, Operation, Railtie, Transaction, Wallet
Constant Summary
collapse
- VERSION =
"0.1.1"
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.configuration ⇒ Object
67
68
69
|
# File 'lib/usage_credits.rb', line 67
def configuration
@configuration ||= Configuration.new
end
|
Class Method Details
.available_credit_packs ⇒ Object
Also known as:
available_packs
106
107
108
|
# File 'lib/usage_credits.rb', line 106
def available_credit_packs
credit_packs.values.uniq
end
|
Configure the gem with a block (main entry point)
72
73
74
|
# File 'lib/usage_credits.rb', line 72
def configure
yield(configuration)
end
|
.credit_pack(name, &block) ⇒ Object
92
93
94
|
# File 'lib/usage_credits.rb', line 92
def credit_pack(name, &block)
configuration.credit_pack(name, &block)
end
|
.credit_packs ⇒ Object
Also known as:
packs
96
97
98
|
# File 'lib/usage_credits.rb', line 96
def credit_packs
configuration.credit_packs
end
|
.credit_subscription_plans ⇒ Object
Also known as:
subscription_plans, plans
115
116
117
|
# File 'lib/usage_credits.rb', line 115
def credit_subscription_plans
configuration.credit_subscription_plans
end
|
.find_credit_pack(name) ⇒ Object
Also known as:
find_pack
101
102
103
|
# File 'lib/usage_credits.rb', line 101
def find_credit_pack(name)
credit_packs[name.to_sym]
end
|
.find_subscription_plan(name) ⇒ Object
Also known as:
find_plan
121
122
123
|
# File 'lib/usage_credits.rb', line 121
def find_subscription_plan(name)
credit_subscription_plans[name.to_sym]
end
|
.find_subscription_plan_by_processor_id(processor_id) ⇒ Object
Also known as:
find_plan_by_id
126
127
128
|
# File 'lib/usage_credits.rb', line 126
def find_subscription_plan_by_processor_id(processor_id)
configuration.find_subscription_plan_by_processor_id(processor_id)
end
|
.handle_event(event, **params) ⇒ Object
137
138
139
140
141
142
|
# File 'lib/usage_credits.rb', line 137
def handle_event(event, **params)
case event
when :low_balance_reached
notify_low_balance(params[:wallet].owner)
end
end
|
.notify_low_balance(owner) ⇒ Object
Event handling for low balance notifications
132
133
134
135
|
# File 'lib/usage_credits.rb', line 132
def notify_low_balance(owner)
return unless configuration.low_balance_callback
configuration.low_balance_callback.call(owner)
end
|
.operation(name, &block) ⇒ Object
DSL methods - all delegate to configuration These enable things like both ‘UsageCredits.credit_pack` and bare `credit_pack` usage
84
85
86
|
# File 'lib/usage_credits.rb', line 84
def operation(name, &block)
configuration.operation(name, &block)
end
|
.operations ⇒ Object
88
89
90
|
# File 'lib/usage_credits.rb', line 88
def operations
configuration.operations
end
|
.reset! ⇒ Object
Reset configuration to defaults (mainly for testing)
77
78
79
|
# File 'lib/usage_credits.rb', line 77
def reset!
@configuration = nil
end
|
.subscription_plan(name, &block) ⇒ Object
111
112
113
|
# File 'lib/usage_credits.rb', line 111
def subscription_plan(name, &block)
configuration.subscription_plan(name, &block)
end
|