Class: Stripe::InvoiceItemService

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

Instance Method Summary collapse

Methods inherited from StripeService

#initialize, #request, #request_stream

Constructor Details

This class inherits a constructor from Stripe::StripeService

Instance Method Details

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

Creates an item to be added to a draft invoice (up to 250 items per invoice). If no invoice is specified, the item will be on the next invoice created for the customer specified.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/stripe/services/invoice_item_service.rb', line 7

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

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

#delete(invoiceitem, params = {}, opts = {}) ⇒ Object

Deletes an invoice item, removing it from an invoice. Deleting invoice items is only possible when they’re not attached to invoices, or if it’s attached to a draft invoice.



20
21
22
23
24
25
26
27
28
# File 'lib/stripe/services/invoice_item_service.rb', line 20

def delete(invoiceitem, params = {}, opts = {})
  request(
    method: :delete,
    path: format("/v1/invoiceitems/%<invoiceitem>s", { invoiceitem: CGI.escape(invoiceitem) }),
    params: params,
    opts: opts,
    base_address: :api
  )
end

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

Returns a list of your invoice items. Invoice items are returned sorted by creation date, with the most recently created invoice items appearing first.



31
32
33
34
35
36
37
38
39
# File 'lib/stripe/services/invoice_item_service.rb', line 31

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

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

Retrieves the invoice item with the given ID.



42
43
44
45
46
47
48
49
50
# File 'lib/stripe/services/invoice_item_service.rb', line 42

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

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

Serializes an InvoiceItem create request into a batch job JSONL line.



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/stripe/services/invoice_item_service.rb', line 53

def serialize_batch_create(params = {}, opts = {})
  request_id = SecureRandom.uuid
  stripe_version = opts[:stripe_version] || Stripe.api_version

  request_body = {
    id: request_id,
    params: params,
    stripe_version: stripe_version,
  }
  request_body[:context] = opts[:stripe_context] if opts[:stripe_context]
  JSON.generate(request_body)
end

#serialize_batch_delete(invoiceitem, params = {}, opts = {}) ⇒ Object

Serializes an InvoiceItem delete request into a batch job JSONL line.



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

def serialize_batch_delete(invoiceitem, params = {}, opts = {})
  request_id = SecureRandom.uuid
  stripe_version = opts[:stripe_version] || Stripe.api_version

  request_body = {
    id: request_id,
    params: params,
    stripe_version: stripe_version,
  }
  request_body[:path_params] = { invoiceitem: invoiceitem }
  request_body[:context] = opts[:stripe_context] if opts[:stripe_context]
  JSON.generate(request_body)
end

#serialize_batch_update(invoiceitem, params = {}, opts = {}) ⇒ Object

Serializes an InvoiceItem update request into a batch job JSONL line.



82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/stripe/services/invoice_item_service.rb', line 82

def serialize_batch_update(invoiceitem, params = {}, opts = {})
  request_id = SecureRandom.uuid
  stripe_version = opts[:stripe_version] || Stripe.api_version

  request_body = {
    id: request_id,
    params: params,
    stripe_version: stripe_version,
  }
  request_body[:path_params] = { invoiceitem: invoiceitem }
  request_body[:context] = opts[:stripe_context] if opts[:stripe_context]
  JSON.generate(request_body)
end

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

Updates the amount or description of an invoice item on an upcoming invoice. Updating an invoice item is only possible before the invoice it’s attached to is closed.



97
98
99
100
101
102
103
104
105
106
107
# File 'lib/stripe/services/invoice_item_service.rb', line 97

def update(invoiceitem, params = {}, opts = {})
  params = ::Stripe::InvoiceItemUpdateParams.coerce_params(params) unless params.is_a?(Stripe::RequestParams)

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