Class: CDEKApiClient::Entities::Payment

Inherits:
Object
  • Object
show all
Includes:
Validatable
Defined in:
lib/cdek_api_client/entities/payment.rb

Overview

Represents a payment entity in the CDEK API. Each payment includes attributes such as value and currency.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Validatable

included, #validate!

Constructor Details

#initialize(value:, currency:) ⇒ Payment

Initializes a new Payment object.

Parameters:

  • value (Integer)

    the payment value.

  • currency (String)

    the currency code for the payment.

Raises:

  • (ArgumentError)

    if any attribute validation fails.



23
24
25
26
27
# File 'lib/cdek_api_client/entities/payment.rb', line 23

def initialize(value:, currency:)
  @value = value
  @currency = CurrencyMapper.to_code(currency)
  validate!
end

Instance Attribute Details

#currencyObject

Returns the value of attribute currency.



13
14
15
# File 'lib/cdek_api_client/entities/payment.rb', line 13

def currency
  @currency
end

#valueObject

Returns the value of attribute value.



13
14
15
# File 'lib/cdek_api_client/entities/payment.rb', line 13

def value
  @value
end

Instance Method Details

#to_json(*_args) ⇒ String

Converts the Payment object to a JSON representation.

Returns:

  • (String)

    the JSON representation of the Payment.



32
33
34
35
36
37
# File 'lib/cdek_api_client/entities/payment.rb', line 32

def to_json(*_args)
  {
    value: @value,
    currency: @currency
  }.to_json
end