Class: Pay::FakeProcessor::Customer
- Inherits:
-
Customer
show all
- Defined in:
- app/models/pay/fake_processor/customer.rb
Instance Method Summary
collapse
Methods inherited from Customer
#active?, #customer_name, #deleted?, #has_incomplete_payment?, #on_generic_trial?, #on_trial?, #on_trial_or_subscribed?, #retry_past_due_subscriptions!, #subscribed?, #subscription, #update_payment_method
Instance Method Details
#add_payment_method(payment_method_id, default: false) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'app/models/pay/fake_processor/customer.rb', line 57
def add_payment_method(payment_method_id, default: false)
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, options = {})
api_record
valid_attributes = options.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
|
# File 'app/models/pay/fake_processor/customer.rb', line 37
def subscribe(name: Pay.default_product_name, plan: Pay.default_plan_name, **options)
api_record
attributes = options.merge(
processor_id: NanoId.generate,
name: name,
processor_plan: plan,
status: :active,
quantity: options.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)
subscriptions.create!(attributes)
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
|