Sha256: eaef2681beda67e477c9b6e4a92152564a41a03572c0f7ee5aec5372e59bce1d

Contents?: true

Size: 1.76 KB

Versions: 3

Compression:

Stored size: 1.76 KB

Contents

module Mollie
  class Refund < Base
    STATUS_QUEUED     = 'queued'.freeze
    STATUS_PENDING    = 'pending'.freeze
    STATUS_PROCESSING = 'processing'.freeze
    STATUS_REFUNDED   = 'refunded'.freeze
    STATUS_FAILED     = 'failed'.freeze

    attr_accessor :id,
                  :amount,
                  :settlement_id,
                  :settlement_amount,
                  :status,
                  :lines,
                  :payment_id,
                  :order_id,
                  :description,
                  :metadata,
                  :created_at,
                  :_links

    alias links _links

    def queued?
      status == STATUS_QUEUED
    end

    def pending?
      status == STATUS_PENDING
    end

    def processing?
      status == STATUS_PROCESSING
    end

    def refunded?
      status == STATUS_REFUNDED
    end

    def failed?
      status == STATUS_FAILED
    end

    def amount=(amount)
      @amount = Amount.new(amount)
    end

    def settlement_amount=(settlement_amount)
      @settlement_amount = Amount.new(settlement_amount)
    end

    def metadata=(metadata)
      @metadata = OpenStruct.new(metadata) if metadata.is_a?(Hash)
    end

    def lines=(lines)
      @lines = lines.map { |line| Order::Line.new(line) }
    end

    def created_at=(created_at)
      @created_at = begin
                      Time.parse(created_at)
                    rescue StandardError
                      nil
                    end
    end

    def payment(options = {})
      Payment.get(payment_id, options)
    end

    def settlement(options = {})
      return if settlement_id.nil?
      Settlement.get(settlement_id, options)
    end

    def order(options = {})
      return if order_id.nil?
      Order.get(order_id, options)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mollie-api-ruby-4.14.0 lib/mollie/refund.rb
mollie-api-ruby-4.7.1 lib/mollie/refund.rb
mollie-api-ruby-4.7.0 lib/mollie/refund.rb