unionpay 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a4c823129d1f1dd841f122f5ea2ee1c013e14468
4
- data.tar.gz: f3a0f27c3fdcff06e5f590e776ffea7c02705d26
3
+ metadata.gz: 2ffcf03e03f0aba5fbcf4b4dfe86a4f43f748179
4
+ data.tar.gz: 72c13fdcbd7d3c9ab1036cca39a11ae6827a42cd
5
5
  SHA512:
6
- metadata.gz: 2023fee365fb05787f8d48c2aaea2016570c73f6acfe86dd53ba523bb8f93d05f29cae983a93b0d51932f3c0ee683645a7db1604fb81189c2a38e6a9b400a236
7
- data.tar.gz: 1919939feccece40af863833464f58d0f7474bc2c485dd1a5c14246c6e736d19632050f0f6e726bdd5e43095b2d16efaa58735669bd5e4dda89858889f741c33
6
+ metadata.gz: cb89c4008a00a986bac420089ea180e7e004a65aff21d1dbb99f5c1c1a61540c35fe25c7616747dd08b559b0cb255f266183c786c8be58fe0c389afc59e6ea22
7
+ data.tar.gz: e94ed90bc86f968ba70660f9f5a89607ed515036fef440537ed9f54cc22fc74fd424964da43db1395bedf0665263ec0ea2de58aab1cef6c8615c8da8c0368f4b
data/README.md CHANGED
@@ -21,7 +21,7 @@ UnionPay.security_key = '88888888'
21
21
  ### Generate payment form
22
22
  ```ruby
23
23
  param = {}
24
- param['transType'] = UnionPay::Conf::CONSUME #交易类型,CONSUME or PRE_AUTH
24
+ param['transType'] = UnionPay::CONSUME #交易类型,CONSUME or PRE_AUTH
25
25
  param['orderAmount'] = 11000 #交易金额
26
26
  param['orderNumber'] = Time.now.strftime('%Y%m%d%H%M%S') #订单号,必须唯一
27
27
  param['customerIp'] = '127.0.0.1'
@@ -37,7 +37,9 @@ param['backEndUrl'] = "http://www.example.com/sdk/utf8/back_notify.php" #
37
37
 
38
38
  # 其余可填空的参数可以不填写
39
39
 
40
- UnionPay::Service.front_pay(param).form(target: '_blank', id: 'form'){"<input type='submit' />"}
40
+ service = UnionPay::Service.front_pay(param)
41
+ service.args ## get args
42
+ service.form(target: '_blank', id: 'form'){"<input type='submit' />"} ## get form
41
43
  ```
42
44
 
43
45
  ### Verify notify
@@ -48,7 +50,7 @@ UnionPay::Service.front_pay(param).form(target: '_blank', id: 'form'){"<input ty
48
50
  def unionpay_notify
49
51
  # except :controller_name, :action_name, :host, etc.
50
52
  notify_params = params.except(*request.path_parameters.keys)
51
- args = UnionPay::Service.responce(notify_params)
53
+ args = UnionPay::Service.responce(notify_params).args
52
54
  if args['respCode'] == UnionPay::RESP_SUCCESS
53
55
  # valid notify, code your business logic.
54
56
  render :text => 'success'
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "test"
6
+ t.test_files = FileList['test/**/*_test.rb']
7
+ end
8
+
9
+ task :default => :test
data/lib/unionpay/conf.rb CHANGED
@@ -1,146 +1,143 @@
1
1
  #encoding:utf-8
2
2
  module UnionPay
3
- class << self
4
- attr_accessor :front_pay_url, :back_pay_url, :query_url
5
- end
6
- VERIFY_HTTPS_CERT = false
3
+ class << self
4
+ attr_accessor :front_pay_url, :back_pay_url, :query_url
5
+ end
6
+ VERIFY_HTTPS_CERT = false
7
7
 
8
- Timezone = "Asia/Shanghai" #时区
9
- Sign_method = "md5" #摘要算法,目前仅支持md5 (2011-08-22)
8
+ Timezone = "Asia/Shanghai" #时区
9
+ Sign_method = "md5" #摘要算法,目前仅支持md5 (2011-08-22)
10
10
 
11
- #Security_key = UnionPay.security_key #商户密钥
11
+ # 支付请求预定义字段
12
+ Pay_params = {
13
+ 'version' => '1.0.0',
14
+ 'charset' => 'UTF-8', #UTF-8, GBK等
15
+ 'merId' => '88888888', #商户填写
16
+ 'acqCode' => '', #收单机构填写
17
+ 'merCode' => '', #收单机构填写
18
+ 'merAbbr' => '商户名称'
19
+ }
12
20
 
13
- # 支付请求预定义字段
14
- Pay_params = {
15
- 'version' => '1.0.0',
16
- 'charset' => 'UTF-8', #UTF-8, GBK等
17
- 'merId' => '88888888', #商户填写
18
- 'acqCode' => '', #收单机构填写
19
- 'merCode' => '', #收单机构填写
20
- 'merAbbr' => '商户名称'
21
- }
21
+ FRONT_PAY = 1
22
+ BACK_PAY = 2
23
+ RESPONSE = 3
24
+ QUERY = 4
22
25
 
26
+ CONSUME = "01"
27
+ CONSUME_VOID = "31"
28
+ PRE_AUTH = "02"
29
+ PRE_AUTH_VOID = "32"
30
+ PRE_AUTH_COMPLETE = "03"
31
+ PRE_AUTH_VOID_COMPLETE = "33"
32
+ REFUND = "04"
33
+ REGISTRATION = "71"
23
34
 
24
- FRONT_PAY = 1
25
- BACK_PAY = 2
26
- RESPONSE = 3
27
- QUERY = 4
35
+ CURRENCY_CNY = "156"
28
36
 
29
- CONSUME = "01"
30
- CONSUME_VOID = "31"
31
- PRE_AUTH = "02"
32
- PRE_AUTH_VOID = "32"
33
- PRE_AUTH_COMPLETE = "03"
34
- PRE_AUTH_VOID_COMPLETE = "33"
35
- REFUND = "04"
36
- REGISTRATION = "71"
37
+ # 支付请求可为空字段(但必须填写)
38
+ Pay_params_empty = {
39
+ "origQid" => "",
40
+ "acqCode" => "",
41
+ "merCode" => "",
42
+ "commodityUrl" => "",
43
+ "commodityName" => "",
44
+ "commodityUnitPrice" => "",
45
+ "commodityQuantity" => "",
46
+ "commodityDiscount" => "",
47
+ "transferFee" => "",
48
+ "customerName" => "",
49
+ "defaultPayType" => "",
50
+ "defaultBankNumber" => "",
51
+ "transTimeout" => "",
52
+ "merReserved" => ""
53
+ }
37
54
 
38
- CURRENCY_CNY = "156"
55
+ # 支付请求必填字段检查
56
+ Pay_params_check = [
57
+ "version",
58
+ "charset",
59
+ "transType",
60
+ "origQid",
61
+ "merId",
62
+ "merAbbr",
63
+ "acqCode",
64
+ "merCode",
65
+ "commodityUrl",
66
+ "commodityName",
67
+ "commodityUnitPrice",
68
+ "commodityQuantity",
69
+ "commodityDiscount",
70
+ "transferFee",
71
+ "orderNumber",
72
+ "orderAmount",
73
+ "orderCurrency",
74
+ "orderTime",
75
+ "customerIp",
76
+ "customerName",
77
+ "defaultPayType",
78
+ "defaultBankNumber",
79
+ "transTimeout",
80
+ "frontEndUrl",
81
+ "backEndUrl",
82
+ "merReserved"
83
+ ]
39
84
 
40
- # 支付请求可为空字段(但必须填写)
41
- Pay_params_empty = {
42
- "origQid" => "",
43
- "acqCode" => "",
44
- "merCode" => "",
45
- "commodityUrl" => "",
46
- "commodityName" => "",
47
- "commodityUnitPrice" => "",
48
- "commodityQuantity" => "",
49
- "commodityDiscount" => "",
50
- "transferFee" => "",
51
- "customerName" => "",
52
- "defaultPayType" => "",
53
- "defaultBankNumber" => "",
54
- "transTimeout" => "",
55
- "merReserved" => ""
56
- }
85
+ # 查询请求必填字段检查
86
+ Query_params_check = [
87
+ "version",
88
+ "charset",
89
+ "transType",
90
+ "merId",
91
+ "orderNumber",
92
+ "orderTime",
93
+ "merReserved",
94
+ ]
57
95
 
58
- # 支付请求必填字段检查
59
- Pay_params_check = [
60
- "version",
61
- "charset",
62
- "transType",
63
- "origQid",
64
- "merId",
65
- "merAbbr",
66
- "acqCode",
67
- "merCode",
68
- "commodityUrl",
69
- "commodityName",
70
- "commodityUnitPrice",
71
- "commodityQuantity",
72
- "commodityDiscount",
73
- "transferFee",
74
- "orderNumber",
75
- "orderAmount",
76
- "orderCurrency",
77
- "orderTime",
78
- "customerIp",
79
- "customerName",
80
- "defaultPayType",
81
- "defaultBankNumber",
82
- "transTimeout",
83
- "frontEndUrl",
84
- "backEndUrl",
85
- "merReserved"
86
- ]
96
+ # 商户保留域可能包含的字段
97
+ Mer_params_reserved = [
98
+ # NEW NAME OLD NAME
99
+ "cardNumber", "pan",
100
+ "cardPasswd", "password",
101
+ "credentialType", "idType",
102
+ "cardCvn2", "cvn",
103
+ "cardExpire", "expire",
104
+ "credentialNumber", "idNo",
105
+ "credentialName", "name",
106
+ "phoneNumber", "mobile",
107
+ "merAbstract",
87
108
 
88
- # 查询请求必填字段检查
89
- $query_params_check = [
90
- "version",
91
- "charset",
92
- "transType",
93
- "merId",
94
- "orderNumber",
95
- "orderTime",
96
- "merReserved",
97
- ]
109
+ # tdb only
110
+ "orderTimeoutDate",
111
+ "origOrderNumber",
112
+ "origOrderTime",
113
+ ]
98
114
 
99
- # 商户保留域可能包含的字段
100
- Mer_params_reserved = [
101
- # NEW NAME OLD NAME
102
- "cardNumber", "pan",
103
- "cardPasswd", "password",
104
- "credentialType", "idType",
105
- "cardCvn2", "cvn",
106
- "cardExpire", "expire",
107
- "credentialNumber", "idNo",
108
- "credentialName", "name",
109
- "phoneNumber", "mobile",
110
- "merAbstract",
115
+ Notify_param_check = [
116
+ "version",
117
+ "charset",
118
+ "transType",
119
+ "respCode",
120
+ "respMsg",
121
+ "respTime",
122
+ "merId",
123
+ "merAbbr",
124
+ "orderNumber",
125
+ "traceNumber",
126
+ "traceTime",
127
+ "qid",
128
+ "orderAmount",
129
+ "orderCurrency",
130
+ "settleAmount",
131
+ "settleCurrency",
132
+ "settleDate",
133
+ "exchangeRate",
134
+ "exchangeDate",
135
+ "cupReserved",
136
+ "signMethod",
137
+ "signature",
138
+ ]
111
139
 
112
- # tdb only
113
- "orderTimeoutDate",
114
- "origOrderNumber",
115
- "origOrderTime",
116
- ]
117
-
118
- Notify_param_check = [
119
- "version",
120
- "charset",
121
- "transType",
122
- "respCode",
123
- "respMsg",
124
- "respTime",
125
- "merId",
126
- "merAbbr",
127
- "orderNumber",
128
- "traceNumber",
129
- "traceTime",
130
- "qid",
131
- "orderAmount",
132
- "orderCurrency",
133
- "settleAmount",
134
- "settleCurrency",
135
- "settleDate",
136
- "exchangeRate",
137
- "exchangeDate",
138
- "cupReserved",
139
- "signMethod",
140
- "signature",
141
- ]
142
-
143
- Sign_ignore_params = [
144
- "bank",
145
- ]
140
+ Sign_ignore_params = [
141
+ "bank",
142
+ ]
146
143
  end
@@ -1,76 +1,54 @@
1
1
  #encoding:utf-8
2
2
  require 'open-uri'
3
3
  require 'digest'
4
+ require 'rack'
4
5
  module UnionPay
5
6
  RESP_SUCCESS = "00" #返回成功
6
7
  QUERY_SUCCESS = "0" #查询成功
7
8
  QUERY_FAIL = "1"
8
9
  QUERY_WAIT = "2"
9
10
  QUERY_INVALID = "3"
10
- module Service
11
+ class Service
12
+ attr_accessor :args
11
13
 
12
- def self.front_pay(args)
13
- args['orderTime'] ||= Time.now.strftime('%Y%m%d%H%M%S') #交易时间, YYYYmmhhddHHMMSS
14
- args['orderCurrency'] ||= UnionPay::CURRENCY_CNY #交易币种,CURRENCY_CNY=>人民币
15
- trans_type = args['transType']
16
- if [UnionPay::CONSUME, UnionPay::PRE_AUTH].include? trans_type
17
- @@api_url = UnionPay.front_pay_url
18
- args.merge!(UnionPay::Pay_params_empty).merge!(UnionPay::Pay_params)
19
- @@param_check = UnionPay::Pay_params_check
20
- else
21
- # 前台交易仅支持 消费 和 预授权
22
- raise("Bad trans_type for front_pay. Use back_pay instead")
23
- end
24
- self.service(args,UnionPay::FRONT_PAY)
25
- end
26
-
27
- def responce(args)
28
- cupReserved = (args['cupReserved'] ||= '')
29
- cupReserved = Rack::Utils.parse_nested_query cupReserved.gsub(/^{/,'').gsub(/}$/,'')
30
- if !args['signature'] || !args['signMethod']
31
- raise('No signature Or signMethod set in notify data!')
32
- end
33
-
34
- args.delete 'signMethod'
35
- if args.delete('signature') != self.sign(args)
36
- raise('Bad signature returned!')
14
+ def self.front_pay(param)
15
+ new.instance_eval do
16
+ param['orderTime'] ||= Time.now.strftime('%Y%m%d%H%M%S') #交易时间, YYYYmmhhddHHMMSS
17
+ param['orderCurrency'] ||= UnionPay::CURRENCY_CNY #交易币种,CURRENCY_CNY=>人民币
18
+ param['transType'] ||= UnionPay::CONSUME
19
+ trans_type = param['transType']
20
+ if [UnionPay::CONSUME, UnionPay::PRE_AUTH].include? trans_type
21
+ @api_url = UnionPay.front_pay_url
22
+ param.merge!(UnionPay::Pay_params_empty).merge!(UnionPay::Pay_params)
23
+ @param_check = UnionPay::Pay_params_check
24
+ else
25
+ # 前台交易仅支持 消费 和 预授权
26
+ raise("Bad trans_type for front_pay. Use back_pay instead")
27
+ end
28
+ service(param,UnionPay::FRONT_PAY)
29
+ self
37
30
  end
38
- args.merge! cupReserved
39
- args.delete 'cupReserved'
40
- args
41
31
  end
42
32
 
43
- def self.service(args, service_type)
44
- if args['commodityUrl']
45
- args['commodityUrl'] = URI::encode(args['commodityUrl'])
46
- end
47
-
48
- has_reserved = false
49
- UnionPay::Mer_params_reserved.each do |k|
50
- if args.has_key? k
51
- value = args.delete k
52
- (arr_reserved ||= []) << "#{k}=#{value}"
53
- has_reserved = true
33
+ def self.responce(param)
34
+ new.instance_eval do
35
+ cup_reserved = (param['cupReserved'] ||= '')
36
+ cup_reserved = Rack::Utils.parse_nested_query cup_reserved[1..-2]
37
+ if !param['signature'] || !param['signMethod']
38
+ raise('No signature Or signMethod set in notify data!')
54
39
  end
55
- end
56
-
57
- if has_reserved
58
- args['merReserved'] = arr_reserved.join('&')
59
- else
60
- args['merReserved'] ||= ''
61
- end
62
40
 
63
- @@param_check.each do |k|
64
- raise("KEY [#{k}] not set in params given") unless args.has_key? k
41
+ param.delete 'signMethod'
42
+ if param.delete('signature') != Service.sign(param)
43
+ raise('Bad signature returned!')
44
+ end
45
+ param.merge! cup_reserved
46
+ param.delete 'cupReserved'
47
+ self
65
48
  end
66
-
67
- # signature
68
- args['signature'] = self.sign(args)
69
- args['signMethod'] = UnionPay::Sign_method
70
- @@args = args
71
- self
72
49
  end
73
50
 
51
+
74
52
  def self.sign(args)
75
53
  sign_str = args.sort.map do |k,v|
76
54
  "#{k}=#{v}&" unless UnionPay::Sign_ignore_params.include? k
@@ -78,12 +56,12 @@ module UnionPay
78
56
  Digest::MD5.hexdigest(sign_str + Digest::MD5.hexdigest(UnionPay.security_key))
79
57
  end
80
58
 
81
- def self.form options={}
59
+ def form options={}
82
60
  attrs = options.map{|k,v| "#{k}='#{v}'"}.join(' ')
83
61
  html = [
84
- "<form #{attrs} action='#{@@api_url}' method='post'>"
62
+ "<form #{attrs} action='#{@api_url}' method='post'>"
85
63
  ]
86
- @@args.each do |k,v|
64
+ args.each do |k,v|
87
65
  html << "<input type='hidden' name='#{k}' value='#{v}' />"
88
66
  end
89
67
  if block_given?
@@ -92,5 +70,36 @@ module UnionPay
92
70
  end
93
71
  html.join
94
72
  end
73
+
74
+ def [] key
75
+ self.args[key]
76
+ end
77
+
78
+ private
79
+ def service(param, service_type)
80
+ if param['commodityUrl']
81
+ param['commodityUrl'] = URI::encode(param['commodityUrl'])
82
+ end
83
+
84
+ arr_reserved = []
85
+ UnionPay::Mer_params_reserved.each do |k|
86
+ arr_reserved << "#{k}=#{param.delete k}" if param.has_key? k
87
+ end
88
+
89
+ if arr_reserved.any?
90
+ param['merReserved'] = arr_reserved.join('&')
91
+ else
92
+ param['merReserved'] ||= ''
93
+ end
94
+
95
+ @param_check.each do |k|
96
+ raise("KEY [#{k}] not set in params given") unless param.has_key? k
97
+ end
98
+
99
+ # signature
100
+ param['signature'] = Service.sign(param)
101
+ param['signMethod'] = UnionPay::Sign_method
102
+ self.args = param
103
+ end
95
104
  end
96
105
  end
@@ -1,3 +1,3 @@
1
1
  module UnionPay
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/unionpay.rb CHANGED
@@ -18,21 +18,21 @@ module UnionPay
18
18
  case e
19
19
  ## 测试环境
20
20
  when :development
21
- UnionPay.front_pay_url = "http://58.246.226.99/UpopWeb/api/Pay.action"
22
- UnionPay.back_pay_url = "http://58.246.226.99/UpopWeb/api/BSPay.action"
23
- UnionPay.query_url = "http://58.246.226.99/UpopWeb/api/Query.action"
21
+ self.front_pay_url = "http://58.246.226.99/UpopWeb/api/Pay.action"
22
+ self.back_pay_url = "http://58.246.226.99/UpopWeb/api/BSPay.action"
23
+ self.query_url = "http://58.246.226.99/UpopWeb/api/Query.action"
24
24
  ## 预上线环境
25
25
  when :pre_production
26
- UnionPay.front_pay_url = "https://www.epay.lxdns.com/UpopWeb/api/Pay.action"
27
- UnionPay.back_pay_url = "https://www.epay.lxdns.com/UpopWeb/api/BSPay.action"
28
- UnionPay.query_url = "https://www.epay.lxdns.com/UpopWeb/api/Query.action"
26
+ self.front_pay_url = "https://www.epay.lxdns.com/UpopWeb/api/Pay.action"
27
+ self.back_pay_url = "https://www.epay.lxdns.com/UpopWeb/api/BSPay.action"
28
+ self.query_url = "https://www.epay.lxdns.com/UpopWeb/api/Query.action"
29
29
  ## 线上环境
30
30
  else
31
- UnionPay.front_pay_url = "https://unionpaysecure.com/api/Pay.action"
32
- UnionPay.back_pay_url = "https://besvr.unionpaysecure.com/api/BSPay.action"
33
- UnionPay.query_url = "https://query.unionpaysecure.com/api/Query.action"
31
+ self.front_pay_url = "https://unionpaysecure.com/api/Pay.action"
32
+ self.back_pay_url = "https://besvr.unionpaysecure.com/api/BSPay.action"
33
+ self.query_url = "https://query.unionpaysecure.com/api/Query.action"
34
34
  end
35
35
  end
36
36
  end
37
37
  self.environment= :production
38
- end
38
+ end
@@ -0,0 +1,7 @@
1
+ require 'test/unit'
2
+ require 'unionpay'
3
+
4
+ UnionPay.environment = :development ## 测试环境, :pre_production #预上线环境, 默认 # 线上环境
5
+ UnionPay.mer_id = '105550149170027'
6
+ UnionPay.mer_abbr = '商户名称'
7
+ UnionPay.security_key = '88888888'
@@ -0,0 +1,29 @@
1
+ require 'test_helper'
2
+
3
+ class UnionPay::ServiceTest < Test::Unit::TestCase
4
+ def generate_form
5
+ param = {}
6
+ param['transType'] = UnionPay::CONSUME #交易类型,CONSUME or PRE_AUTH
7
+ param['orderAmount'] = 11000 #交易金额
8
+ param['orderNumber'] = '20131220151706'
9
+ param['customerIp'] = '127.0.0.1'
10
+ param['frontEndUrl'] = "http://www.example.com/sdk/utf8/front_notify.php" #前台回调URL
11
+ param['backEndUrl'] = "http://www.example.com/sdk/utf8/back_notify.php" #后台回调URL
12
+ param['orderTime'] = '20131220151706'
13
+ param['orderCurrency'] = UnionPay::CURRENCY_CNY #交易币种,CURRENCY_CNY=>人民币
14
+ UnionPay::Service.front_pay(param)
15
+ end
16
+
17
+ def test_generate_form
18
+ assert_not_nil generate_form.form(target: '_blank', id: 'form'){"<input type='submit' />"}
19
+ end
20
+
21
+ def test_generate_form_with_different_environment
22
+ UnionPay.environment = :development
23
+ dev_form = generate_form.form(target: '_blank', id: 'form'){"<input type='submit' />"}
24
+ UnionPay.environment = :production
25
+ pro_form = generate_form.form(target: '_blank', id: 'form'){"<input type='submit' />"}
26
+ assert dev_form != pro_form
27
+ end
28
+
29
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unionpay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-19 00:00:00.000000000 Z
11
+ date: 2013-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -46,11 +46,13 @@ extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
48
  - README.md
49
+ - Rakefile
49
50
  - lib/unionpay.rb
50
51
  - lib/unionpay/conf.rb
51
52
  - lib/unionpay/service.rb
52
53
  - lib/unionpay/version.rb
53
- - test.rb
54
+ - test/test_helper.rb
55
+ - test/unionpay/service_test.rb
54
56
  - unionpay.gemspec
55
57
  homepage: https://github.com/kikyous/unionpay
56
58
  licenses:
@@ -76,4 +78,6 @@ rubygems_version: 2.0.3
76
78
  signing_key:
77
79
  specification_version: 4
78
80
  summary: An unofficial unionpay gem
79
- test_files: []
81
+ test_files:
82
+ - test/test_helper.rb
83
+ - test/unionpay/service_test.rb
data/test.rb DELETED
@@ -1,28 +0,0 @@
1
- #encoding:utf-8
2
- require './lib/unionpay'
3
-
4
- UnionPay.environment = :development ## 测试环境, :pre_production #预上线环境, 默认 # 线上环境
5
- UnionPay.mer_id = '105550149170027'
6
- UnionPay.mer_abbr = '商户名称'
7
- UnionPay.security_key = '88888888'
8
-
9
- param = {}
10
- param['transType'] = UnionPay::CONSUME; #交易类型,CONSUME or PRE_AUTH
11
- param['orderAmount'] = 11000; #交易金额
12
- param['orderNumber'] = Time.now.strftime('%Y%m%d%H%M%S') #订单号,必须唯一
13
- param['customerIp'] = '127.0.0.1'
14
- param['frontEndUrl'] = "http://www.example.com/sdk/utf8/front_notify.php" #前台回调URL
15
- param['backEndUrl'] = "http://www.example.com/sdk/utf8/back_notify.php" #后台回调URL
16
-
17
- # 可填空字段
18
- # param['commodityUrl'] = "http://www.example.com/product?name=商品" #商品URL
19
- # param['commodityName'] = '商品名称' # 商品名称
20
- # param['commodityUnitPrice'] = 11000; //商品单价
21
- # param['commodityQuantity'] = 1; //商品数量
22
- #
23
-
24
- # 其余可填空的参数可以不填写
25
-
26
-
27
-
28
- puts UnionPay::Service.front_pay(param).form(target: '_blank', id: 'form'){"<input type='submit' />"}