Class: Aurfy::Configure

Inherits:
Object
  • Object
show all
Defined in:
lib/aurfy/configure.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfigure

Returns a new instance of Configure.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/aurfy/configure.rb', line 9

def initialize
  @cardtype         = "UP"
  @charset          = "UTF-8"
  @ordertime        = DateTime.now.strftime("%Y%m%d%H%M%S")
  @orderid          = DateTime.now.strftime("%Y%m%d%H%M%S%N")
  @ordercurrency    = "USD"
  @orderdescription = ""
  @signmethod       = "MD5"
  @transtype        = "PURCHASE"
  @txnremark1       = ""
  @txnremark2       = ""
  @version          = "1.0"
  @website          = ""
end

Class Method Details

.keysObject



3
4
5
6
7
# File 'lib/aurfy/configure.rb', line 3

def self.keys
  [:merchantid, :orderid, :ordertime, :ordercurrency, :orderamount, :orderdescription, :txnremark1, :txnremark2,
   :charset, :clientip, :version, :transtype, :website, :cardtype, :cardnumber, :cv2, :expirydate, :signmethod,
   :trade_certificate]
end

Instance Method Details

#options=(options = {}) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/aurfy/configure.rb', line 28

def options=(options = {})
  options.each_pair do |key, value|
    next unless Configure.keys.include? key
    instance_variable_set(:"@#{key}", value)
  end
  options
end

#paramsObject



24
25
26
# File 'lib/aurfy/configure.rb', line 24

def params
  sorted_variables.merge({ signature: signature })
end

#signature_keyObject



42
43
44
# File 'lib/aurfy/configure.rb', line 42

def signature_key
  sorted_variables.delete_if { |k, _| k == :signmethod }.map {|p| "#{p.first}=#{p.last}" }.join("&") + "&#{@trade_certificate}"
end

#sorted_variablesObject



36
37
38
39
40
# File 'lib/aurfy/configure.rb', line 36

def sorted_variables
  instance_variables.map { |v| [v.to_s.sub("@", "").to_sym, instance_variable_get(v)] }.delete_if do
    |k, _| k == :trade_certificate
  end.sort.to_h
end