shouqianba-webapi-ruby 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1b5ad72f7f67862d6ffd146024bf5bde04f2b60b
4
+ data.tar.gz: efd608a13dec7beaa6c1abef23ca02fbbc621829
5
+ SHA512:
6
+ metadata.gz: 466419912f5f75bfa55809658849592214266496ca6342886a6be80d35fec42d939ce23b92f2ec0c4e16319d47bb05e01be0c81c441e24f5e370ac743a5b974d
7
+ data.tar.gz: 0a23990a1d122ab527b298bac23c81ca9987d9c58a332eb017db0773f57e5c37b308ea161dfa748baa99606bba4063bc42c748fdbb983be117a3cee4db7ad52f
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.14.6
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at xiesubin@xiesubinMBP. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in shouqianba-webapi-ruby.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # Shouqianba::Webapi
2
+
3
+ 该Gem包主要面向收钱吧支付平台文档(https://doc.shouqianba.com/zh-cn/) 进行开发,服务由收钱吧提供
4
+
5
+ ## Installation
6
+
7
+ 将以下粘贴至项目的Gemfile
8
+
9
+ ```ruby
10
+ gem 'shouqianba-webapi-ruby'
11
+ ```
12
+
13
+ 然后:
14
+
15
+ $ bundle
16
+
17
+ 或者手动:
18
+
19
+ $ gem install shouqianba-webapi-ruby
20
+
21
+ ## Usage
22
+
23
+ 激活终端并获取终端信息:activate
24
+ ```
25
+ Shouqianba::Webapi.activate(vendor_sn, vendor_key, app_id, code, device_id, options={}) do |resp|
26
+ # 处理终端返回信息
27
+ end
28
+ ```
29
+
30
+ 终端签到并获取新的终端key:checkin
31
+ ```
32
+ Shouqianba::Webapi.checkin(terminal_sn, terminal_key, device_id, options={}) do |resp|
33
+ # 处理终端返回信息
34
+ end
35
+ ```
36
+
37
+ 付款接口:pay
38
+ ```
39
+ Shouqianba::Webapi.pay(terminal_sn, terminal_key, client_sn, total_amount, dynamic_id, subject, operator, options={}) do |resp|
40
+ # 处理终端返回信息
41
+ end
42
+ ```
43
+
44
+ 预下单接口:precreate
45
+ ```
46
+ Shouqianba::Webapi.precreate(terminal_sn, terminal_key, client_sn, total_amount, payway, subject, operator, options={}) do |resp|
47
+ # 处理终端返回信息
48
+ end
49
+ ```
50
+
51
+ 退款接口:refund
52
+ ```
53
+ Shouqianba::Webapi.refund(terminal_sn, terminal_key, refund_request_no, operator, refund_amount, options={}) do |resp|
54
+ # 处理终端返回信息
55
+ end
56
+ ```
57
+
58
+ 撤单接口:cancel
59
+ ```
60
+ Shouqianba::Webapi.cancel(terminal_sn, terminal_key, options={}) do |resp|
61
+ # 处理终端返回信息
62
+ end
63
+ ```
64
+
65
+ 查询接口:query
66
+ ```
67
+ Shouqianba::Webapi.query(terminal_sn, terminal_key, options={}) do |resp|
68
+ # 处理终端返回信息
69
+ end
70
+ ```
71
+
72
+ 查询接口:wap2_url
73
+ ```
74
+ Shouqianba::Webapi.wap2_url(terminal_sn, client_sn, total_amount, subject, operator, return_url, options={}) do |resp|
75
+ # 处理终端返回跳转链接地址
76
+ end
77
+ ```
78
+
79
+ ## Development
80
+
81
+
82
+
83
+ ## Contributing
84
+
85
+ 有任何疑问,请联系 wanxsb@gmail.com
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "shouqianba/webapi/ruby"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/.DS_Store ADDED
Binary file
Binary file
Binary file
@@ -0,0 +1,5 @@
1
+ module Shouqianba
2
+ module Webapi
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,190 @@
1
+ require "shouqianba/webapi/version"
2
+ require "open-uri"
3
+
4
+ module Shouqianba
5
+ module Webapi
6
+ class Error < ::StandardError
7
+ attr_accessor :result_code, :error_message, :data
8
+
9
+ def initialize(result_code, error_message, data)
10
+ @result_code = result_code.to_i
11
+ @error_message = error_message
12
+ @data = data
13
+ message = "[ result_code: #{@result_code}, error_message: #{@error_message} ]"
14
+ super(message)
15
+ end
16
+ end
17
+
18
+ ShouqianbaHost = "https://api.shouqianba.com"
19
+ #you code goes here
20
+ def self.activate(vendor_sn, vendor_key, app_id, code, device_id, options={})
21
+ params = {
22
+ app_id: app_id,
23
+ code: code,
24
+ device_id: device_id
25
+ }.merge({
26
+ name: options[:name],
27
+ os_info: options[:os_info],
28
+ sdk_version: options[:sdk_version]
29
+ })
30
+
31
+ self.post_method "/terminal/activate", vendor_sn, vendor_key, {}, params do |resp|
32
+ yield(resp)
33
+ end
34
+ end
35
+
36
+ def self.checkin(terminal_sn, terminal_key, device_id, options={})
37
+ params = {
38
+ terminal_sn: terminal_sn,
39
+ device_id: device_id
40
+ }.merge({
41
+ os_info: options[:os_info],
42
+ sdk_version: options[:sdk_version]
43
+ })
44
+ self.post_method "/terminal/checkin", terminal_sn, terminal_key, {}, params do |resp|
45
+ yield(resp)
46
+ end
47
+ end
48
+
49
+ def self.pay(terminal_sn, terminal_key, client_sn, total_amount, dynamic_id, subject, operator, options={})
50
+ params = {
51
+ terminal_sn: terminal_sn,
52
+ client_sn: client_sn,
53
+ total_amount: total_amount,
54
+ dynamic_id: dynamic_id,
55
+ subject: subject,
56
+ operator: operator,
57
+ }.merge({
58
+ payway: options[:payway],
59
+ description: options[:description],
60
+ longitude: options[:longitude],
61
+ latitude: options[:latitude],
62
+ device_id: options[:device_id],
63
+ extended: options[:extended],
64
+ reflect: options[:reflect],
65
+ notify_url: options[:notify_url]
66
+ })
67
+ self.post_method "/upay/v2/pay", terminal_sn, terminal_key, {}, params do |resp|
68
+ yield(resp)
69
+ end
70
+ end
71
+
72
+
73
+ def self.precreate(terminal_sn, terminal_key, client_sn, total_amount, payway, subject, operator, options={})
74
+ params = {
75
+ terminal_sn: terminal_sn,
76
+ client_sn: client_sn,
77
+ total_amount: total_amount,
78
+ payway: payway,
79
+ subject: subject,
80
+ operator: operator
81
+ }.merge({
82
+ sub_payway: options[:sub_payway],
83
+ payer_uid: options[:payer_uid],
84
+ description: options[:description],
85
+ longitude: options[:longitude],
86
+ latitude: options[:latitude],
87
+ extended: options[:extended],
88
+ reflect: options[:reflect],
89
+ notify_url: options[:notify_url]
90
+ })
91
+ self.post_method "/upay/v2/precreate", terminal_sn, terminal_key, {}, params do |resp|
92
+ yield(resp)
93
+ end
94
+ end
95
+
96
+ def self.refund(terminal_sn, terminal_key, refund_request_no, operator, refund_amount, options={})
97
+ params = {
98
+ terminal_sn: terminal_sn,
99
+ refund_request_no: refund_request_no,
100
+ operator: operator,
101
+ refund_amount: refund_amount
102
+ }.merge({
103
+ sn: options[:sn],
104
+ client_sn: options[:client_sn],
105
+ client_tsn: options[:client_tsn],
106
+
107
+ })
108
+ self.post_method "/upay/v2/refund", terminal_sn, terminal_key, {}, params do |resp|
109
+ yield(resp)
110
+ end
111
+ end
112
+
113
+ def self.cancel(terminal_sn, terminal_key, options={})
114
+ params = {
115
+ terminal_sn: terminal_sn
116
+ }.merge({
117
+ sn: options[:sn],
118
+ client_sn: options[:client_sn]
119
+ })
120
+ self.post_method "/upay/v2/cancel", terminal_sn, terminal_key, {}, params do |resp|
121
+ yield(resp)
122
+ end
123
+ end
124
+
125
+ def self.query(terminal_sn, terminal_key, options={})
126
+ params = {
127
+ terminal_sn: terminal_sn
128
+ }.merge({
129
+ sn: options[:sn],
130
+ client_sn: options[:client_sn]
131
+ })
132
+ self.post_method "/upay/v2/query", terminal_sn, terminal_key, {}, params do |resp|
133
+ yield(resp)
134
+ end
135
+ end
136
+
137
+ def self.wap2_url(terminal_sn, terminal_key, client_sn, total_amount, subject, operator, return_url, options={})
138
+ params = {
139
+ terminal_sn: terminal_sn,
140
+ client_sn: client_sn,
141
+ total_amount: total_amount,
142
+ subject: subject,
143
+ operator: operator,
144
+ return_url: return_url
145
+ }.merge({
146
+ payway: options[:payway],
147
+ description: options[:description],
148
+ longitude: options[:longitude],
149
+ latitude: options[:latitude],
150
+ extended: options[:extended],
151
+ reflect: options[:reflect],
152
+ notify_url: options[:notify_url]
153
+ })
154
+ params[:sign] = get_wrap2_sign(params, terminal_key)
155
+ "https://m.wosai.cn/qr/gateway?#{params.to_query}"
156
+ end
157
+
158
+ def self.get_wrap2_sign(params, terminal_key)
159
+ Digest::MD5.hexdigest("#{params.to_query}&#{terminal_key}").upcase
160
+ end
161
+
162
+
163
+ def self.get_sign(body, vendor_or_terminal_key)
164
+ Digest::MD5.hexdigest(body+ vendor_or_terminal_key)
165
+ end
166
+
167
+ # 如果body是字符串,则直接作为请求的内容。如果body是其他类型,则会在内部调用to_json
168
+ def self.post_method(url, vendor_or_terminal_sn, vendor_or_terminal_key, params={}, body={})
169
+ uri = URI.parse("#{ShouqianbaHost}#{url}?#{params.to_query}")
170
+ https = Net::HTTP.new(uri.host,uri.port)
171
+ https.open_timeout = 60
172
+ https.read_timeout = 60
173
+ https.use_ssl = true
174
+ body = body.is_a?(String) ? body : JSON.generate(body)
175
+ req = Net::HTTP::Post.new(uri.request_uri, initheader = {'Content-Type' =>'application/json', 'Authorization' => "#{vendor_or_terminal_sn} #{self.get_sign(body, vendor_or_terminal_key)}"})
176
+ req.body = body
177
+ response = https.request(req)
178
+ data = ActiveSupport::JSON.decode(response.body).to_options
179
+ check_errcode(data)
180
+ yield(data[:biz_response])
181
+ end
182
+
183
+ def self.check_errcode(data)
184
+ Rails.logger.info data
185
+ if data[:result_code].present? && data[:result_code] != "200"
186
+ raise Shouqianba::Webapi::Error.new(data[:result_code], data[:error_message], data)
187
+ end
188
+ end
189
+ end
190
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'shouqianba/webapi/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "shouqianba-webapi-ruby"
8
+ spec.version = Shouqianba::Webapi::VERSION
9
+ spec.authors = ["wanxsb@gmail.com"]
10
+ spec.email = ["wanxsb@gmail.com"]
11
+
12
+ spec.summary = "收钱吧Webapi接口"
13
+ spec.description = "收钱吧Webapi接口"
14
+ spec.homepage = "http://www.diandanbao.com"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.14"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ spec.add_development_dependency "settingslogic"
27
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shouqianba-webapi-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - wanxsb@gmail.com
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-11-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: settingslogic
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: 收钱吧Webapi接口
70
+ email:
71
+ - wanxsb@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - lib/.DS_Store
86
+ - lib/shouqianba/.DS_Store
87
+ - lib/shouqianba/webapi.rb
88
+ - lib/shouqianba/webapi/.DS_Store
89
+ - lib/shouqianba/webapi/version.rb
90
+ - shouqianba-webapi-ruby.gemspec
91
+ homepage: http://www.diandanbao.com
92
+ licenses: []
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.6.11
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: 收钱吧Webapi接口
114
+ test_files: []