Class: Whop_sdk::Invoices::Client
- Inherits:
-
Object
- Object
- Whop_sdk::Invoices::Client
- Defined in:
- lib/whop_sdk/invoices/client.rb
Instance Method Summary collapse
-
#create(request_options: {}, **params) ⇒ Whop_sdk::Types::Invoice
Create an invoice for a customer.
-
#delete(request_options: {}, **params) ⇒ Boolean
Delete a draft invoice.
- #initialize(client:) ⇒ void constructor
-
#list(request_options: {}, **params) ⇒ Whop_sdk::Invoices::Types::ListInvoicesResponse
Returns a paginated list of invoices for a company, with optional filtering by product, status, collection method, and creation date.
-
#mark_paid(request_options: {}, **params) ⇒ Boolean
Mark an open invoice as paid when payment was collected outside of Whop.
-
#mark_uncollectible(request_options: {}, **params) ⇒ Boolean
Mark an open invoice as uncollectible when payment is not expected.
-
#resend(request_options: {}, **params) ⇒ Boolean
Resend the notification email for an existing invoice to the customer.
-
#retrieve(request_options: {}, **params) ⇒ Whop_sdk::Types::Invoice
Retrieves the details of an existing invoice.
-
#update(request_options: {}, **params) ⇒ Whop_sdk::Types::Invoice
Update a draft invoice's details.
-
#void(request_options: {}, **params) ⇒ Boolean
Void an open invoice so it can no longer be paid.
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/whop_sdk/invoices/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#create(request_options: {}, **params) ⇒ Whop_sdk::Types::Invoice
Create an invoice for a customer. The invoice can be charged automatically using a stored payment method, or sent to the customer for manual payment.
Required permissions:
invoice:createmember:email:readmember:basic:readpayment:basic:read
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/whop_sdk/invoices/client.rb', line 122 def create(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "invoices", body: Whop_sdk::Invoices::Types::CreateInvoicesRequest.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Whop_sdk::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Whop_sdk::Types::Invoice.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#delete(request_options: {}, **params) ⇒ Boolean
Delete a draft invoice.
Required permissions:
invoice:update
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/whop_sdk/invoices/client.rb', line 206 def delete(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "DELETE", path: "invoices/#{URI.encode_uri_component(params[:id].to_s)}", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Whop_sdk::Errors::TimeoutError end code = response.code.to_i return if code.between?(200, 299) error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end |
#list(request_options: {}, **params) ⇒ Whop_sdk::Invoices::Types::ListInvoicesResponse
Returns a paginated list of invoices for a company, with optional filtering by product, status, collection method, and creation date.
Required permissions:
invoice:basic:read
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/whop_sdk/invoices/client.rb', line 49 def list(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) query_params = {} query_params["after"] = params[:after] if params.key?(:after) query_params["before"] = params[:before] if params.key?(:before) query_params["first"] = params[:first] if params.key?(:first) query_params["last"] = params[:last] if params.key?(:last) query_params["company_id"] = params[:company_id] if params.key?(:company_id) query_params["direction"] = params[:direction] if params.key?(:direction) query_params["product_ids"] = params[:product_ids] if params.key?(:product_ids) query_params["collection_methods"] = params[:collection_methods] if params.key?(:collection_methods) query_params["statuses"] = params[:statuses] if params.key?(:statuses) query_params["order"] = params[:order] if params.key?(:order) query_params["created_before"] = params[:created_before] if params.key?(:created_before) query_params["created_after"] = params[:created_after] if params.key?(:created_after) Whop_sdk::Internal::CursorItemIterator.new( cursor_field: :end_cursor, item_field: :data, initial_cursor: query_params["after"] ) do |next_cursor| query_params["after"] = next_cursor request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "invoices", query: query_params, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Whop_sdk::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) parsed_response = Whop_sdk::Invoices::Types::ListInvoicesResponse.load(response.body) [parsed_response, response] else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end end |
#mark_paid(request_options: {}, **params) ⇒ Boolean
Mark an open invoice as paid when payment was collected outside of Whop.
Required permissions:
invoice:update
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
# File 'lib/whop_sdk/invoices/client.rb', line 292 def mark_paid(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "invoices/#{URI.encode_uri_component(params[:id].to_s)}/mark_paid", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Whop_sdk::Errors::TimeoutError end code = response.code.to_i return if code.between?(200, 299) error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end |
#mark_uncollectible(request_options: {}, **params) ⇒ Boolean
Mark an open invoice as uncollectible when payment is not expected.
Required permissions:
invoice:update
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
# File 'lib/whop_sdk/invoices/client.rb', line 330 def mark_uncollectible(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "invoices/#{URI.encode_uri_component(params[:id].to_s)}/mark_uncollectible", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Whop_sdk::Errors::TimeoutError end code = response.code.to_i return if code.between?(200, 299) error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end |
#resend(request_options: {}, **params) ⇒ Boolean
Resend the notification email for an existing invoice to the customer.
Required permissions:
invoice:update
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
# File 'lib/whop_sdk/invoices/client.rb', line 368 def resend(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "invoices/#{URI.encode_uri_component(params[:id].to_s)}/resend", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Whop_sdk::Errors::TimeoutError end code = response.code.to_i return if code.between?(200, 299) error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end |
#retrieve(request_options: {}, **params) ⇒ Whop_sdk::Types::Invoice
Retrieves the details of an existing invoice.
Required permissions:
invoice:basic:readmember:email:readmember:basic:readpayment:basic:read
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/whop_sdk/invoices/client.rb', line 166 def retrieve(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "invoices/#{URI.encode_uri_component(params[:id].to_s)}", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Whop_sdk::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Whop_sdk::Types::Invoice.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#update(request_options: {}, **params) ⇒ Whop_sdk::Types::Invoice
Update a draft invoice's details.
Required permissions:
invoice:updatemember:email:readmember:basic:readpayment:basic:read
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'lib/whop_sdk/invoices/client.rb', line 247 def update(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request_data = Whop_sdk::Invoices::Types::UpdateInvoicesRequest.new(params).to_h non_body_param_names = %w[id] body = request_data.except(*non_body_param_names) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "PATCH", path: "invoices/#{URI.encode_uri_component(params[:id].to_s)}", body: body, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Whop_sdk::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Whop_sdk::Types::Invoice.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#void(request_options: {}, **params) ⇒ Boolean
Void an open invoice so it can no longer be paid. Voiding is permanent and cannot be undone.
Required permissions:
invoice:update
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 |
# File 'lib/whop_sdk/invoices/client.rb', line 406 def void(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "invoices/#{URI.encode_uri_component(params[:id].to_s)}/void", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Whop_sdk::Errors::TimeoutError end code = response.code.to_i return if code.between?(200, 299) error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end |