Class: Allpay::Client
- Inherits:
-
Object
- Object
- Allpay::Client
- Defined in:
- lib/allpay.rb
Instance Attribute Summary collapse
-
#all_iv ⇒ Object
Returns the value of attribute all_iv.
-
#all_key ⇒ Object
Returns the value of attribute all_key.
-
#api ⇒ Object
Returns the value of attribute api.
-
#http ⇒ Object
Returns the value of attribute http.
-
#iv ⇒ Object
Returns the value of attribute iv.
-
#key ⇒ Object
Returns the value of attribute key.
-
#merchant_id ⇒ Object
Returns the value of attribute merchant_id.
-
#rest ⇒ Object
Returns the value of attribute rest.
Class Method Summary collapse
- .decrypt_data(key, iv, data) ⇒ Object
- .encrypt_data(key, iv, data) ⇒ Object
- .parse_xml(data) ⇒ Object
Instance Method Summary collapse
- #get_vaccount(options = {}) ⇒ Object
- #get_vaccount_callback(xmldata) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/allpay.rb', line 15 def initialize( = {}) if [:merchant_id].to_i == 2000132 @merchant_id = 2000132 @key = "ejCk326UnaZWKisg" @iv = "q9jcZX8Ib9LM8wYk" @api = 'pay-stage.allpay.com.tw' else @merchant_id = [:merchant_id] @key = [:key] @iv = [:iv] @api = 'pay.allpay.com.tw' end end |
Instance Attribute Details
#all_iv ⇒ Object
Returns the value of attribute all_iv.
13 14 15 |
# File 'lib/allpay.rb', line 13 def all_iv @all_iv end |
#all_key ⇒ Object
Returns the value of attribute all_key.
13 14 15 |
# File 'lib/allpay.rb', line 13 def all_key @all_key end |
#api ⇒ Object
Returns the value of attribute api.
13 14 15 |
# File 'lib/allpay.rb', line 13 def api @api end |
#http ⇒ Object
Returns the value of attribute http.
13 14 15 |
# File 'lib/allpay.rb', line 13 def http @http end |
#iv ⇒ Object
Returns the value of attribute iv.
13 14 15 |
# File 'lib/allpay.rb', line 13 def iv @iv end |
#key ⇒ Object
Returns the value of attribute key.
13 14 15 |
# File 'lib/allpay.rb', line 13 def key @key end |
#merchant_id ⇒ Object
Returns the value of attribute merchant_id.
13 14 15 |
# File 'lib/allpay.rb', line 13 def merchant_id @merchant_id end |
#rest ⇒ Object
Returns the value of attribute rest.
13 14 15 |
# File 'lib/allpay.rb', line 13 def rest @rest end |
Class Method Details
.decrypt_data(key, iv, data) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/allpay.rb', line 58 def self.decrypt_data(key, iv, data) cipher = OpenSSL::Cipher::AES128.new(:CBC).decrypt cipher.key = key cipher.iv = iv Client.parse_xml(cipher.update(Base64.decode64(data.gsub(" ","+"))) + cipher.final) end |
.encrypt_data(key, iv, data) ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/allpay.rb', line 65 def self.encrypt_data(key, iv, data) data = Gyoku.xml({"Root" => { "Data" => data}}) cipher = OpenSSL::Cipher::AES128.new(:CBC).encrypt cipher.key = key cipher.iv = iv Base64.encode64(cipher.update(data) + cipher.final).gsub("\n","") end |
.parse_xml(data) ⇒ Object
74 75 76 |
# File 'lib/allpay.rb', line 74 def self.parse_xml(data) Nori.new.parse(data)["Root"]["Data"] end |
Instance Method Details
#get_vaccount(options = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/allpay.rb', line 30 def get_vaccount( = {}) has_key? enc_data = Client.encrypt_data(@key, @iv, { 'MerchantID' => merchant_id, 'MerchantTradeNo' => [:merchant_trade_no] || SecureRandom.hex(10), 'MerchantTradeDate' => [:merchant_trade_date] || Time.now.strftime('%Y/%m/%d %H:%M:%S'), 'TradeAmount' => [:trade_amount] || 0, 'ExpireDate' => [:expire_date] || '7', 'BankName' => [:bank_name] || "CHINATRUST", 'ReplyURL' => [:reply_url] || "", 'Remark' => [:remark] || "", }) # p enc_data begin result = Client.parse_xml(get('/payment/Srv/gateway', {"MerchantID" => merchant_id, "PaymentType" => "vAccount", "XMLData" => enc_data})) rescue => e response = e end [result["RtnCode"].to_i, result] end |
#get_vaccount_callback(xmldata) ⇒ Object
52 53 54 55 56 |
# File 'lib/allpay.rb', line 52 def get_vaccount_callback(xmldata) has_key? result = Client.decrypt_data(@key, @iv, xmldata) [result["RtnCode"].to_i, result] end |