Class: ActiveMerchant::Billing::EveryPayRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/active_merchant/billing/every_pay_request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gateway_options, scheme, params) ⇒ EveryPayRequest

Returns a new instance of EveryPayRequest.



6
7
8
9
10
# File 'lib/active_merchant/billing/every_pay_request.rb', line 6

def initialize gateway_options, scheme, params
  self.gateway_options = gateway_options
  self.scheme = scheme
  self.params = params
end

Instance Attribute Details

#gateway_optionsObject

Returns the value of attribute gateway_options.



4
5
6
# File 'lib/active_merchant/billing/every_pay_request.rb', line 4

def gateway_options
  @gateway_options
end

#paramsObject

Returns the value of attribute params.



4
5
6
# File 'lib/active_merchant/billing/every_pay_request.rb', line 4

def params
  @params
end

#schemeObject

Returns the value of attribute scheme.



4
5
6
# File 'lib/active_merchant/billing/every_pay_request.rb', line 4

def scheme
  @scheme
end

Instance Method Details

#basic_authObject



37
38
39
# File 'lib/active_merchant/billing/every_pay_request.rb', line 37

def basic_auth
  "Basic " + Base64.strict_encode64("#{gateway_options.fetch(:api_username)}:#{gateway_options.fetch(:api_secret)}")
end

#dataObject



12
13
14
# File 'lib/active_merchant/billing/every_pay_request.rb', line 12

def data
  params.to_json if scheme.post_request?
end

#headersObject



29
30
31
32
33
34
35
# File 'lib/active_merchant/billing/every_pay_request.rb', line 29

def headers
  {
    "Content-Type" => "application/json",
    "Accept" => "application/json",
    "Authorization" => basic_auth
  }
end

#methodObject



25
26
27
# File 'lib/active_merchant/billing/every_pay_request.rb', line 25

def method
  scheme.request_method
end

#urlObject



16
17
18
19
20
21
22
23
# File 'lib/active_merchant/billing/every_pay_request.rb', line 16

def url
  uri = URI(gateway_options.fetch(:gateway_url))
  uri.path += scheme.request_path.gsub(/(:[\w]*)/) {|m| m.gsub(m, params.fetch(m.tr(":", "").to_sym)) }

  uri.query = URI.encode_www_form(params) if scheme.get_request?

  uri.to_s
end