Class: AlphaCard::Sale

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

Overview

Implementation of Alpha Card Services Sale object. Contains all the information about Customer Credit Card, such as CVV, number, expiration date, etc. Process the Alpha Card Services payment.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from AlphaCardObject

#filled_attributes

Instance Attribute Details

#typeObject (readonly)

Not writable attribute, defines the type of transaction (default is ‘sale’)



17
# File 'lib/alpha_card/objects/sale.rb', line 17

attribute :type, String, default: 'sale', writer: :private

Instance Method Details

#create(order, account) ⇒ Boolean

Creates the sale for the specified AlphaCard::Order with the AlphaCard::Account credentials.

Examples:

 = AlphaCard::Account.new('demo', 'password')
order = AlphaCard::Order.new({orderid: 1, orderdescription: 'Test order'})
sale = AlphaCard::Sale.new({ccexp: '0117', ccnumber: '4111111111111111', amount: "5.00" })
sale.create(order, )

#=> true

Parameters:

Returns:

  • (Boolean)

    True if sale was created successfully. Raise an AlphaCardError exception if some error occurred.

Raises:

  • (Exception)

    Exception if one of required attributes doesn’t specified.



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/alpha_card/objects/sale.rb', line 42

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

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

  AlphaCard.request(params, ).success?
end