Class: SuntechRails::Payment::BuySafe
- Inherits:
-
Object
- Object
- SuntechRails::Payment::BuySafe
- Defined in:
- lib/suntech_rails/payment/buysafe.rb
Constant Summary collapse
- DEFAULT_MODE =
:sandbox
- MODES =
[ :live, :sandbox ]
Instance Attribute Summary collapse
-
#Card_Type ⇒ Object
Returns the value of attribute Card_Type.
-
#ChkValue ⇒ Object
Returns the value of attribute ChkValue.
-
#Country_Type ⇒ Object
Returns the value of attribute Country_Type.
-
#email ⇒ Object
Returns the value of attribute email.
-
#MN ⇒ Object
Returns the value of attribute MN.
-
#note1 ⇒ Object
Returns the value of attribute note1.
-
#note2 ⇒ Object
Returns the value of attribute note2.
-
#OrderInfo ⇒ Object
Returns the value of attribute OrderInfo.
-
#sdt ⇒ Object
Returns the value of attribute sdt.
-
#sna ⇒ Object
Returns the value of attribute sna.
-
#Td ⇒ Object
Returns the value of attribute Td.
-
#web ⇒ Object
Returns the value of attribute web.
Class Method Summary collapse
Instance Method Summary collapse
- #generate_chkvalue ⇒ Object
-
#initialize(options = {}) ⇒ BuySafe
constructor
A new instance of BuySafe.
- #merge!(options, &block) ⇒ Object
-
#set(key, value) ⇒ Object
Set value for given member === Arguments *
key
– member name *value
– value for member.
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( = {}) @web = SuntechRails::Core::Config.config.buy_safe_id merge!() @ChkValue = generate_chkvalue end |
Instance Attribute Details
#Card_Type ⇒ Object
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 |
#ChkValue ⇒ Object
Returns the value of attribute ChkValue.
4 5 6 |
# File 'lib/suntech_rails/payment/buysafe.rb', line 4 def ChkValue @ChkValue end |
#Country_Type ⇒ Object
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 |
#email ⇒ Object
Returns the value of attribute email.
4 5 6 |
# File 'lib/suntech_rails/payment/buysafe.rb', line 4 def email @email end |
#MN ⇒ Object
Returns the value of attribute MN.
4 5 6 |
# File 'lib/suntech_rails/payment/buysafe.rb', line 4 def MN @MN end |
#note1 ⇒ Object
Returns the value of attribute note1.
4 5 6 |
# File 'lib/suntech_rails/payment/buysafe.rb', line 4 def note1 @note1 end |
#note2 ⇒ Object
Returns the value of attribute note2.
4 5 6 |
# File 'lib/suntech_rails/payment/buysafe.rb', line 4 def note2 @note2 end |
#OrderInfo ⇒ Object
Returns the value of attribute OrderInfo.
4 5 6 |
# File 'lib/suntech_rails/payment/buysafe.rb', line 4 def OrderInfo @OrderInfo end |
#sdt ⇒ Object
Returns the value of attribute sdt.
4 5 6 |
# File 'lib/suntech_rails/payment/buysafe.rb', line 4 def sdt @sdt end |
#sna ⇒ Object
Returns the value of attribute sna.
4 5 6 |
# File 'lib/suntech_rails/payment/buysafe.rb', line 4 def sna @sna end |
#Td ⇒ Object
Returns the value of attribute Td.
4 5 6 |
# File 'lib/suntech_rails/payment/buysafe.rb', line 4 def Td @Td end |
#web ⇒ Object
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
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
48 49 50 |
# File 'lib/suntech_rails/payment/buysafe.rb', line 48 def self.success?(params) params["errcode"] == "00" end |
Instance Method Details
#generate_chkvalue ⇒ Object
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!(, &block) if .is_a? Hash .each do |key, value| set(key, value) end else raise ArgumentError, "invalid data(#{.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. rescue TypeError, ArgumentError => error raise TypeError, "#{error.}(#{value.inspect}) for #{self.class.name}.#{key} member" end |