Class: CompletePaymentSystems::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/complete_payment_systems/request_processing.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Request

Returns a new instance of Request.



6
7
8
9
# File 'lib/complete_payment_systems/request_processing.rb', line 6

def initialize(params)
  @params = params #|| File.read("#{CPS.root}/response.xml")
  @xml = build_request_xml
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



4
5
6
# File 'lib/complete_payment_systems/request_processing.rb', line 4

def params
  @params
end

#xmlObject (readonly)

Returns the value of attribute xml.



4
5
6
# File 'lib/complete_payment_systems/request_processing.rb', line 4

def xml
  @xml
end

Instance Method Details

#send!Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/complete_payment_systems/request_processing.rb', line 11

def send!
  response = Unirest.post CPS.config.cps_url,
                      #headers:{ "Accept" => "application/json" },
                      parameters:{ type: CPS.config.cps_method, xml: xml }

  puts response.code # Status code
  puts response.headers # Response headers
  puts response.body # Parsed body

  return "OK" if response.body.to_s.match(CPS.config.success_regex).present?
  return "ERROR"
end