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.
Instance Method Summary collapse
- #get_vaccount(options = {}) ⇒ Object
- #get_vaccount_callback(xmldata) ⇒ Object
-
#initialize(merchant_id, options = {}) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(merchant_id, options = {}) ⇒ Client
Returns a new instance of Client.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/allpay.rb', line 15 def initialize(merchant_id, = {}) @merchant_id = merchant_id begin env = ENV.try("fetch", "RAILS_ENV") rescue env = "development" end if env == 'production' @api = 'pay.allpay.com.tw' else @api = 'pay-stage.allpay.com.tw' end @key = [:key] @iv = [:iv] 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 |
Instance Method Details
#get_vaccount(options = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/allpay.rb', line 32 def get_vaccount( = {}) has_key? enc_data = 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] || 10000, 'ExpireDate' => [:expire_date] || '7', 'BankName' => [:bank_name] || "CHINATRUST", 'ReplyURL' => [:reply_url] || "", 'Remark' => [:remark] || "", }) begin result = 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
54 55 56 57 58 |
# File 'lib/allpay.rb', line 54 def get_vaccount_callback(xmldata) has_key? result = parse_xml(decrypt_data(@key, @iv, xmldata)) [result["RtnCode"].to_i, result] end |