unionpei 1.2.0 → 1.3.1

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
  SHA256:
3
- metadata.gz: ab2f6a36a20d9faf9d86114493a7ec077afd68a937cc8f321a9b721d72ec5765
4
- data.tar.gz: 3430627f305f5772463bead2e8ca45b39414b023a02da1d7856433216fc2b16c
3
+ metadata.gz: 1e6b75a75c7873af619848b433d7f80bc086e110fd675130a529fdc87e38fcdb
4
+ data.tar.gz: 8d85162ba956cd54db133f1383f1c27354053d243fe4bc0d0105ce46b9283b63
5
5
  SHA512:
6
- metadata.gz: 179c56aac0e48f0938de414db3a46978d3ac6d46b03cad194cbeada375c4e028778a1aa68083910ef71f39e7112538cd3999ca7d0504e4f73bc80c06bee82ab2
7
- data.tar.gz: 7097aaa2fd90dae33c6426a583c6d5deefdf231dbfe7ca5a00f4524f5134767849e0cc50b52d4e6415e2e3ace6790337f0a17770cb9e901e68fee014ffe207b0
6
+ metadata.gz: d7a5e4a06edf18f83a62d13a2974434b3fdbbc52d83125c94c2dd0f50a8061c3b9ac4ac74cfd90e10ea4216c543df7d68dec96d383f4fb742ed3eb65de53fe32
7
+ data.tar.gz: d743aa56571ab9bad9e23b2b87f63a41185da98ab126e3988f0f3924e03f6ad82dea18125267c0972af8f440dc640f7c46476a9258c35e07536ab34ae8c9f288
@@ -0,0 +1,45 @@
1
+ name: Ruby Gem
2
+
3
+ on:
4
+ push:
5
+ branches: [ "master" ]
6
+ pull_request:
7
+ branches: [ "master" ]
8
+
9
+ jobs:
10
+ build:
11
+ name: Build + Publish
12
+ runs-on: ubuntu-latest
13
+ permissions:
14
+ contents: read
15
+ packages: write
16
+
17
+ steps:
18
+ - uses: actions/checkout@v3
19
+ - name: Set up Ruby 2.6
20
+ uses: actions/setup-ruby@v1
21
+ with:
22
+ ruby-version: 2.6.x
23
+
24
+ - name: Publish to GPR
25
+ run: |
26
+ mkdir -p $HOME/.gem
27
+ touch $HOME/.gem/credentials
28
+ chmod 0600 $HOME/.gem/credentials
29
+ printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
30
+ gem build *.gemspec
31
+ gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
32
+ env:
33
+ GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
34
+ OWNER: ${{ github.repository_owner }}
35
+
36
+ - name: Publish to RubyGems
37
+ run: |
38
+ mkdir -p $HOME/.gem
39
+ touch $HOME/.gem/credentials
40
+ chmod 0600 $HOME/.gem/credentials
41
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
42
+ gem build *.gemspec
43
+ gem push *.gem
44
+ env:
45
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ UnionPei - 非官方银联支付(UnionPay)SDK
2
+ --------
3
+
4
+ # Install
5
+
6
+ ```ruby
7
+ gem 'unionpei'
8
+
9
+ ```
10
+
11
+ # 快速开始(rails)
12
+
13
+ ## 指定读取设定的配置文件
14
+
15
+ ```ruby
16
+ # config/initializers/unionpei.rb
17
+ UnionPei.configure do |config|
18
+ if Rails.env.production?
19
+ config.acp_sdk_config_path = Rails.root.join('safe/unionpay/acp_production_sdk.ini')
20
+ end
21
+ end
22
+
23
+ ```
24
+
25
+ ## 生成支付的页面
26
+ ```ruby
27
+ # 参数可参考相关文档,或者源码中payment.rb
28
+
29
+ class PaymentsController < ApplicationController
30
+
31
+ # B2C 支付
32
+ def union_b2c_pay
33
+ UnionPei::Payment.b2c({})
34
+ render html: UnionPei::Payment.b2c.html_safe
35
+ end
36
+
37
+ # B2B 支付
38
+ def union_b2b_pay
39
+ UnionPei::Payment.b2b({})
40
+ render html: UnionPei::Payment.b2b.html_safe
41
+ end
42
+
43
+ # 查询订单详情
44
+ def query_trans
45
+ UnionPei::Payment.query_trans({})
46
+ end
47
+ end
48
+ ```
49
+
50
+ # 参考文档
51
+
52
+ - 银联测试参数:https://open.unionpay.com/tjweb/user/mchTest/param
53
+ - 测试说明:https://open.unionpay.com/tjweb/support/faq/mchlist?id=516
54
+ - 证书说明:https://open.unionpay.com/tjweb/support/faq/mchlist?id=21
55
+ - API文档:https://open.unionpay.com/tjweb/acproduct/APIList?apiservId=448&acpAPIId=754&bussType=0
56
+ - SDK下载:https://open.unionpay.com/tjweb/support/faq/mchlist?id=38
57
+ - 测试卡信息:https://open.unionpay.com/tjweb/support/faq/mchlist?id=4
58
+ - B2B:https://open.unionpay.com/tjweb/acproduct/list?apiSvcId=452&index=999
59
+
60
+ # 免责声明
61
+
62
+ 本Gem对以下非官方代码进行封装和改造:
63
+
64
+ https://open.unionpay.com/tjweb/support/faq/mchlist?id=38
65
+
66
+ 代码仅供参考学习,生产环境请自行封装代码。
67
+
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UnionPei
4
+ class Configuration
5
+ attr_accessor :acp_sdk_config_path
6
+
7
+ def initialize
8
+ @acp_sdk_config_path = default_acp_sdk_path
9
+ end
10
+
11
+ def default_acp_sdk_path
12
+ "#{File.dirname(__FILE__)}/acp_sdk.ini"
13
+ end
14
+ end
15
+ end
@@ -6,80 +6,89 @@ require_relative 'acp_service'
6
6
  module UnionPei
7
7
  class Payment
8
8
  class << self
9
- @@default_b2c_req = {
10
- 'version' => UnionPei::SDKConfig.instance.version,
11
- 'encoding' => UnionPei::SDKConfig.instance.encoding,
12
- 'signMethod' => UnionPei::SDKConfig.instance.signMethod,
13
- 'frontUrl' => UnionPei::SDKConfig.instance.frontUrl,
14
- 'backUrl' => UnionPei::SDKConfig.instance.backUrl,
15
- 'txnType' => '01',
16
- 'txnSubType' => '01',
17
- 'bizType' => '000201', # 000201 是b2c / 000202 是 b2b
18
- 'channelType' => '07',
19
- 'currencyCode' => '156',
20
- 'txnAmt' => '881000',
21
- 'merId' => '777290058189920',
22
- 'orderId' => DateTime.parse(Time.now.to_s).strftime('%Y%m%d%H%M%S').to_s,
23
- 'txnTime' => DateTime.parse(Time.now.to_s).strftime('%Y%m%d%H%M%S').to_s,
24
- 'accessType' => '0'
25
- }
9
+ def default_b2c_req
10
+ {
11
+ 'version' => UnionPei::SDKConfig.instance.version,
12
+ 'encoding' => UnionPei::SDKConfig.instance.encoding,
13
+ 'signMethod' => UnionPei::SDKConfig.instance.signMethod,
14
+ 'frontUrl' => UnionPei::SDKConfig.instance.frontUrl,
15
+ 'backUrl' => UnionPei::SDKConfig.instance.backUrl,
16
+ 'txnType' => '01',
17
+ 'txnSubType' => '01',
18
+ 'bizType' => '000201', # 000201 是b2c / 000202 是 b2b
19
+ 'channelType' => '07',
20
+ 'currencyCode' => '156',
21
+ 'txnAmt' => '881000',
22
+ 'merId' => '777290058189920',
23
+ 'orderId' => DateTime.parse(Time.now.to_s).strftime('%Y%m%d%H%M%S').to_s,
24
+ 'txnTime' => DateTime.parse(Time.now.to_s).strftime('%Y%m%d%H%M%S').to_s,
25
+ 'accessType' => '0'
26
+ }
27
+ end
26
28
 
27
29
  # 【默认大于配置】哲学
28
- def b2c(req = @@default_b2c_req)
29
- req = @@default_b2c_req.merge(req)
30
- UnionPei::AcpService.sign(req)
30
+ def b2c(req = {})
31
+ req = default_b2c_req.merge(req)
32
+ signature = UnionPei::AcpService.sign(req)
33
+ req['signature'] = signature
31
34
  url = UnionPei::SDKConfig.instance.frontTransUrl
32
35
  UnionPei::AcpService.createAutoFormHtml(req, url)
33
36
  end
34
37
 
35
- @@default_b2b_req = {
36
- 'version' => UnionPei::SDKConfig.instance.version,
37
- 'encoding' => UnionPei::SDKConfig.instance.encoding,
38
- 'signMethod' => UnionPei::SDKConfig.instance.signMethod,
39
- 'frontUrl' => UnionPei::SDKConfig.instance.frontUrl,
40
- 'backUrl' => UnionPei::SDKConfig.instance.backUrl,
41
- 'txnType' => '01',
42
- 'txnSubType' => '01',
43
- 'bizType' => '000202', # 000201 是b2c / 000202 是 b2b,
44
- 'channelType' => '07',
45
- 'currencyCode' => '156',
46
- 'txnAmt' => '881000',
47
- 'merId' => '777290058189920',
48
- 'orderId' => DateTime.parse(Time.now.to_s).strftime('%Y%m%d%H%M%S').to_s,
49
- 'txnTime' => DateTime.parse(Time.now.to_s).strftime('%Y%m%d%H%M%S').to_s,
50
- 'accessType' => '0',
51
- 'payTimeout' => DateTime.parse((Time.now + 15 * 60 * 1000).to_s).strftime('%Y%m%d%H%M%S').to_s,
52
- 'bizScene' => '110001',
53
- 'payeeAcctNm' => 'xx商户',
54
- 'payeeAcctNo' => '12345678',
55
- 'payeeBankName' => 'xx行'
56
- }
38
+ def default_b2b_req
39
+ {
40
+ 'version' => UnionPei::SDKConfig.instance.version,
41
+ 'encoding' => UnionPei::SDKConfig.instance.encoding,
42
+ 'signMethod' => UnionPei::SDKConfig.instance.signMethod,
43
+ 'frontUrl' => UnionPei::SDKConfig.instance.frontUrl,
44
+ 'backUrl' => UnionPei::SDKConfig.instance.backUrl,
45
+ 'txnType' => '01',
46
+ 'txnSubType' => '01',
47
+ 'bizType' => '000202', # 000201 是b2c / 000202 是 b2b,
48
+ 'channelType' => '07',
49
+ 'currencyCode' => '156',
50
+ 'txnAmt' => '881000',
51
+ 'merId' => '777290058189920',
52
+ 'orderId' => DateTime.parse(Time.now.to_s).strftime('%Y%m%d%H%M%S').to_s,
53
+ 'txnTime' => DateTime.parse(Time.now.to_s).strftime('%Y%m%d%H%M%S').to_s,
54
+ 'accessType' => '0',
55
+ 'payTimeout' => DateTime.parse((Time.now + 15 * 60 * 1000).to_s).strftime('%Y%m%d%H%M%S').to_s,
56
+ 'bizScene' => '110001',
57
+ 'payeeAcctNm' => 'xx商户',
58
+ 'payeeAcctNo' => '12345678',
59
+ 'payeeBankName' => 'xx行'
60
+ }
61
+ end
57
62
 
58
- def b2b(req = @@default_b2b_req)
59
- req = @@default_b2b_req.merge(req)
60
- UnionPei::AcpService.sign(req)
63
+ def b2b(req = {})
64
+ req = default_b2b_req.merge(req)
65
+ signature = UnionPei::AcpService.sign(req)
66
+ req['signature'] = signature
61
67
  url = UnionPei::SDKConfig.instance.frontTransUrl
62
68
  UnionPei::AcpService.createAutoFormHtml(req, url)
63
69
  end
64
70
 
65
- @@default_trans_req = {
66
- 'version' => UnionPei::SDKConfig.instance.version,
67
- 'encoding' => UnionPei::SDKConfig.instance.encoding,
68
- 'bizType' => '000000',
69
- 'txnTime' => DateTime.parse(Time.now.to_s).strftime('%Y%m%d%H%M%S').to_s,
70
- 'txnType' => '00',
71
- 'txnSubType' => '00',
72
- 'accessType' => '0',
73
- 'signMethod' => UnionPei::SDKConfig.instance.signMethod,
74
- 'merId' => '777290058189920',
75
- 'orderId' => DateTime.parse(Time.now.to_s).strftime('%Y%m%d%H%M%S').to_s
76
- }
71
+ def default_trans_req
72
+ {
73
+ 'version' => UnionPei::SDKConfig.instance.version,
74
+ 'encoding' => UnionPei::SDKConfig.instance.encoding,
75
+ 'bizType' => '000000',
76
+ 'txnTime' => DateTime.parse(Time.now.to_s).strftime('%Y%m%d%H%M%S').to_s,
77
+ 'txnType' => '00',
78
+ 'txnSubType' => '00',
79
+ 'accessType' => '0',
80
+ 'signMethod' => UnionPei::SDKConfig.instance.signMethod,
81
+ 'merId' => '777290058189920',
82
+ 'orderId' => DateTime.parse(Time.now.to_s).strftime('%Y%m%d%H%M%S').to_s
83
+ }
84
+ end
77
85
 
78
86
  # query single transaction info
79
87
  # doc https://open.unionpay.com/tjweb/acproduct/APIList?acpAPIId=757&apiservId=448&version=V2.2&bussType=0
80
- def query_trans(req = @@default_trans_req)
81
- req = @@default_trans_req.merge(req)
82
- UnionPei::AcpService.sign(req)
88
+ def query_trans(req = {})
89
+ req = default_trans_req.merge(req)
90
+ signature = UnionPei::AcpService.sign(req)
91
+ req['signature'] = signature
83
92
  url = UnionPei::SDKConfig.instance.singleQueryUrl
84
93
  UnionPei::AcpService.post(req, url)
85
94
  end
@@ -16,7 +16,6 @@ module UnionPei
16
16
  def initialize
17
17
  ini = parse_acpsdk
18
18
  acpsdk = ini['acpsdk']
19
-
20
19
  @frontTransUrl = acpsdk['acpsdk.frontTransUrl']
21
20
  @singleQueryUrl = acpsdk['acpsdk.singleQueryUrl']
22
21
  @backTransUrl = acpsdk['acpsdk.backTransUrl']
@@ -68,8 +67,8 @@ module UnionPei
68
67
  end
69
68
 
70
69
  def parse_acpsdk
71
- path = File.dirname(__FILE__)
72
- @ini ||= IniParse.parse(File.read("#{path}/acp_sdk.ini").force_encoding('UTF-8'))
70
+ acp_sdk_config_path = ::UnionPei.configuration.acp_sdk_config_path
71
+ IniParse.parse(File.read(acp_sdk_config_path).force_encoding('UTF-8'))
73
72
  end
74
73
  end
75
74
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module UnionPei
4
- VERSION = '1.2.0'
5
- end
4
+ VERSION = '1.3.1'
5
+ end
data/lib/unionpei.rb CHANGED
@@ -1,5 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ module UnionPei
4
+ class Error < StandardError; end
5
+
6
+ class << self
7
+ def configuration
8
+ @configuration ||= Configuration.new
9
+ end
10
+
11
+ def configure
12
+ yield(configuration)
13
+ end
14
+ end
15
+ end
16
+
17
+ require 'unionpei/configuration'
3
18
  require 'unionpei/version'
4
19
  require 'unionpei/sdk_config'
5
20
  require 'unionpei/log_util'
@@ -7,6 +22,3 @@ require 'unionpei/cert_util'
7
22
  require 'unionpei/sdk_util'
8
23
  require 'unionpei/acp_service'
9
24
  require 'unionpei/payment'
10
-
11
- module UnionPei
12
- end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unionpei
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - memorycancel
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-08-29 00:00:00.000000000 Z
12
+ date: 2022-08-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: iniparse
@@ -101,8 +101,10 @@ executables: []
101
101
  extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
+ - ".github/workflows/gem-push.yml"
104
105
  - ".gitignore"
105
106
  - Gemfile
107
+ - README.md
106
108
  - Rakefile
107
109
  - certs/acp_test_enc.cer
108
110
  - certs/acp_test_middle.cer
@@ -113,12 +115,12 @@ files:
113
115
  - lib/unionpei/acp_sdk.ini
114
116
  - lib/unionpei/acp_service.rb
115
117
  - lib/unionpei/cert_util.rb
118
+ - lib/unionpei/configuration.rb
116
119
  - lib/unionpei/log_util.rb
117
120
  - lib/unionpei/payment.rb
118
121
  - lib/unionpei/sdk_config.rb
119
122
  - lib/unionpei/sdk_util.rb
120
123
  - lib/unionpei/version.rb
121
- - readme.txt
122
124
  - unionpei.gemspec
123
125
  homepage: https://rubygems.org/gems/unionpei
124
126
  licenses:
@@ -139,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
141
  - !ruby/object:Gem::Version
140
142
  version: '0'
141
143
  requirements: []
142
- rubygems_version: 3.3.5
144
+ rubygems_version: 3.0.3.1
143
145
  signing_key:
144
146
  specification_version: 4
145
147
  summary: An unofficial unionpay gem
data/readme.txt DELETED
@@ -1,25 +0,0 @@
1
- UnionPei - 非官方银联支付(UnionPay)SDK,使用MIT协议。
2
-
3
- 免责声明
4
-
5
- 本Gem对以下非官方代码进行封装和改造:
6
- https://open.unionpay.com/tjweb/support/faq/mchlist?id=38
7
- 代码仅供参考学习,生产环境请自行封装代码。
8
-
9
- 参考文档
10
-
11
- 银联测试参数:https://open.unionpay.com/tjweb/user/mchTest/param
12
- 测试说明:https://open.unionpay.com/tjweb/support/faq/mchlist?id=516
13
- 证书说明:https://open.unionpay.com/tjweb/support/faq/mchlist?id=21
14
- API文档:https://open.unionpay.com/tjweb/acproduct/APIList?apiservId=448&acpAPIId=754&bussType=0
15
- SDK下载:https://open.unionpay.com/tjweb/support/faq/mchlist?id=38
16
- 测试卡信息:https://open.unionpay.com/tjweb/support/faq/mchlist?id=4
17
- B2B:https://open.unionpay.com/tjweb/acproduct/list?apiSvcId=452&index=999
18
-
19
- 快速开始(rails)
20
-
21
- class PaymentsController < ApplicationController
22
- def union_pay
23
- render html: UnionPei::Payment.b2c.html_safe
24
- end
25
- end