class Sberbank::Acquiring::Request

Constants

PRODUCTION_HOST
TEST_HOST

Attributes

host[R]
http[R]
http_request[R]
params[R]
path[R]
response[R]
test[R]
test?[R]

Public Class Methods

new(host: nil, params:, path:, test: false) click to toggle source
# File lib/sberbank/acquiring/request.rb, line 16
def initialize(host: nil, params:, path:, test: false)
  @host        = host || test && TEST_HOST || PRODUCTION_HOST
  @params      = params
  @path        = path
  @test        = test
end

Public Instance Methods

build_uri() click to toggle source
# File lib/sberbank/acquiring/request.rb, line 23
def build_uri
  URI::HTTPS.build(host: host, path: path)
end
perform() click to toggle source
# File lib/sberbank/acquiring/request.rb, line 27
def perform
  uri = build_uri
  Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
    @http_request = Net::HTTP::Post.new(uri)
    @http_request['Content-Type'] = 'application/x-www-form-urlencoded'
    @http_request.body = URI.encode_www_form(params)

    @response = Response.new(http_response: http.request(@http_request), request: self)
  end
end