Class: Allpay::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  @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 = options[:key]
  @iv = options[:iv]
end

Instance Attribute Details

#all_ivObject

Returns the value of attribute all_iv.



13
14
15
# File 'lib/allpay.rb', line 13

def all_iv
  @all_iv
end

#all_keyObject

Returns the value of attribute all_key.



13
14
15
# File 'lib/allpay.rb', line 13

def all_key
  @all_key
end

#apiObject

Returns the value of attribute api.



13
14
15
# File 'lib/allpay.rb', line 13

def api
  @api
end

#httpObject

Returns the value of attribute http.



13
14
15
# File 'lib/allpay.rb', line 13

def http
  @http
end

#ivObject

Returns the value of attribute iv.



13
14
15
# File 'lib/allpay.rb', line 13

def iv
  @iv
end

#keyObject

Returns the value of attribute key.



13
14
15
# File 'lib/allpay.rb', line 13

def key
  @key
end

#merchant_idObject

Returns the value of attribute merchant_id.



13
14
15
# File 'lib/allpay.rb', line 13

def merchant_id
  @merchant_id
end

#restObject

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(options = {})
  has_key?
  enc_data = encrypt_data(@key, @iv, {
    'MerchantID' => merchant_id,
    'MerchantTradeNo' => options[:merchant_trade_no] ||  SecureRandom.hex(10),
    'MerchantTradeDate' => options[:merchant_trade_date] || Time.now.strftime('%Y/%m/%d %H:%M:%S'),
    'TradeAmount' => options[:trade_amount] || 10000,
    'ExpireDate' => options[:expire_date] || '7',
    'BankName' => options[:bank_name] || "CHINATRUST",
    'ReplyURL' => options[:reply_url] || "",
    'Remark' => options[: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