Class: Openpix::RubySdk::Resources::Charge

Inherits:
Resource
  • Object
show all
Defined in:
lib/openpix/ruby_sdk/resources/charge.rb

Overview

Make API operations on Charge resource

Constant Summary collapse

ATTRS =
%w[
  correlationID
  value
  type
  comment
  identifier
  expiresIn
  customer
  daysForDueDate
  daysAfterDueDate
  interests
  fines
  additionalInfo
].freeze

Instance Method Summary collapse

Methods inherited from Resource

#destroy, #destroy!, #fetch, #fetch!, #fetch_next_page!, #fetch_previous_page!, #find, #find!, #initialize, #save, #save!, #to_collection_resource, #to_single_resource

Constructor Details

This class inherits a constructor from Openpix::RubySdk::Resources::Resource

Instance Method Details

#add_additional_info(key, value) ⇒ Object

add a new additional_info

Parameters:

  • key (String)

    the key

  • value (String)

    the value



63
64
65
66
67
# File 'lib/openpix/ruby_sdk/resources/charge.rb', line 63

def add_additional_info(key, value)
  @additionalInfo = [] if @additionalInfo.nil?

  @additionalInfo << { 'key' => key, 'value' => value }
end

#create_attributesObject

attributes used on POST create method



35
36
37
# File 'lib/openpix/ruby_sdk/resources/charge.rb', line 35

def create_attributes
  ATTRS
end

#init_body(params: {}, rest: {}) ⇒ Object

Parameters:

  • params (Hash) (defaults to: {})

    the attributes for creating a Charge

  • rest (Hash) (defaults to: {})

    more attributes to be merged at the body, use this only for unsupported fields



30
31
32
# File 'lib/openpix/ruby_sdk/resources/charge.rb', line 30

def init_body(params: {}, rest: {})
  super(base_attrs: ATTRS, params: params, rest: rest)
end

#set_fines(value) ⇒ Object

set fines configuration for creating this resource

Parameters:

  • value (Number)

    value in basis points of fines to be applied when the charge hits the deadline



77
78
79
# File 'lib/openpix/ruby_sdk/resources/charge.rb', line 77

def set_fines(value)
  @fines = { 'value' => value }
end

#set_interests(value) ⇒ Object

set interests configuration for creating this resource

Parameters:

  • value (Number)

    value in basis points of interests to be applied daily after the charge hits the deadline



71
72
73
# File 'lib/openpix/ruby_sdk/resources/charge.rb', line 71

def set_interests(value)
  @interests = { 'value' => value }
end

#to_bodyObject

Converts its attributes into a hash



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/openpix/ruby_sdk/resources/charge.rb', line 45

def to_body
  body = super

  return body if body['customer'].nil? || body['customer'].empty?

  body['customer'] = Openpix::RubySdk::ApiBodyFormatter.remove_empty_values(body['customer'])

  return body if body['customer']['address'].nil? || body['customer']['address'].empty?

  customer_address_parsed = Openpix::RubySdk::ApiBodyFormatter.remove_empty_values(body['customer']['address'])
  body['customer'] = body['customer'].merge({ 'address' => customer_address_parsed })

  body
end

#to_urlObject

URL for this resource



40
41
42
# File 'lib/openpix/ruby_sdk/resources/charge.rb', line 40

def to_url
  'charge'
end