Class: Pay::FakeProcessor::Billable

Inherits:
Object
  • Object
show all
Defined in:
lib/pay/fake_processor/billable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(billable) ⇒ Billable

Returns a new instance of Billable.



13
14
15
# File 'lib/pay/fake_processor/billable.rb', line 13

def initialize(billable)
  @billable = billable
end

Instance Attribute Details

#billableObject (readonly)

Returns the value of attribute billable.



4
5
6
# File 'lib/pay/fake_processor/billable.rb', line 4

def billable
  @billable
end

Instance Method Details

#charge(amount, options = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/pay/fake_processor/billable.rb', line 21

def charge(amount, options = {})
  billable.charges.create(
    processor: :fake_processor,
    processor_id: rand(100_000_000),
    amount: amount,
    card_type: :fake,
    card_last4: 1234,
    card_exp_month: Date.today.month,
    card_exp_year: Date.today.year
  )
end

#customerObject



17
18
19
# File 'lib/pay/fake_processor/billable.rb', line 17

def customer
  billable
end

#processor_subscription(subscription_id, options = {}) ⇒ Object



51
52
53
# File 'lib/pay/fake_processor/billable.rb', line 51

def processor_subscription(subscription_id, options = {})
  billable.subscriptions.find_by(processor: :fake_processor, processor_id: subscription_id)
end

#subscribe(name: Pay.default_product_name, plan: Pay.default_plan_name, **options) ⇒ Object



33
34
35
36
# File 'lib/pay/fake_processor/billable.rb', line 33

def subscribe(name: Pay.default_product_name, plan: Pay.default_plan_name, **options)
  subscription = OpenStruct.new id: rand(1_000_000)
  billable.create_pay_subscription(subscription, :fake_processor, name, plan, status: :active, quantity: options.fetch(:quantity, 1))
end

#trial_end_date(subscription) ⇒ Object



55
56
57
# File 'lib/pay/fake_processor/billable.rb', line 55

def trial_end_date(subscription)
  Date.today
end

#update_card(payment_method_id) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/pay/fake_processor/billable.rb', line 38

def update_card(payment_method_id)
  billable.update(
    card_type: :fake,
    card_last4: 1234,
    card_exp_month: Date.today.month,
    card_exp_year: Date.today.year
  )
end

#update_email!Object



47
48
49
# File 'lib/pay/fake_processor/billable.rb', line 47

def update_email!
  # pass
end