Sha256: 14568e1a481e93546903825687c0dd68cf5009d14d7b92d6e3e1407164cadace

Contents?: true

Size: 1.15 KB

Versions: 4

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

module CoinsPaid
  module API
    class CallbackData < Dry::Struct
      NOT_CONFIRMED = 'not_confirmed'
      CANCELLED = 'cancelled'

      attribute :id, Types::Integer
      attribute? :foreign_id, Types::String
      attribute? :type, Types::String
      attribute? :status, Types::String
      attribute? :error, Types::Coercible::String

      attribute? :crypto_address do
        attribute :currency, Types::String
      end

      attribute? :transactions, Types::Array do
        attribute :transaction_type, Types::String
        attribute :type, Types::String
        attribute :id, Types::Integer
      end

      attribute? :currency_sent do
        attribute :amount, Types::String
      end

      attribute? :currency_received do
        attribute :amount, Types::String
        attribute? :amount_minus_fee, Types::String
      end

      def self.from_json(attributes)
        attributes[:foreign_id] ||= attributes.dig(:crypto_address, :foreign_id) || ''
        new(attributes)
      end

      def pending?
        status == NOT_CONFIRMED
      end

      def cancelled?
        status == CANCELLED
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
coins_paid_api-1.1.0 lib/coins_paid/api/callback_data.rb
coins_paid_api-1.0.7 lib/coins_paid/api/callback_data.rb
coins_paid_api-1.0.6 lib/coins_paid/api/callback_data.rb
coins_paid_api-1.0.5 lib/coins_paid/api/callback_data.rb