Class: Sendara::Resources::Billing

Inherits:
Sendara::Resource show all
Defined in:
lib/sendara/resources/billing.rb

Constant Summary collapse

PLANS =
%w[starter pro growth scale].freeze
PERIODS =
%w[month year].freeze

Instance Method Summary collapse

Methods inherited from Sendara::Resource

#initialize

Constructor Details

This class inherits a constructor from Sendara::Resource

Instance Method Details

#checkout(plan: nil, period: nil) ⇒ Object

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
20
21
22
# File 'lib/sendara/resources/billing.rb', line 13

def checkout(plan: nil, period: nil)
  plan = plan.to_s unless plan.nil?
  period = period.to_s unless period.nil?
  raise ArgumentError, "plan must be starter, pro, growth, or scale" if plan && !PLANS.include?(plan)
  raise ArgumentError, "period must be month or year" if period && !PERIODS.include?(period)

  body = compact_params("plan" => plan, "period" => period)
  response = request(:post, "/v1/billing/checkout", body: body) || {}
  CheckoutResult.from_response(response)
end

#getObject



9
10
11
# File 'lib/sendara/resources/billing.rb', line 9

def get
  request(:get, "/v1/billing") || {}
end

#portalObject



24
25
26
27
# File 'lib/sendara/resources/billing.rb', line 24

def portal
  response = request(:post, "/v1/billing/portal") || {}
  response["url"].to_s
end