Class: Portmone::Responses::OrderStatus

Inherits:
BaseResponse show all
Defined in:
lib/portmone/responses/order_status.rb

Direct Known Subclasses

RefundOrderStatus

Instance Attribute Summary

Attributes inherited from BaseResponse

#response, #xml_data

Instance Method Summary collapse

Methods inherited from BaseResponse

#http_status, #initialize

Constructor Details

This class inherits a constructor from Portmone::Responses::BaseResponse

Instance Method Details

#actual_amountObject



39
40
41
# File 'lib/portmone/responses/order_status.rb', line 39

def actual_amount
  amount + reversed_amount
end

#amountObject



27
28
29
30
31
# File 'lib/portmone/responses/order_status.rb', line 27

def amount
  transactions.select(&:paid?)
              .map { |t| t.bill_amount }
              .inject(:+) || transactions.first&.bill_amount
end

#orderObject



68
69
70
71
72
73
74
75
76
# File 'lib/portmone/responses/order_status.rb', line 68

def order
  @order ||= begin
    if data
      Portmone::Transaction.new(data.first.merge(data.last).merge(timezone: @timezone, currency: @currency))
    else
      Portmone::Transaction.new(timezone: @timezone, currency: @currency)
    end
  end
end

#paid?Boolean

статусы “оплачено” и “авторизовано”

Returns:

  • (Boolean)


44
45
46
# File 'lib/portmone/responses/order_status.rb', line 44

def paid?
  transactions.any?(&:paid?)
end

#reversed?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/portmone/responses/order_status.rb', line 48

def reversed?
  transactions.any?(&:reversed?)
end

#reversed_amountObject



33
34
35
36
37
# File 'lib/portmone/responses/order_status.rb', line 33

def reversed_amount
  transactions.select(&:reversed?)
              .map { |t| t.bill_amount }
              .inject(:+) || 0
end

#success?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/portmone/responses/order_status.rb', line 52

def success?
  order.present? && error_code == '0'
end

#transactionsObject



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/portmone/responses/order_status.rb', line 56

def transactions
  @transactions ||= begin
    if data
      data.map do |h|
        Portmone::Transaction.new(h.merge(timezone: @timezone, currency: @currency))
      end
    else
      []
    end
  end
end