Class: SpreedlyCore::Gateway

Inherits:
Base
  • Object
show all
Defined in:
lib/spreedly-core-ruby/gateway.rb

Direct Known Subclasses

TestGateway

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

configure, environment_key, gateway_token, gateway_token=, verify_get, verify_options, verify_post, verify_put, verify_request

Constructor Details

#initialize(attrs = {}) ⇒ Gateway

Returns a new instance of Gateway.



46
47
48
49
# File 'lib/spreedly-core-ruby/gateway.rb', line 46

def initialize(attrs={})
  attrs.merge!(attrs.delete("characteristics") || {})
  super(attrs)
end

Instance Attribute Details

#auth_modesObject (readonly)

Returns the value of attribute auth_modes.



3
4
5
# File 'lib/spreedly-core-ruby/gateway.rb', line 3

def auth_modes
  @auth_modes
end

#gateway_typeObject (readonly)

Returns the value of attribute gateway_type.



3
4
5
# File 'lib/spreedly-core-ruby/gateway.rb', line 3

def gateway_type
  @gateway_type
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/spreedly-core-ruby/gateway.rb', line 3

def name
  @name
end

#redactedObject (readonly)

Returns the value of attribute redacted.



3
4
5
# File 'lib/spreedly-core-ruby/gateway.rb', line 3

def redacted
  @redacted
end

#supports_authorizeObject (readonly)

Returns the value of attribute supports_authorize.



3
4
5
# File 'lib/spreedly-core-ruby/gateway.rb', line 3

def supports_authorize
  @supports_authorize
end

#supports_captureObject (readonly)

Returns the value of attribute supports_capture.



3
4
5
# File 'lib/spreedly-core-ruby/gateway.rb', line 3

def supports_capture
  @supports_capture
end

#supports_creditObject (readonly)

Returns the value of attribute supports_credit.



3
4
5
# File 'lib/spreedly-core-ruby/gateway.rb', line 3

def supports_credit
  @supports_credit
end

#supports_purchaseObject (readonly)

Returns the value of attribute supports_purchase.



3
4
5
# File 'lib/spreedly-core-ruby/gateway.rb', line 3

def supports_purchase
  @supports_purchase
end

#supports_voidObject (readonly)

Returns the value of attribute supports_void.



3
4
5
# File 'lib/spreedly-core-ruby/gateway.rb', line 3

def supports_void
  @supports_void
end

#tokenObject (readonly)

Returns the value of attribute token.



3
4
5
# File 'lib/spreedly-core-ruby/gateway.rb', line 3

def token
  @token
end

Class Method Details

.allObject

returns an array of all the Gateways owned by the account



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/spreedly-core-ruby/gateway.rb', line 15

def self.all
  verify_get("/gateways.xml") do |response|
    # will return Hash if only 1 gateways->gateway, Array otherwise
    gateways =  begin
                  response.parsed_response["gateways"]["gateway"]
                rescue
                  nil
                end
    if gateways
      gateways = [gateways] unless gateways.is_a?(Array)
      
      return gateways.collect{|gateway_hash| new gateway_hash}
    end
  end

  return []
end

.create(gateway_options) ⇒ Object

Raises:

  • (ArgumentError)


33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/spreedly-core-ruby/gateway.rb', line 33

def self.create(gateway_options)
  raise ArgumentError.new("gateway_options must be a hash") unless gateway_options.is_a?(Hash)
  
  opts = {
    :headers => {"Content-Type" => "application/xml"},
    :body => gateway_options.to_xml(:root => :gateway, :dasherize => false),
  }

  verify_post("/gateways.xml", opts) do |response|
    return new response.parsed_response["gateway"]
  end
end

.supported_gatewaysObject

returns an array of Gateway which are supported



8
9
10
11
12
# File 'lib/spreedly-core-ruby/gateway.rb', line 8

def self.supported_gateways
  verify_options("/gateways.xml") do |response|
    response.parsed_response["gateways"]["gateway"].map{|h| new(h) }
  end
end

Instance Method Details

#==(other) ⇒ Object



55
56
57
# File 'lib/spreedly-core-ruby/gateway.rb', line 55

def ==(other)
  self.token == other.token
end

#use!Object



51
52
53
# File 'lib/spreedly-core-ruby/gateway.rb', line 51

def use!
  self.class.gateway_token = self.token
end