yl_pay 1.0.4

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: d6f85e07ab4b74bc06f0681cfed233b595631d8d
4
+ data.tar.gz: 70a04aaa45c3ea553b0d7f81742be50740953d62
5
+ SHA512:
6
+ metadata.gz: d8ff3dcddad997c3ba88b677ee931697d9e253fa0a12a82c7243baef8fbec64c0aa0c2189a27db649cb7feb82b778176b2d36eedc2e1a9df769a6d5e6fbcafb1
7
+ data.tar.gz: eedf4f11d52f299a6349161de3d6cbbd690664727861e704e22f774808d3cb64ed7b65fa821e75a7594bc88cf290d1bc10859b54f8942208cb8889c95aaa9239
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.idea/**
11
+
12
+ # rspec failure tracking
13
+ .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.3.3
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 rickycxj@gmail.com. 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 yl_pay.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Ricky
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ 易联支付 Ruby SDK Gem
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ gem 'yl_pay'
8
+
9
+ And then execute:
10
+
11
+ $ bundle
12
+
13
+ Or install it yourself as:
14
+
15
+ $ gem install yl_pay
16
+
17
+ ## Usage
18
+ ### H5 Payment
19
+
20
+ ### Config
21
+
22
+ Create `config/initializers/yl_pay.rb` and put following configurations into it.
23
+
24
+ ```ruby
25
+ # required
26
+ YlPay.payeco_url = '' # 易联接口URL
27
+ YlPay.mch_rsa_private_key = '' # 商户私钥路径
28
+ YlPay.payeco_rsa_public_key = '' # 易联公钥路径
29
+ YlPay.merchant_id = '' # 商户ID
30
+ YlPay.notify_url = '' # 通知服务器地址
31
+ YlPay.return_url = '' # 重定向地址
32
+
33
+ `YlPay::Service.generate_order_url params` will create an payment request and return a pay url.
34
+
35
+ # required fields
36
+ params = {
37
+ amount: '',
38
+ order_desc: '',
39
+ client_ip: '',
40
+ merch_order_id: '' # 商户订单ID
41
+ }
42
+
43
+ # call generate_order_url
44
+ pay_url = YlPay::Service.generate_order_url params
45
+ ```
46
+
47
+ ## Contributing
48
+
49
+ 1. Fork it ( https://github.com/chenxiaojun/yl_pay/fork )
50
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
51
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
52
+ 4. Push to the branch (`git push origin my-new-feature`)
53
+ 5. Create new Pull Request
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 "yl_pay"
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
@@ -0,0 +1,19 @@
1
+ module YlPay
2
+ class Result
3
+ attr_accessor :code, :msg, :body
4
+
5
+ def initialize(result)
6
+ @code = result['response']['head']['retCode']
7
+ @msg = result['response']['head']['retMsg']
8
+ @body = result['response']['body']
9
+ end
10
+
11
+ def success?
12
+ code.eql?('0000')
13
+ end
14
+
15
+ def failure
16
+ { code: code, msg: msg }
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,75 @@
1
+ require 'faraday'
2
+ require 'json'
3
+ require 'active_support/core_ext/hash/conversions'
4
+
5
+ module YlPay
6
+ class Service
7
+ H5_URI = '/ppi/h5/plugin/itf.do'
8
+ AUTHORIZE_URI = '/ppi/merchant/itf.do'
9
+
10
+ INVOKE_ORDER_REQUIRED_FIELDS = [:amount, :order_desc, :client_ip, :merch_order_id]
11
+ def self.generate_order_url(params, options = {})
12
+ check_required_options(params, INVOKE_ORDER_REQUIRED_FIELDS)
13
+ params = set_params(params, options)
14
+ result = YlPay::Result.new(Hash.from_xml(invoke_remote(YlPay.payeco_url + AUTHORIZE_URI, make_payload(params))))
15
+ return JSON(result.failure) unless result.success?
16
+ back_sign = check_back_sign(result.body)
17
+ return JSON({code: 'E102', data: '签名验证失败'}) unless back_sign
18
+ pay_url(back_sign[0] + "&Sign=#{back_sign[1]}")
19
+ end
20
+
21
+ # 根据返回回来的参数,生成去支付页面的url
22
+ def self.pay_url(params, options = {pay_way: 'h5_pay_url'})
23
+ pay_way = options.delete(:pay_way)
24
+ send(pay_way, params)
25
+ end
26
+
27
+ def self.h5_pay_url(params)
28
+ YlPay.payeco_url + H5_URI + '?tradeId=h5Init' + "&#{params}"
29
+ end
30
+
31
+ class << self
32
+ private
33
+
34
+ def set_params(params, options)
35
+ {
36
+ version: YlPay.version,
37
+ merchant_id: options.delete(:merchant_id) || YlPay.merchant_id,
38
+ notify_url: options.delete(:notify_url) || YlPay.notify_url,
39
+ return_url: options.delete(:return_url) || YlPay.return_url,
40
+ trade_code: options.delete(:trade_code) || 'PayOrder',
41
+ ext_data: options.delete(:ext_data) || 'H5测试',
42
+ exp_time: options.delete(:exp_time) || '',
43
+ notify_flag: options.delete(:notify_flag) || '0',
44
+ misc_data: options.delete(:misc_data) || '',
45
+ }.merge(params)
46
+ end
47
+
48
+ def check_required_options(options, names)
49
+ return unless YlPay.debug_mode?
50
+
51
+ names.each do |name|
52
+ warn("YlPay Warn: missing required option: #{name}") unless options.has_key?(name)
53
+ end
54
+ end
55
+
56
+ def make_payload(params)
57
+ trade_code = params.delete(:trade_code)
58
+ sign_params = YlPay::Utils.param_sign(params)
59
+ rsa_sign = YlPay::Sign.sign(sign_params)
60
+ "TradeCode=#{trade_code}&" + YlPay::Utils.uri_params(params) + "&Sign=#{rsa_sign}"
61
+ end
62
+
63
+ def invoke_remote(url, payload, options = {})
64
+ remote_url = url + "?#{payload}"
65
+ Faraday.get(remote_url).body
66
+ end
67
+
68
+ def check_back_sign(data)
69
+ sign = data.delete('Sign')
70
+ back_sign = YlPay::Utils.back_sign(data)
71
+ YlPay::Sign.verify?(back_sign, sign) ? [back_sign, sign] : false
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,13 @@
1
+ module YlPay
2
+ class Sign
3
+ def self.sign(string)
4
+ rsa = OpenSSL::PKey::RSA.new(File.read(YlPay.mch_rsa_private_key))
5
+ Base64.strict_encode64(rsa.sign(OpenSSL::Digest::MD5.new, string))
6
+ end
7
+
8
+ def self.verify?(string, sign)
9
+ rsa = OpenSSL::PKey::RSA.new(File.read(YlPay.payeco_rsa_public_key))
10
+ rsa.verify(OpenSSL::Digest::MD5.new, Base64.strict_decode64(sign), string)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,38 @@
1
+ module YlPay
2
+ require 'base64'
3
+
4
+ class Utils
5
+ def self.param_sign(params)
6
+ "Version=#{params[:version]}&MerchantId=#{params[:merchant_id]}&MerchOrderId=#{params[:merch_order_id]}&"\
7
+ "Amount=#{params[:amount]}&OrderDesc=#{params[:order_desc]}&TradeTime=#{params[:trade_time]}&ExpTime=#{params[:exp_time]}&"\
8
+ "NotifyUrl=#{params[:notify_url]}&ReturnUrl=#{params[:return_url]}&ExtData=#{params[:ext_data]}&"\
9
+ "MiscData=#{params[:misc_data]}&NotifyFlag=#{params[:notify_flag]}&ClientIp=#{params[:client_ip]}"
10
+ end
11
+
12
+ def self.back_sign(params)
13
+ "Version=#{params['Version']}&MerchantId=#{params['MerchantId']}&MerchOrderId=#{params['MerchOrderId']}&"\
14
+ "Amount=#{params['Amount']}&TradeTime=#{params['TradeTime']}&OrderId=#{params['OrderId']}&VerifyTime=#{params['VerifyTime']}"
15
+ end
16
+
17
+ # 提交参数中包含中文的需要做base64转码
18
+ def self.uri_params(params)
19
+ container = [:order_desc, :ext_data, :misc_data]
20
+ new_params = params.collect do |param|
21
+ if container.include? param[0]
22
+ param[1] = Base64.strict_encode64(param[1])
23
+ end
24
+ param
25
+ end
26
+ new_params = Hash[new_params]
27
+ new_params[:notify_url] = CGI.escape(new_params[:notify_url]) if new_params.key?(:notify_url)
28
+ new_params[:return_url] = CGI.escape(new_params[:return_url]) if new_params.key?(:return_url)
29
+ param_sign new_params
30
+ end
31
+ end
32
+ end
33
+
34
+ # def self.param_sign_auto(params)
35
+ # return_str = ''
36
+ # params.each { |k, v| return_str << "#{k.to_s.split('_').collect(&:capitalize).join}=#{v}&" }
37
+ # return_str.split.join(' ').chop
38
+ # end
@@ -0,0 +1,3 @@
1
+ module YlPay
2
+ VERSION = "1.0.4"
3
+ end
data/lib/yl_pay.rb ADDED
@@ -0,0 +1,23 @@
1
+ require 'yl_pay/service'
2
+ require 'yl_pay/version'
3
+ require 'yl_pay/sign'
4
+ require 'yl_pay/utils'
5
+ require 'yl_pay/result'
6
+ require 'openssl'
7
+
8
+ module YlPay
9
+ @debug_mode = true
10
+
11
+ class << self
12
+ attr_accessor :merchant_id, :notify_url, :return_url, :payeco_url, :mch_rsa_private_key, :payeco_rsa_public_key
13
+
14
+ def debug_mode?
15
+ @debug_mode
16
+ end
17
+
18
+ # 对应的调用易联支付那边的版本号
19
+ def version
20
+ '2.0.0'
21
+ end
22
+ end
23
+ end
data/yl_pay.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'yl_pay/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "yl_pay"
8
+ spec.version = YlPay::VERSION
9
+ spec.authors = ["Ricky"]
10
+ spec.email = ["rickycxj@gmail.com"]
11
+
12
+ spec.summary = "An unofficial simple yilian pay gem"
13
+ spec.description = "An unofficial simple yilian pay gem"
14
+ spec.homepage = "https://github.com/chenxiaojun/yl_pay"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.14"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_development_dependency "faraday"
28
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yl_pay
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Ricky
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-08 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: faraday
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: An unofficial simple yilian pay gem
70
+ email:
71
+ - rickycxj@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
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - lib/yl_pay.rb
87
+ - lib/yl_pay/result.rb
88
+ - lib/yl_pay/service.rb
89
+ - lib/yl_pay/sign.rb
90
+ - lib/yl_pay/utils.rb
91
+ - lib/yl_pay/version.rb
92
+ - yl_pay.gemspec
93
+ homepage: https://github.com/chenxiaojun/yl_pay
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.6.10
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: An unofficial simple yilian pay gem
117
+ test_files: []