2 @@proxy_command = "(cd #{RAILS_ROOT}/script/veritrans; perl proxy.pl)"
3 cattr_accessor :proxy_command
4 @@service_type = 'bsx1'
5 cattr_accessor :service_type
8 def initialize(proxy_command=@@proxy_command)
9 @proxy_command = proxy_command || "(cd #{RAILS_ROOT}/script/veritrans; perl proxy.pl)"
13 def request(command, params)
16 'params' => params.stringify_keys
19 IO.popen(@proxy_command, "r+") {|io|
22 chunk = io.read # 向こうで close しないと無限に待つ
24 Response.new(YAML.load(chunk))
29 auth('authonly', params)
34 auth('mauthonly', params)
38 def authcapture(params)
39 auth('authcapture', params)
43 def mauthcapture(params)
44 auth('mauthcapture', params)
49 p = build_params(params, [:order_id, :amount])
50 request('postauth', p)
55 p = build_params(params, [:order_id, :txn_type])
56 request('payrequest', p)
61 p = build_params(params, [:order_id, :txn_type])
62 request('payrequest', p)
66 def payrequest(params)
67 p = build_params(params, [:order_id, :amount, :note])
68 request('payrequest', p)
73 p = build_params(params, [:order_id])
79 p = build_params(params, [])
84 def query_orders(params)
85 p = build_params(params, [:start_time, :end_time])
86 request('query-orders', p)
91 n == 1 and return '10'
97 def auth(command, params)
98 p = build_params(params, [:order_id, :amount, :card_number, :card_exp])
102 def build_params(params, required)
103 params = params.inject({}) do |hash, pair|
104 k = pair[0].to_s.gsub(/_/, '-')
109 params['service-type'] ||= @@service_type
111 missing = required.select do |name|
112 name = name.to_s.gsub(/_/, '-')
115 unless missing.empty?
116 raise ArgumentError, "parameter(s) required: %s" % missing.join(", ")
127 @h['MStatus'] == 'success'
131 message = @h['aux-msg']
132 if message.blank? || !success?
133 message = @h['MErrMsg']
135 message && message.toutf8
139 n = @h['card-number'].to_s
141 n[0..1] + '*' * 10 + n[2..5]
146 key = translate_key(key)
151 s = @h['paid-amount']
152 s && s.split(/ /)[1].to_i
156 key = translate_key(key)
160 def method_missing(name, *args)
166 def translate_key(key)
168 key = key.to_s.gsub('_', '-')