Class: Xendit::Invoice

Inherits:
Object
  • Object
show all
Defined in:
lib/xendit/resources/invoice.rb

Class Method Summary collapse

Class Method Details

.create(invoice_params) ⇒ Object

rubocop:disable Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/PerceivedComplexity

Raises:

  • (ArgumentError)


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/xendit/resources/invoice.rb', line 24

def create(invoice_params)
  # validation
  raise ArgumentError, 'invoice body payload is required' \
      if invoice_params.nil? || invoice_params.empty?
  raise ArgumentError, 'payer_email is required and should be a string' \
      if invoice_params[:payer_email].nil? ||
         !invoice_params[:payer_email].is_a?(String)
  raise ArgumentError, 'external_id is required and should be a string' \
      if invoice_params[:external_id].nil? ||
         !invoice_params[:external_id].is_a?(String)
  raise ArgumentError, 'description is required and should be a string' \
      if invoice_params[:description].nil? ||
         !invoice_params[:description].is_a?(String)
  raise ArgumentError, 'amount is required and should be an integer or float' \
      if invoice_params[:amount].nil? ||
         (!invoice_params[:amount].is_a?(Integer) &&
         !invoice_params[:amount].is_a?(Float))

  resp = Xendit::ApiOperations.post('v2/invoices', **invoice_params)
  Xendit::Response.handle_error_response resp

  JSON.parse resp.body
end

.expire(invoice_id) ⇒ Object

rubocop:enable Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/PerceivedComplexity

Raises:

  • (ArgumentError)


49
50
51
52
53
54
55
56
57
58
# File 'lib/xendit/resources/invoice.rb', line 49

def expire(invoice_id)
  # validation
  raise ArgumentError, 'invoice_id is required and should be a string' \
      if invoice_id.nil? || !invoice_id.is_a?(String)

  resp = Xendit::ApiOperations.post "invoices/#{invoice_id}/expire!"
  Xendit::Response.handle_error_response resp

  JSON.parse resp.body
end

.get(invoice_id) ⇒ Object

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
20
21
# File 'lib/xendit/resources/invoice.rb', line 12

def get(invoice_id)
  # validation
  raise ArgumentError, 'invoice_id is required and should be a string' \
      if invoice_id.nil? || !invoice_id.is_a?(String)

  resp = Xendit::ApiOperations.get "v2/invoices/#{invoice_id}"
  Xendit::Response.handle_error_response resp

  JSON.parse resp.body
end

.get_all(filter_params = nil) ⇒ Object



60
61
62
63
64
65
# File 'lib/xendit/resources/invoice.rb', line 60

def get_all(filter_params = nil)
  resp = Xendit::ApiOperations.get('v2/invoices', filter_params)
  Xendit::Response.handle_error_response resp

  JSON.parse resp.body
end