Class: Unit::Account::Credit::CreateAccountRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/unit/models/account/credit/create_account_request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(credit_terms, credit_limit, customer_id = nil, tags = nil, idempotency_key = nil) ⇒ CreateAccountRequest

Returns a new instance of CreateAccountRequest.

Parameters:

  • credit_terms (String)
  • credit_limit (Integer)
  • customer_id (String) (defaults to: nil)
    • optional

  • tags (Hash) (defaults to: nil)
    • optional

  • idempotency_key (String) (defaults to: nil)
    • optional



16
17
18
19
20
21
22
# File 'lib/unit/models/account/credit/create_account_request.rb', line 16

def initialize(credit_terms, credit_limit, customer_id = nil, tags = nil, idempotency_key = nil)
  @credit_terms = credit_terms
  @credit_limit = credit_limit
  @customer_id = customer_id
  @tags = tags
  @idempotency_key = idempotency_key
end

Instance Attribute Details

#credit_limitObject (readonly)

Returns the value of attribute credit_limit.



9
10
11
# File 'lib/unit/models/account/credit/create_account_request.rb', line 9

def credit_limit
  @credit_limit
end

#credit_termsObject (readonly)

Returns the value of attribute credit_terms.



9
10
11
# File 'lib/unit/models/account/credit/create_account_request.rb', line 9

def credit_terms
  @credit_terms
end

#customer_idObject (readonly)

Returns the value of attribute customer_id.



9
10
11
# File 'lib/unit/models/account/credit/create_account_request.rb', line 9

def customer_id
  @customer_id
end

#idempotency_keyObject (readonly)

Returns the value of attribute idempotency_key.



9
10
11
# File 'lib/unit/models/account/credit/create_account_request.rb', line 9

def idempotency_key
  @idempotency_key
end

#tagsObject (readonly)

Returns the value of attribute tags.



9
10
11
# File 'lib/unit/models/account/credit/create_account_request.rb', line 9

def tags
  @tags
end

Instance Method Details

#to_json_apiObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/unit/models/account/credit/create_account_request.rb', line 24

def to_json_api
  payload = {
    data: {
      type: "creditAccount",
      attributes: {
        creditTerms: credit_terms,
        creditLimit: credit_limit,
        tags: tags
      },
      relationships: {
        customer: Unit::Types::Relationship.new("customer", customer_id).to_hash
      }
    }
  }
  payload[:data][:attributes].compact!
  payload.to_json
end