Class: Datacash::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/datacash/client.rb

Constant Summary collapse

ENDPOINTS =
{
  live: "https://mars.transaction.datacash.com/Transaction",
  test: "https://accreditation.datacash.com/Transaction/cnp_a"
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
14
# File 'lib/datacash/client.rb', line 9

def initialize(options={})
  @client      = options.fetch(:client, Datacash.configuration.client)
  @password    = options.fetch(:password, Datacash.configuration.password)
  @environment    = options.fetch(:environment, Datacash.configuration.environment)
  @rest_client = options.fetch(:rest_client, RestClient)
end

Instance Method Details

#post(request) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/datacash/client.rb', line 16

def post(request)
  prepare_request(request)

  handle_response do 
    rest_client.post(
      endpoint,
      request.to_xml, 
      content_type: :xml, 
      accept: :xml
    )
  end
end

#query(datacash_reference) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/datacash/client.rb', line 29

def query(datacash_reference)
  request = Request::Request.new(transaction: {
    historic_transaction: { 
      method: "query", reference: datacash_reference
    }
  })
  post(request)
end