Class: Sendara::CheckoutResult

Inherits:
Object
  • Object
show all
Defined in:
lib/sendara/checkout_result.rb

Overview

Result of POST /v1/billing/checkout. A new subscription has a URL to redirect to; an existing subscription reports the plan changed in place.

Constant Summary collapse

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url: nil, updated:, plan: nil) ⇒ CheckoutResult

Returns a new instance of CheckoutResult.



23
24
25
26
27
28
# File 'lib/sendara/checkout_result.rb', line 23

def initialize(url: nil, updated:, plan: nil)
  @url = url
  @updated = updated
  @plan = plan
  freeze
end

Instance Attribute Details

#planObject (readonly)

Returns the value of attribute plan.



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

def plan
  @plan
end

#urlObject (readonly)

Returns the value of attribute url.



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

def url
  @url
end

Class Method Details

.from_response(response) ⇒ Object

Raises:



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/sendara/checkout_result.rb', line 11

def self.from_response(response)
  url = response["url"]
  return new(url: url, updated: false) if url.is_a?(String) && !url.empty?

  plan = response["plan"]
  if response["updated"] == true && PLANS.include?(plan)
    return new(updated: true, plan: plan)
  end

  raise Error, "Billing checkout returned neither a checkout URL nor an updated plan"
end

Instance Method Details

#redirect?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/sendara/checkout_result.rb', line 34

def redirect?
  !@url.nil?
end

#updated?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/sendara/checkout_result.rb', line 30

def updated?
  @updated
end