class GpWebpay::PaymentAttributes

Constants

KEYS
MASTER_KEYS
OPTIONAL_KEYS
REGULAR_PAYMENT_KEYS
TRANSITIONS
WS_KEYS

Public Class Methods

map_to_keys(hash) click to toggle source
# File lib/gp_webpay/payment_attributes.rb, line 74
def self.map_to_keys(hash)
  hash.each_with_object({}) do |(method, value), transformed|
    transformed[TRANSITIONS[method]] = value
  end
end
new(payment, ws_flag = false, type = "") click to toggle source
# File lib/gp_webpay/payment_attributes.rb, line 35
def initialize(payment, ws_flag = false, type = "")
  @payment = payment
  @ws_flag = ws_flag
  @type = type
end

Public Instance Methods

keys() click to toggle source
# File lib/gp_webpay/payment_attributes.rb, line 41
def keys
  case @payment.payment_type
  when "master"
    return (@ws_flag ? WS_KEYS : KEYS)
  when "recurring"
    case @type
    when "processRegularSubscriptionPayment"
      return REGULAR_PAYMENT_KEYS
    else
      return WS_KEYS
    end
  else
    return KEYS.reject { |k| MASTER_KEYS.include?(k) }
  end
end
to_h() click to toggle source
# File lib/gp_webpay/payment_attributes.rb, line 57
def to_h
  keys.each_with_object({}) do |method, hash|
    method_chain = method.to_s.split(".").map(&:to_sym)
    if @payment.respond_to?(*method_chain)
      if method == :message_id
        hash[method] = @payment.public_send(method, @type)
      else
        hash[method] = method_chain.inject(@payment, :public_send)
      end
    elsif !OPTIONAL_KEYS.include?(method)
      method_missing(method)
    end

    hash
  end
end