Class: SagePay::Server::Command

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/sage_pay/server/command.rb

Direct Known Subclasses

Abort, Authorise, Cancel, Refund, Registration, Release, Repeat

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Command

Returns a new instance of Command.



30
31
32
33
34
# File 'lib/sage_pay/server/command.rb', line 30

def initialize(attributes = {})
  attributes.each do |k, v|
    send("#{k}=", v)
  end
end

Instance Attribute Details

#modeObject

Returns the value of attribute mode.



10
11
12
# File 'lib/sage_pay/server/command.rb', line 10

def mode
  @mode
end

#vendorObject

Returns the value of attribute vendor.



10
11
12
# File 'lib/sage_pay/server/command.rb', line 10

def vendor
  @vendor
end

#vendor_tx_codeObject

Returns the value of attribute vendor_tx_code.



10
11
12
# File 'lib/sage_pay/server/command.rb', line 10

def vendor_tx_code
  @vendor_tx_code
end

Class Method Details

.decimal_accessor(*attrs) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/sage_pay/server/command.rb', line 21

def self.decimal_accessor(*attrs)
  attrs.each do |attr|
    attr_reader attr
    define_method("#{attr}=") do |value|
      instance_variable_set("@#{attr}", value.blank? ? nil : BigDecimal.new(value.to_s))
    end
  end
end

Instance Method Details

#live_serviceObject

Raises:

  • (NotImplementedError)


40
41
42
# File 'lib/sage_pay/server/command.rb', line 40

def live_service
  raise NotImplementedError, "Subclass of command implement live_service with tail of the URL used for that command in the test & live systems."
end

#post_paramsObject

Raises:

  • (ArgumentError)


63
64
65
66
67
68
69
70
71
72
# File 'lib/sage_pay/server/command.rb', line 63

def post_params
  raise ArgumentError, "Invalid transaction registration options (see errors hash for details)" unless valid?

  {
    "VPSProtocol"        => vps_protocol,
    "TxType"             => tx_type.to_s.upcase,
    "Vendor"             => vendor,
    "VendorTxCode"       => vendor_tx_code,
  }
end

#response_from_response_body(response_body) ⇒ Object



74
75
76
# File 'lib/sage_pay/server/command.rb', line 74

def response_from_response_body(response_body)
  Response.from_response_body(response_body)
end

#run!Object



36
37
38
# File 'lib/sage_pay/server/command.rb', line 36

def run!
  @response ||= handle_response(post)
end

#simulator_serviceObject

Raises:

  • (NotImplementedError)


44
45
46
# File 'lib/sage_pay/server/command.rb', line 44

def simulator_service
  raise NotImplementedError, "Subclass of command implement simulator_service with tail of the URL used for that command in the simulator."
end

#urlObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/sage_pay/server/command.rb', line 48

def url
  case mode
  when :showpost
    "https://test.sagepay.com/showpost/showpost.asp?Service=#{simulator_service}"
  when :simulator
    "https://test.sagepay.com/simulator/VSPServerGateway.asp?Service=#{simulator_service}"
  when :test
    "https://test.sagepay.com/gateway/service/#{live_service}.vsp"
  when :live
    "https://live.sagepay.com/gateway/service/#{live_service}.vsp"
  else
    raise ArgumentError, "Invalid transaction mode"
  end
end