Module: Allinpay::Payment

Extended by:
ActiveSupport::Concern
Included in:
Client
Defined in:
lib/allinpay/payment.rb

Overview

通联支付 支付接口

具体文档请查看 113.108.182.3:8282/techsp/helper/interapi/tlt/interapi0.html

Instance Method Summary collapse

Instance Method Details

#batch_pay(trans, options = {}) ⇒ Object

批量代付 交易代码:100002

Parameters:

Options Hash (trans):

  • :bank_code (String)

    银行代码,存折必须填写

  • :account_number (String)

    银行卡或存折号码

  • :account_name (String)

    银行卡或存折上的所有人姓名

  • :account_prop (String)

    账号属性 0私人,1公司。不填时,默认为私人0



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/allinpay/payment.rb', line 50

def batch_pay(trans, options = {})
  params = set_infomation('100002', {LEVEL: 9})
  details = []
  index = 1
  trans_sum = {
    BUSINESS_CODE: options[:business_code] || '09900', 
    MERCHANT_ID: merchant, 
    SUBMIT_TIME: timestamps
  }
  trans_sum[:TOTAL_SUM] = trans.inject(0) do |sum, item|
    sn = index.to_s.rjust(4, '0')
    amount =  (item[:amount].to_f * 100).to_i
    details << {
      SN: item[:number] || sn,
      E_USER_CODE: 1,
      BANK_CODE: item[:bank_code],
      ACCOUNT_TYPE: item[:account_type],
      ACCOUNT_NO:  item[:account_number],
      ACCOUNT_NAME: item[:account_name],
      ACCOUNT_PROP: item[:account_prop],
      AMOUNT: amount
    }
    index += 1
    amount + sum
  end
  trans_sum[:TOTAL_ITEM] = index - 1
  params[:BODY] = { TRANS_SUM: trans_sum, TRANS_DETAILS: details }
  res = conn.request(params)
  res_info = res["INFO"]
  return result_wrap(:fail, res, params) if res_info["RET_CODE"] != "0000"
  return result_wrap(:success, res, params)
end

#pay(tran, options = {}) ⇒ Object

单笔实时付款 交易代码:100014

Parameters:

Options Hash (tran):

  • :bank_code (String)

    银行代码,存折必须填写

  • :account_number (String)

    银行卡或存折号码

  • :account_name (String)

    银行卡或存折上的所有人姓名

  • :account_prop (String)

    账号属性 0私人,1公司。不填时,默认为私人0



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/allinpay/payment.rb', line 20

def pay(tran, options = {})
  params = set_infomation('100014')
  tran_body = {
    BUSINESS_CODE: options[:business_code] || '09900', 
    MERCHANT_ID: merchant, 
    SUBMIT_TIME: timestamps,
    E_USER_CODE: 1,
    BANK_CODE: tran[:bank_code],
    ACCOUNT_TYPE: tran[:account_type],
    ACCOUNT_NO:  tran[:account_number],
    ACCOUNT_NAME: tran[:account_name],
    ACCOUNT_PROP: tran[:account_prop]
  }
  params[:TRANS] = tran_body
  res = conn.request(params)
  return result_wrap(:fail, res, params) if res_info["RET_CODE"] != "0000"
  return result_wrap(:success, res, params)
end