Class: AlphaCard::Resource

Inherits:
Object
  • Object
show all
Includes:
Attribute
Defined in:
lib/alpha_card/resource.rb

Overview

Alpha Card resource base class.

Direct Known Subclasses

Billing, Order, Shipping, Transaction

Constant Summary collapse

ORIGIN_TRANSACTION_VARIABLES =

Original AlphaCard transaction variables names

{}.freeze

Instance Method Summary collapse

Methods included from Attribute

included

Instance Method Details

#attributes_for_request(attrs = filled_attributes) ⇒ Object

Returns only filled attributes with the original Alpha Card Services transaction variables names.

Examples:

order = AlphaCard::Order.new(id: '1', tax: nil, po_number: 'PO123')
order.attributes_for_request

#=> { orderid: '1', ponumber: 'PO123' }

Parameters:

  • attrs (Hash) (defaults to: filled_attributes)

    Attributes that must be converted to AlphaCard request params/ Default value is filled_attributes.



26
27
28
29
30
31
32
# File 'lib/alpha_card/resource.rb', line 26

def attributes_for_request(attrs = filled_attributes)
  return attrs if self.class::ORIGIN_TRANSACTION_VARIABLES.empty?

  attrs.each_with_object({}) do |(attr, value), request_attrs|
    request_attrs[self.class::ORIGIN_TRANSACTION_VARIABLES.fetch(attr, attr)] = value
  end
end