Class: RubyPsigate::Order

Inherits:
Object
  • Object
show all
Includes:
CreditCardMethods, HashVariables
Defined in:
lib/ruby_psigate/order.rb

Constant Summary collapse

CARD_ACTION =
{
  :sale           => 0,
  :preauth        => 1,
  :postauth       => 2,
  :credit         => 3,
  :force_postauth => 4,
  :void           => 9
}

Instance Attribute Summary collapse

Attributes included from CreditCardMethods

#cc

Instance Method Summary collapse

Methods included from HashVariables

included

Constructor Details

#initializeOrder

Returns a new instance of Order.



27
28
29
# File 'lib/ruby_psigate/order.rb', line 27

def initialize
  @items = []
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



20
21
22
# File 'lib/ruby_psigate/order.rb', line 20

def action
  @action
end

#amountObject Also known as: subtotal

Returns the value of attribute amount.



20
21
22
# File 'lib/ruby_psigate/order.rb', line 20

def amount
  @amount
end

#billingObject

Returns the value of attribute billing.



20
21
22
# File 'lib/ruby_psigate/order.rb', line 20

def billing
  @billing
end

#card_auth_numberObject Also known as: cardauthnumber

Returns the value of attribute card_auth_number.



21
22
23
# File 'lib/ruby_psigate/order.rb', line 21

def card_auth_number
  @card_auth_number
end

#commentObject Also known as: comments

Returns the value of attribute comment.



21
22
23
# File 'lib/ruby_psigate/order.rb', line 21

def comment
  @comment
end

#emailObject

Returns the value of attribute email.



21
22
23
# File 'lib/ruby_psigate/order.rb', line 21

def email
  @email
end

#itemsObject (readonly)

Returns the value of attribute items.



20
21
22
# File 'lib/ruby_psigate/order.rb', line 20

def items
  @items
end

#order_idObject Also known as: orderid

Returns the value of attribute order_id.



21
22
23
# File 'lib/ruby_psigate/order.rb', line 21

def order_id
  @order_id
end

#shippingObject

Returns the value of attribute shipping.



20
21
22
# File 'lib/ruby_psigate/order.rb', line 20

def shipping
  @shipping
end

#tax1Object (readonly)

Returns the value of attribute tax1.



20
21
22
# File 'lib/ruby_psigate/order.rb', line 20

def tax1
  @tax1
end

#tax2Object (readonly)

Returns the value of attribute tax2.



20
21
22
# File 'lib/ruby_psigate/order.rb', line 20

def tax2
  @tax2
end

#tax3Object (readonly)

Returns the value of attribute tax3.



20
21
22
# File 'lib/ruby_psigate/order.rb', line 20

def tax3
  @tax3
end

#tax4Object (readonly)

Returns the value of attribute tax4.



20
21
22
# File 'lib/ruby_psigate/order.rb', line 20

def tax4
  @tax4
end

#tax5Object (readonly)

Returns the value of attribute tax5.



20
21
22
# File 'lib/ruby_psigate/order.rb', line 20

def tax5
  @tax5
end

#trans_ref_numberObject Also known as: transrefnumber

Returns the value of attribute trans_ref_number.



21
22
23
# File 'lib/ruby_psigate/order.rb', line 21

def trans_ref_number
  @trans_ref_number
end

Instance Method Details

#<<(new_item) ⇒ Object

Raises:



50
51
52
53
54
# File 'lib/ruby_psigate/order.rb', line 50

def << (new_item)
  raise InvalidItem unless new_item.is_a?(RubyPsigate::Item)
  @items << new_item
  return self
end

#cardactionObject

Returns the Psigate format equivalent for the action method



72
73
74
# File 'lib/ruby_psigate/order.rb', line 72

def cardaction
  CARD_ACTION[action]
end

#to_hash(type = nil) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ruby_psigate/order.rb', line 31

def to_hash(type = nil)
  result = super
  result = result.merge(billing.to_hash(:billing)) unless billing.nil?  # Add billing address if present
  result = result.merge(shipping.to_hash(:shipping)) unless shipping.nil?  # Add shipping address if present
  
  # Add items if present
  if items.count > 0
    result[:Item] = []
    items.each do |item|
      result[:Item] << item.to_hash
    end
  end
  
  result.merge!(cc.to_hash) if cc
  
  result = result.delete_if { |key, value| value.nil? }  # Delete empty hash values
  result
end

#valid?Boolean

Used internally by the Gateway class to determine if minimal parameters are set to be processed

Returns:

  • (Boolean)


105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/ruby_psigate/order.rb', line 105

def valid?
  errors = 0

  if amount.zero?
    errors += 1 unless action == :postauth || action == :void
  end      
  errors += 1 if action.nil?
  errors += 1 if email.nil?
  errors += 1 if ( action == :postauth && order_id.nil? ) || ( action == :credit && order_id.nil? ) || ( action == :void && order_id.nil? )
  errors += 1 if ( action == :force_postauth && card_auth_number.nil? )
  errors += 1 if ( action == :void && trans_ref_number.nil? )
  errors > 0 ? false : true
end