Module: Payzilla::Transports::HTTP

Instance Method Summary collapse

Instance Method Details

#get(url, params, attributes = {}) ⇒ String

Send data via GET method

Parameters:

  • url (String)

    carrier’s server url

  • params (Hash)

    data, which would be sent

  • attributes (Hash) (defaults to: {})

    additional attributes such as ssl certificate and keys

Returns:

  • (String)

    server response



21
22
23
24
25
# File 'lib/payzilla/transports/http.rb', line 21

def get(url, params, attributes={})
  logger.info "GET #{url}: #{params.inspect}" unless logger.blank?
  logger.debug attributes.inspect unless logger.blank?
  resource(url, attributes).get(:params => params).to_s
end

#post(url, params, attributes = {}, headers = {}) ⇒ String

Send data via POST method

Parameters:

  • url (String)

    carrier’s server url

  • params (Hash)

    data, which would be sent

  • attributes (Hash) (defaults to: {})

    additional attributes such as ssl certificate and keys

Returns:

  • (String)

    server response



33
34
35
36
37
# File 'lib/payzilla/transports/http.rb', line 33

def post(url, params, attributes={}, headers={})
  logger.info "POST #{url}: #{params.inspect}" unless logger.blank?
  logger.debug attributes.inspect unless logger.blank?
  resource(url, attributes).post(params, headers).to_s
end

#resource(url, attributes) ⇒ RestClient::Resource

Generate new RestClient resource

Parameters:

  • url (String)

    carrier’s server url

  • attributes (Hash)

    additional attributes such as ssl certificate and keys

Returns:

  • (RestClient::Resource)

    resource, where you can send payment data with GET or POST methods



11
12
13
# File 'lib/payzilla/transports/http.rb', line 11

def resource(url, attributes)
  RestClient::Resource.new url, attributes
end

#ssl(cert, key, password, ca = false) ⇒ Object

Prepare SSL data to be sent

Parameters:

  • cert (File)

    certificate file, that you should use to access to secure host

  • key (File)

    key file, that you need to use to access to secure host

  • password (String)

    password that used to read encrypted key file

  • ca (File) (defaults to: false)

    certificate authority file, if it is needed



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/payzilla/transports/http.rb', line 45

def ssl(cert, key, password, ca=false)
  ssl = {
    :ssl_client_cert  =>  OpenSSL::X509::Certificate.new(File.read cert.path),
    :verify_ssl       =>  OpenSSL::SSL::VERIFY_NONE
  }

  unless password.blank?
    ssl[:ssl_client_key] = OpenSSL::PKey::RSA.new(File.read(key.path), password)
  else
    ssl[:ssl_client_key] = OpenSSL::PKey::RSA.new(File.read(key.path))
  end
  ssl[:ssl_ca_file] = ca.path unless ca.blank?

  ssl
end