class UnionPay::Mobile::Client
Attributes
config[R]
Public Class Methods
new(config_or_file)
click to toggle source
trade_url, query_url, merchant_id, back_end_url, front_end_url, secret_key
# File lib/union-pay/mobile/client.rb, line 11 def initialize(config_or_file) if config_or_file.is_a?(String) @config = ::UnionPay::Core::Config.mobile_config(config_or_file) else @config = config_or_file end end
Public Instance Methods
async_notice(params)
click to toggle source
# File lib/union-pay/mobile/client.rb, line 42 def async_notice(params) net_log(nil, params, true) ::UnionPay::Core::Response.new(params, @config) end
consume(other_params)
click to toggle source
默认为人民币 金额填原始值就行, 比如100元,传100过来就行
# File lib/union-pay/mobile/client.rb, line 21 def consume(other_params) UnionPay::Core::Utils.check_hash_keys!(other_params, [:orderTime, :orderNumber, :orderAmount]) params = default_params params = params.merge(other_params) params = params.merge({ transType: '01', orderTime: conver_time(other_params[:orderTime]), orderAmount: conver_amount(other_params[:orderAmount]) }) trade(params) end
query(other_params)
click to toggle source
# File lib/union-pay/mobile/client.rb, line 47 def query(other_params) UnionPay::Core::Utils.check_hash_keys!(other_params, [:transType, :orderTime, :orderNumber]) params = default_params params = params.merge(other_params) params[:orderTime] = conver_time(other_params[:orderTime]) call_api(@config.query_url, params) end
refund(other_params)
click to toggle source
# File lib/union-pay/mobile/client.rb, line 38 def refund(other_params) undo_and_refund(other_params.merge({transType: '04'})) end
undo(other_params)
click to toggle source
# File lib/union-pay/mobile/client.rb, line 34 def undo(other_params) undo_and_refund(other_params.merge({transType: '31'})) end
Protected Instance Methods
call_api(path, params)
click to toggle source
# File lib/union-pay/mobile/client.rb, line 70 def call_api(path, params) encode_reserved!(params) ::UnionPay::Core::Signer.sign!(params, @config.secret_key) ::UnionPay::Core::HttpClient.post(path, params, @config) end
default_params()
click to toggle source
# File lib/union-pay/mobile/client.rb, line 56 def default_params @_default_params ||= { version: '1.0.0', charset: 'UTF-8', merId: @config.merchant_id, backEndUrl: @config.back_end_url, frontEndUrl: @config.front_end_url, } end
trade(params)
click to toggle source
# File lib/union-pay/mobile/client.rb, line 66 def trade(params) call_api(@config.trade_url, params) end
Private Instance Methods
conver_amount(amount)
click to toggle source
# File lib/union-pay/mobile/client.rb, line 88 def conver_amount(amount) (amount * 100).ceil end
conver_time(dt)
click to toggle source
# File lib/union-pay/mobile/client.rb, line 92 def conver_time(dt) if dt.respond_to?(:strftime) dt.strftime('%Y%m%d%H%M%S') else dt end end
encode_reserved!(params)
click to toggle source
# File lib/union-pay/mobile/client.rb, line 100 def encode_reserved!(params) params.each do |k, v| params[k] = UnionPay::Core::Utils.encode_reserved(v) if k.to_s =~ /Reserved$/ end end
undo_and_refund(other_params)
click to toggle source
# File lib/union-pay/mobile/client.rb, line 77 def undo_and_refund(other_params) UnionPay::Core::Utils.check_hash_keys!(other_params, [:orderTime, :orderNumber, :qn, :orderAmount]) params = default_params params = params.merge(other_params) params = params.merge({ orderTime: conver_time(other_params[:orderTime]), orderAmount: conver_amount(other_params[:orderAmount]) }) trade(params) end