Class: AlphaCard::Sale

Inherits:
AlphaCardObject show all
Defined in:
lib/alpha_card/sale.rb

Instance Method Summary collapse

Methods inherited from AlphaCardObject

#filled_attributes

Instance Method Details

#create(order, account) ⇒ Object

create(order, account) -> true create(order, account) -> false create(order, account) -> Exception

Creates the sale for the order with specified attributes, such as ccexp, ccnumber, amount and cvv.

attrs = {ccexp: '0117', ccnumber: '123', amount: '10.00'}
sale = AlphaCard::Sale.new(attrs)
sale.create(order, ) #=> true or false


22
23
24
25
26
27
28
29
30
31
# File 'lib/alpha_card/sale.rb', line 22

def create(order, )
  [:ccexp, :ccnumber, :amount].each do |attr|
    raise Exception.new("No #{attr} information provided") if self[attr].blank?
  end

  params = self.filled_attributes || {}
  [order, order.billing, order.shipping].compact.each { |obj| params.merge!(obj.try(:filled_attributes)) }

  AlphaCard.request(params, ).success?
end