Class: RubyPsigate::Gateway

Inherits:
Object
  • Object
show all
Includes:
TransactionMethods
Defined in:
lib/ruby_psigate/gateway.rb

Constant Summary collapse

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

Constants included from TransactionMethods

TransactionMethods::TRANSACTION_TEST_URL

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TransactionMethods

#amount, #amount=

Constructor Details

#initialize(options = {}) ⇒ Gateway

Returns a new instance of Gateway.



32
33
34
35
# File 'lib/ruby_psigate/gateway.rb', line 32

def initialize(options={})
  @options = options
  set_mode(@options)
end

Instance Attribute Details

#accountObject

include RubyPsigate::AccountManagerMethods



30
31
32
# File 'lib/ruby_psigate/gateway.rb', line 30

def 
  @account
end

#modeObject

include RubyPsigate::AccountManagerMethods



30
31
32
# File 'lib/ruby_psigate/gateway.rb', line 30

def mode
  @mode
end

#optionsObject (readonly)

include RubyPsigate::AccountManagerMethods



30
31
32
# File 'lib/ruby_psigate/gateway.rb', line 30

def options
  @options
end

#orderObject

include RubyPsigate::AccountManagerMethods



30
31
32
# File 'lib/ruby_psigate/gateway.rb', line 30

def order
  @order
end

Class Method Details

.envObject



15
16
17
# File 'lib/ruby_psigate/gateway.rb', line 15

def self.env
  @env
end

.live!Object



19
20
21
# File 'lib/ruby_psigate/gateway.rb', line 19

def self.live!
  @env = :live
end

.test!Object



23
24
25
# File 'lib/ruby_psigate/gateway.rb', line 23

def self.test!
  @env = :test
end

Instance Method Details

#commit!Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/ruby_psigate/gateway.rb', line 62

def commit!
  # 1) Check the mode
  # 2) Ensure credentials are set
  # 3) Check which action user is wanting to take
  # 4) Ensure adequate minimum parameters for the given action
  # 5) Parameterize and ensure it is properly formatted
  # 6) Send!
  
  begin
    raise InvalidGatewayMode unless mode_set?
    raise InvalidCredentials unless 

    if mode == :transaction
      raise InvalidOrder unless order.valid?

      @params = {}
      @params[:Order] = {}
      @params[:Order] = { :StoreID => options[:store_id], :Passphrase => options[:passphrase] }
      @params[:Order].merge!(order.to_hash(order.action))

      @endpoint = "https://dev.psigate.com:7989/Messenger/XMLMessenger"
    end

    if mode == :account_manager
      # raise InvalidAccount unless account.valid?

      # Parameterize based on account manager
      @params = {}
      @params[:Request] = {}
      @params[:Request] = { :CID => options[:cid], :UserID => options[:user_id], :Password => options[:password] }
      @params[:Request].merge!(.to_hash(.action))

      @endpoint = "https://dev.psigate.com:8645/Messenger/AMMessenger"
    end

    # Serializes the parameters to xml      
    @params = Serializer.new(@params, :header => true).to_xml

    @connection = Connection.new(@endpoint)
    @response = @connection.post(@params)
    @response = Response.new(@response)
  rescue ConnectionError => e
    @response = false
  end

  @response
end