Class: Stripe::Checkout::SessionService

Inherits:
StripeService show all
Defined in:
lib/stripe/services/checkout/session_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from StripeService

#request, #request_stream

Constructor Details

#initialize(requestor) ⇒ SessionService

Returns a new instance of SessionService.



9
10
11
12
# File 'lib/stripe/services/checkout/session_service.rb', line 9

def initialize(requestor)
  super
  @line_items = Stripe::Checkout::SessionLineItemService.new(@requestor)
end

Instance Attribute Details

#line_itemsObject (readonly)

Returns the value of attribute line_items.



7
8
9
# File 'lib/stripe/services/checkout/session_service.rb', line 7

def line_items
  @line_items
end

Instance Method Details

#create(params = {}, opts = {}) ⇒ Object

Creates a Checkout Session object.



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/stripe/services/checkout/session_service.rb', line 15

def create(params = {}, opts = {})
  unless params.is_a?(Stripe::RequestParams)
    params = ::Stripe::Checkout::SessionCreateParams.coerce_params(params)
  end

  request(
    method: :post,
    path: "/v1/checkout/sessions",
    params: params,
    opts: opts,
    base_address: :api
  )
end

#expire(session, params = {}, opts = {}) ⇒ Object

A Checkout Session can be expired when it is in one of these statuses: open

After it expires, a customer can’t complete a Checkout Session and customers loading the Checkout Session see a message saying the Checkout Session is expired.



32
33
34
35
36
37
38
39
40
# File 'lib/stripe/services/checkout/session_service.rb', line 32

def expire(session, params = {}, opts = {})
  request(
    method: :post,
    path: format("/v1/checkout/sessions/%<session>s/expire", { session: CGI.escape(session) }),
    params: params,
    opts: opts,
    base_address: :api
  )
end

#list(params = {}, opts = {}) ⇒ Object

Returns a list of Checkout Sessions.



43
44
45
46
47
48
49
50
51
# File 'lib/stripe/services/checkout/session_service.rb', line 43

def list(params = {}, opts = {})
  request(
    method: :get,
    path: "/v1/checkout/sessions",
    params: params,
    opts: opts,
    base_address: :api
  )
end

#retrieve(session, params = {}, opts = {}) ⇒ Object

Retrieves a Checkout Session object.



54
55
56
57
58
59
60
61
62
# File 'lib/stripe/services/checkout/session_service.rb', line 54

def retrieve(session, params = {}, opts = {})
  request(
    method: :get,
    path: format("/v1/checkout/sessions/%<session>s", { session: CGI.escape(session) }),
    params: params,
    opts: opts,
    base_address: :api
  )
end

#update(session, params = {}, opts = {}) ⇒ Object

Updates a Checkout Session object.

Related guide: [Dynamically update a Checkout Session](docs.stripe.com/payments/advanced/dynamic-updates)



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/stripe/services/checkout/session_service.rb', line 67

def update(session, params = {}, opts = {})
  unless params.is_a?(Stripe::RequestParams)
    params = ::Stripe::Checkout::SessionUpdateParams.coerce_params(params)
  end

  request(
    method: :post,
    path: format("/v1/checkout/sessions/%<session>s", { session: CGI.escape(session) }),
    params: params,
    opts: opts,
    base_address: :api
  )
end