Class: RubyPsigate::Order
- Inherits:
-
Object
- Object
- RubyPsigate::Order
- 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
-
#action ⇒ Object
Returns the value of attribute action.
-
#amount ⇒ Object
(also: #subtotal)
Returns the value of attribute amount.
-
#billing ⇒ Object
Returns the value of attribute billing.
-
#card_auth_number ⇒ Object
(also: #cardauthnumber)
Returns the value of attribute card_auth_number.
-
#comment ⇒ Object
(also: #comments)
Returns the value of attribute comment.
-
#email ⇒ Object
Returns the value of attribute email.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#order_id ⇒ Object
(also: #orderid)
Returns the value of attribute order_id.
-
#shipping ⇒ Object
Returns the value of attribute shipping.
-
#tax1 ⇒ Object
readonly
Returns the value of attribute tax1.
-
#tax2 ⇒ Object
readonly
Returns the value of attribute tax2.
-
#tax3 ⇒ Object
readonly
Returns the value of attribute tax3.
-
#tax4 ⇒ Object
readonly
Returns the value of attribute tax4.
-
#tax5 ⇒ Object
readonly
Returns the value of attribute tax5.
-
#trans_ref_number ⇒ Object
(also: #transrefnumber)
Returns the value of attribute trans_ref_number.
Attributes included from CreditCardMethods
Instance Method Summary collapse
- #<<(new_item) ⇒ Object
-
#cardaction ⇒ Object
Returns the Psigate format equivalent for the action method.
-
#initialize ⇒ Order
constructor
A new instance of Order.
- #to_hash(type = nil) ⇒ Object
-
#valid? ⇒ Boolean
Used internally by the Gateway class to determine if minimal parameters are set to be processed.
Methods included from HashVariables
Constructor Details
#initialize ⇒ Order
Returns a new instance of Order.
27 28 29 |
# File 'lib/ruby_psigate/order.rb', line 27 def initialize @items = [] end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
20 21 22 |
# File 'lib/ruby_psigate/order.rb', line 20 def action @action end |
#amount ⇒ Object 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 |
#billing ⇒ Object
Returns the value of attribute billing.
20 21 22 |
# File 'lib/ruby_psigate/order.rb', line 20 def billing @billing end |
#card_auth_number ⇒ Object 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 |
#comment ⇒ Object 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 |
#email ⇒ Object
Returns the value of attribute email.
21 22 23 |
# File 'lib/ruby_psigate/order.rb', line 21 def email @email end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
20 21 22 |
# File 'lib/ruby_psigate/order.rb', line 20 def items @items end |
#order_id ⇒ Object 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 |
#shipping ⇒ Object
Returns the value of attribute shipping.
20 21 22 |
# File 'lib/ruby_psigate/order.rb', line 20 def shipping @shipping end |
#tax1 ⇒ Object (readonly)
Returns the value of attribute tax1.
20 21 22 |
# File 'lib/ruby_psigate/order.rb', line 20 def tax1 @tax1 end |
#tax2 ⇒ Object (readonly)
Returns the value of attribute tax2.
20 21 22 |
# File 'lib/ruby_psigate/order.rb', line 20 def tax2 @tax2 end |
#tax3 ⇒ Object (readonly)
Returns the value of attribute tax3.
20 21 22 |
# File 'lib/ruby_psigate/order.rb', line 20 def tax3 @tax3 end |
#tax4 ⇒ Object (readonly)
Returns the value of attribute tax4.
20 21 22 |
# File 'lib/ruby_psigate/order.rb', line 20 def tax4 @tax4 end |
#tax5 ⇒ Object (readonly)
Returns the value of attribute tax5.
20 21 22 |
# File 'lib/ruby_psigate/order.rb', line 20 def tax5 @tax5 end |
#trans_ref_number ⇒ Object 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
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 |
#cardaction ⇒ Object
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
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 |