class Pay::FakeProcessor::Billable

Attributes

pay_customer[R]

Public Class Methods

new(pay_customer) click to toggle source
# File lib/pay/fake_processor/billable.rb, line 13
def initialize(pay_customer)
  @pay_customer = pay_customer
end

Public Instance Methods

add_payment_method(payment_method_id, default: false) click to toggle source
# File lib/pay/fake_processor/billable.rb, line 54
def add_payment_method(payment_method_id, default: false)
  # Make to generate a processor_id
  customer

  pay_customer.payment_methods.create!(
    processor_id: NanoId.generate,
    default: default,
    type: :fake,
    data: {
      brand: "Fake",
      last4: 1234,
      exp_month: Date.today.month,
      exp_year: Date.today.year
    }
  )
end
charge(amount, options = {}) click to toggle source
# File lib/pay/fake_processor/billable.rb, line 22
def charge(amount, options = {})
  # Make to generate a processor_id
  customer

  attributes = options.merge(
    processor_id: NanoId.generate,
    amount: amount,
    data: {
      kind: :card,
      type: :fake,
      last4: 1234,
      exp_month: Date.today.month,
      exp_year: Date.today.year
    }
  )
  pay_customer.charges.create!(attributes)
end
customer() click to toggle source
# File lib/pay/fake_processor/billable.rb, line 17
def customer
  pay_customer.update!(processor_id: NanoId.generate) unless processor_id?
  pay_customer
end
processor_subscription(subscription_id, options = {}) click to toggle source
# File lib/pay/fake_processor/billable.rb, line 75
def processor_subscription(subscription_id, options = {})
  pay_customer.subscriptions.find_by(processor_id: subscription_id)
end
subscribe(name: Pay.default_product_name, plan: Pay.default_plan_name, **options) click to toggle source
# File lib/pay/fake_processor/billable.rb, line 40
def subscribe(name: Pay.default_product_name, plan: Pay.default_plan_name, **options)
  # Make to generate a processor_id
  customer

  attributes = options.merge(
    processor_id: NanoId.generate,
    name: name,
    processor_plan: plan,
    status: :active,
    quantity: options.fetch(:quantity, 1)
  )
  pay_customer.subscriptions.create!(attributes)
end
trial_end_date(subscription) click to toggle source
# File lib/pay/fake_processor/billable.rb, line 79
def trial_end_date(subscription)
  Date.today
end
update_email!() click to toggle source
# File lib/pay/fake_processor/billable.rb, line 71
def update_email!
  # pass
end