Class: PayjpMock::Response::Resource::Subscription

Inherits:
Base
  • Object
show all
Defined in:
lib/payjp_mock/response/resource/subscription.rb

Constant Summary collapse

PREFIX =
'sub'.freeze
OBJECT =
'subscription'.freeze

Instance Attribute Summary

Attributes inherited from Base

#attributes

Instance Method Summary collapse

Methods inherited from Base

#initialize, #set, #status

Methods included from Util

#generate_fingerprint, #generate_resource_id

Methods inherited from Base

#body, #exception, #status, #to_h

Constructor Details

This class inherits a constructor from PayjpMock::Response::Resource::Base

Instance Method Details

#canonicalize(key, value) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/payjp_mock/response/resource/subscription.rb', line 33

def canonicalize(key, value)
  case key
  when :plan
    { plan: Plan.new(id: value).to_h }
  when :trial_end
    now = Time.now.to_i
    { status: 'trial', trial_start: now - 10.days, trial_end: value }
  else
    super
  end
end

#default_attributesObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/payjp_mock/response/resource/subscription.rb', line 9

def default_attributes
  now = Time.now.to_i

  {
    canceled_at:          nil,
    created:              now,
    current_period_end:   now + 15.days,
    current_period_start: now - 15.days,
    customer:             generate_resource_id(Customer::PREFIX),
    id:                   generate_resource_id(PREFIX),
    livemode:             false,
    metadata:             nil,
    object:               OBJECT,
    paused_at:            nil,
    plan:                 Plan.new.to_h,
    resumed_at:           nil,
    start:                now - 15.days,
    status:               'active',
    trial_end:            nil,
    trial_start:          nil,
    prorate:              false
  }
end