Class: SuntechRails::Payment::BuySafe

Inherits:
Object
  • Object
show all
Defined in:
lib/suntech_rails/payment/buysafe.rb

Constant Summary collapse

DEFAULT_MODE =
:sandbox
MODES =
[ :live, :sandbox ]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ BuySafe

Returns a new instance of BuySafe.



10
11
12
13
14
# File 'lib/suntech_rails/payment/buysafe.rb', line 10

def initialize(options = {})
  @web = SuntechRails::Core::Config.config.buy_safe_id
  merge!(options)
  @ChkValue = generate_chkvalue
end

Instance Attribute Details

#Card_TypeObject

Returns the value of attribute Card_Type.



4
5
6
# File 'lib/suntech_rails/payment/buysafe.rb', line 4

def Card_Type
  @Card_Type
end

#ChkValueObject

Returns the value of attribute ChkValue.



4
5
6
# File 'lib/suntech_rails/payment/buysafe.rb', line 4

def ChkValue
  @ChkValue
end

#Country_TypeObject

Returns the value of attribute Country_Type.



4
5
6
# File 'lib/suntech_rails/payment/buysafe.rb', line 4

def Country_Type
  @Country_Type
end

#emailObject

Returns the value of attribute email.



4
5
6
# File 'lib/suntech_rails/payment/buysafe.rb', line 4

def email
  @email
end

#MNObject

Returns the value of attribute MN.



4
5
6
# File 'lib/suntech_rails/payment/buysafe.rb', line 4

def MN
  @MN
end

#note1Object

Returns the value of attribute note1.



4
5
6
# File 'lib/suntech_rails/payment/buysafe.rb', line 4

def note1
  @note1
end

#note2Object

Returns the value of attribute note2.



4
5
6
# File 'lib/suntech_rails/payment/buysafe.rb', line 4

def note2
  @note2
end

#OrderInfoObject

Returns the value of attribute OrderInfo.



4
5
6
# File 'lib/suntech_rails/payment/buysafe.rb', line 4

def OrderInfo
  @OrderInfo
end

#sdtObject

Returns the value of attribute sdt.



4
5
6
# File 'lib/suntech_rails/payment/buysafe.rb', line 4

def sdt
  @sdt
end

#snaObject

Returns the value of attribute sna.



4
5
6
# File 'lib/suntech_rails/payment/buysafe.rb', line 4

def sna
  @sna
end

#TdObject

Returns the value of attribute Td.



4
5
6
# File 'lib/suntech_rails/payment/buysafe.rb', line 4

def Td
  @Td
end

#webObject

Returns the value of attribute web.



4
5
6
# File 'lib/suntech_rails/payment/buysafe.rb', line 4

def web
  @web
end

Class Method Details

.check(params) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/suntech_rails/payment/buysafe.rb', line 52

def self.check(params)
 
  if SuntechRails::Core::Config.config.buy_safe_id == params["web"] && check_chkvalue?(params)
    return params
  else
    return nil
  end
end

.check_chkvalue?(params) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/suntech_rails/payment/buysafe.rb', line 20

def self.check_chkvalue?(params)
  Digest::SHA1.hexdigest("#{params["web"]}#{SuntechRails::Core::Config.config.transaction_code}#{params["buysafeno"]}#{params["MN"]}#{params["errcode"]}").upcase == params["ChkValue"]
end

.success?(params) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/suntech_rails/payment/buysafe.rb', line 48

def self.success?(params)
  params["errcode"] == "00"
end

Instance Method Details

#generate_chkvalueObject



16
17
18
# File 'lib/suntech_rails/payment/buysafe.rb', line 16

def generate_chkvalue
  Digest::SHA1.hexdigest("#{@web}#{SuntechRails::Core::Config.config.transaction_code}#{@MN}").upcase
end

#merge!(options, &block) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/suntech_rails/payment/buysafe.rb', line 24

def merge!(options, &block)
  if options.is_a? Hash
    options.each do |key, value|
      set(key, value)
    end
  else
    raise ArgumentError, "invalid data(#{options.inspect}) for #{self.class.name} class"
  end
  self.instance_eval(&block) if block
  self
end

#set(key, value) ⇒ Object

Set value for given member

Arguments

  • key – member name

  • value – value for member



40
41
42
43
44
45
46
# File 'lib/suntech_rails/payment/buysafe.rb', line 40

def set(key, value)
  send("#{key}=", value)
rescue NoMethodError => error
  SuntechRails.logger.warn error.message
rescue TypeError, ArgumentError => error
  raise TypeError, "#{error.message}(#{value.inspect}) for #{self.class.name}.#{key} member"
end