Class: LemonSqueezy::Checkout

Inherits:
Object
  • Object
show all
Defined in:
lib/lemon_squeezy/models/checkout.rb

Class Method Summary collapse

Methods inherited from Object

#initialize, #to_ostruct

Constructor Details

This class inherits a constructor from LemonSqueezy::Object

Class Method Details

.create(store_id:, variant_id:, **attrs) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/lemon_squeezy/models/checkout.rb', line 16

def create(store_id:, variant_id:, **attrs)
  data = {}

  data["type"] = "checkouts"

  data["relationships"] = {
    store: {
      data: {
        type: "stores",
        id: store_id.to_s
      }
    },
    variant: {
      data: {
        type: "variants",
        id: variant_id.to_s
      }
    }
  }

  data["attributes"] = attrs

  response = Client.post_request("checkouts", body: {data: data}.to_json)

  Checkout.new(response.body["data"]) if response.success?
end

.list(**params) ⇒ Object



6
7
8
9
# File 'lib/lemon_squeezy/models/checkout.rb', line 6

def list(**params)
  response = Client.get_request("checkouts", params: {filter: params})
  Collection.from_response(response, type: Checkout)
end

.retrieve(id:) ⇒ Object



11
12
13
14
# File 'lib/lemon_squeezy/models/checkout.rb', line 11

def retrieve(id:)
  response = Client.get_request("checkouts/#{id}")
  Checkout.new(response.body["data"]) if response.success?
end