Class: Pay::FakeProcessor::Billable
- Inherits:
-
Object
- Object
- Pay::FakeProcessor::Billable
- Defined in:
- lib/pay/fake_processor/billable.rb
Instance Attribute Summary collapse
-
#pay_customer ⇒ Object
readonly
Returns the value of attribute pay_customer.
Instance Method Summary collapse
- #add_payment_method(payment_method_id, default: false) ⇒ Object
- #charge(amount, options = {}) ⇒ Object
- #customer ⇒ Object
-
#initialize(pay_customer) ⇒ Billable
constructor
A new instance of Billable.
- #processor_subscription(subscription_id, options = {}) ⇒ Object
- #subscribe(name: Pay.default_product_name, plan: Pay.default_plan_name, **options) ⇒ Object
- #trial_end_date(subscription) ⇒ Object
- #update_customer!(**attributes) ⇒ Object
Constructor Details
#initialize(pay_customer) ⇒ Billable
Returns a new instance of Billable.
13 14 15 |
# File 'lib/pay/fake_processor/billable.rb', line 13 def initialize(pay_customer) @pay_customer = pay_customer end |
Instance Attribute Details
#pay_customer ⇒ Object (readonly)
Returns the value of attribute pay_customer.
4 5 6 |
# File 'lib/pay/fake_processor/billable.rb', line 4 def pay_customer @pay_customer end |
Instance Method Details
#add_payment_method(payment_method_id, default: false) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/pay/fake_processor/billable.rb', line 66 def add_payment_method(payment_method_id, default: false) # Make to generate a processor_id customer pay_payment_method = pay_customer.payment_methods.create!( processor_id: NanoId.generate, default: default, type: :card, data: { brand: "Fake", last4: 1234, exp_month: Date.today.month, exp_year: Date.today.year } ) if default pay_customer.payment_methods.where.not(id: pay_payment_method.id).update_all(default: false) pay_customer.reload_default_payment_method end pay_payment_method end |
#charge(amount, options = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/pay/fake_processor/billable.rb', line 27 def charge(amount, = {}) # Make to generate a processor_id customer valid_attributes = .slice(*Pay::Charge.attribute_names.map(&:to_sym)) attributes = { processor_id: NanoId.generate, amount: amount, data: { payment_method_type: :card, brand: "Fake", last4: 1234, exp_month: Date.today.month, exp_year: Date.today.year } }.deep_merge(valid_attributes) pay_customer.charges.create!(attributes) end |
#customer ⇒ Object
17 18 19 20 |
# 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 = {}) ⇒ Object
90 91 92 |
# File 'lib/pay/fake_processor/billable.rb', line 90 def processor_subscription(subscription_id, = {}) pay_customer.subscriptions.find_by(processor_id: subscription_id) end |
#subscribe(name: Pay.default_product_name, plan: Pay.default_plan_name, **options) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/pay/fake_processor/billable.rb', line 46 def subscribe(name: Pay.default_product_name, plan: Pay.default_plan_name, **) # Make to generate a processor_id customer attributes = .merge( processor_id: NanoId.generate, name: name, processor_plan: plan, status: :active, quantity: .fetch(:quantity, 1) ) if (trial_period_days = attributes.delete(:trial_period_days)) attributes[:trial_ends_at] = trial_period_days.to_i.days.from_now end attributes.delete(:promotion_code) pay_customer.subscriptions.create!(attributes) end |
#trial_end_date(subscription) ⇒ Object
94 95 96 |
# File 'lib/pay/fake_processor/billable.rb', line 94 def trial_end_date(subscription) Date.today end |
#update_customer!(**attributes) ⇒ Object
22 23 24 25 |
# File 'lib/pay/fake_processor/billable.rb', line 22 def update_customer!(**attributes) # return customer to fake an update customer end |