Class: Pay::FakeProcessor::Customer
- Inherits:
-
Customer
- Object
- Customer
- Pay::FakeProcessor::Customer
- Defined in:
- app/models/pay/fake_processor/customer.rb
Instance Method Summary collapse
- #add_payment_method(payment_method_id, default: false) ⇒ Object
- #api_record ⇒ Object
- #charge(amount, options = {}) ⇒ Object
- #subscribe(name: Pay.default_product_name, plan: Pay.default_plan_name, **options) ⇒ Object
- #sync_subscriptions(**options) ⇒ Object
- #update_api_record(**attributes) ⇒ Object
Instance Method Details
#add_payment_method(payment_method_id, default: false) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/models/pay/fake_processor/customer.rb', line 62 def add_payment_method(payment_method_id, default: false) # Make to generate a processor_id api_record pay_payment_method = payment_methods.create!( processor_id: NanoId.generate, default: default, payment_method_type: :card, data: { brand: "Fake", last4: 1234, exp_month: Date.today.month, exp_year: Date.today.year } ) if default payment_methods.where.not(id: pay_payment_method.id).update_all(default: false) reload_default_payment_method end pay_payment_method end |
#api_record ⇒ Object
9 10 11 12 |
# File 'app/models/pay/fake_processor/customer.rb', line 9 def api_record update!(processor_id: NanoId.generate) unless processor_id? self end |
#charge(amount, options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/models/pay/fake_processor/customer.rb', line 18 def charge(amount, = {}) # Make to generate a processor_id api_record 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) charges.create!(attributes) end |
#subscribe(name: Pay.default_product_name, plan: Pay.default_plan_name, **options) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/models/pay/fake_processor/customer.rb', line 37 def subscribe(name: Pay.default_product_name, plan: Pay.default_plan_name, **) # Make to generate a processor_id api_record 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 # Ignore any keys that aren't attribute names attributes.deep_stringify_keys!.slice!(*subscriptions.attribute_names) subscriptions.create!(attributes) end |
#sync_subscriptions(**options) ⇒ Object
58 59 60 |
# File 'app/models/pay/fake_processor/customer.rb', line 58 def sync_subscriptions(**) [] end |
#update_api_record(**attributes) ⇒ Object
14 15 16 |
# File 'app/models/pay/fake_processor/customer.rb', line 14 def update_api_record(**attributes) self end |