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)


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

def approved_reply?(reply)
  reply == APPROVED_REPLY
end

#form_actionObject



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

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
# 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.
  all_fields_except_mac = custom_fields.merge(more_custom_fields)
  mac = request_mac(all_fields_except_mac)
  all_fields_except_mac.merge(:MAC => mac)
end

#valid_response?(mac, sum, reply, verify_id, currency = custom_fields[:currency]) ⇒ Boolean

Returns:

  • (Boolean)


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

def valid_response?(mac, sum, reply, verify_id, currency = custom_fields[:currency])
  response_mac(sum, reply, verify_id, currency) == mac.upcase.split("=").last
end