Class: Debitech::WebApi

Inherits:
Object
  • Object
show all
Defined in:
lib/debitech/web_api.rb

Constant Summary collapse

APPROVED_REPLY =
"A"

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ WebApi

Returns a new instance of WebApi.



8
9
10
11
12
# File 'lib/debitech/web_api.rb', line 8

def initialize(opts = {})
  @merchant = opts.fetch(:merchant, nil)
  @secret_key = opts.fetch(:secret_key, nil)
  @custom_fields = opts.fetch(:fields, {})
end

Instance Method Details

#approved_reply?(reply) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/debitech/web_api.rb', line 32

def approved_reply?(reply)
  reply == APPROVED_REPLY
end

#form_actionObject



24
25
26
# File 'lib/debitech/web_api.rb', line 24

def form_action
  "https://securedt.dibspayment.com/verify/bin/#{@merchant}/index"
end

#form_fields(more_custom_fields = {}) ⇒ Object

you probably want to encode these when posting to dibs, for example HTMLEntities.new.encode(v, :named) (gem: htmlentities)



15
16
17
18
19
20
21
22
# File 'lib/debitech/web_api.rb', line 15

def form_fields(more_custom_fields = {})
  # Overriding via the initializer may be more convenient for per-env stuff like "method"".
  # Overriding via the method argument may be more convenient for per-request stuff like multiple pageSets.
  base_fields.
    merge(@custom_fields).
    merge(more_custom_fields).
    merge(:MAC => request_mac)
end

#valid_response?(mac, sum, reply, verify_id) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/debitech/web_api.rb', line 28

def valid_response?(mac, sum, reply, verify_id)
  response_mac(sum, reply, verify_id) == mac.upcase.split("=").last
end