midpay_kuaiqian 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.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +68 -0
- data/Rakefile +1 -0
- data/lib/midpay/kuaiqian/version.rb +5 -0
- data/lib/midpay/strategies/kuaiqian.rb +62 -0
- data/lib/midpay_kuaiqian.rb +5 -0
- data/midpay_kuaiqian.gemspec +24 -0
- data/spec/midpay/strategies/kuaiqian_spec.rb +52 -0
- data/spec/spec_helper.rb +37 -0
- metadata +110 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.9.3@midpay-kuaiqian --create
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 xixilive
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# Midpay::Kuaiqian
|
2
|
+
|
3
|
+
Payment strategy for Kuaiqian(快钱 https://www.99bill.com/) base on Midpay Middleware.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'midpay_kuaiqian'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install midpay_kuaiqian
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
In your application initialize
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'midpay_kuaiqian'
|
25
|
+
use Midpay::Strategies::Alipay, APPID, APPSECRET, :request_params_proc => {|params|
|
26
|
+
order = Order.find(params['order_id'])
|
27
|
+
order.to_kuaiqian_params
|
28
|
+
}
|
29
|
+
```
|
30
|
+
|
31
|
+
In your routes:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
map '/midpay/kuaiqian/callback' => 'payment#callback'
|
35
|
+
```
|
36
|
+
|
37
|
+
Type following URL in your browser
|
38
|
+
|
39
|
+
```
|
40
|
+
http://DOMAIN.COM/midpay/kuaiqian?order_id=123
|
41
|
+
```
|
42
|
+
|
43
|
+
And your broswer will navigate to Alipay Casher page,
|
44
|
+
|
45
|
+
Then, handle the callback phase in your controller
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
def callback
|
49
|
+
strategy = request.env['midpay.strategy']
|
50
|
+
callback_data = request.env['midpay.callback'] # A Midpay::PaymentInfo object
|
51
|
+
if callback_data.success?
|
52
|
+
order = Order.find(callback_data.raw_data[:out_trade_no])
|
53
|
+
order.paid!
|
54
|
+
end
|
55
|
+
|
56
|
+
p callback_data.to_hash
|
57
|
+
p callback_data.to_json
|
58
|
+
# ....
|
59
|
+
end
|
60
|
+
```
|
61
|
+
|
62
|
+
## Contributing
|
63
|
+
|
64
|
+
1. Fork it
|
65
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
66
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
67
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
68
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'midpay'
|
2
|
+
module Midpay
|
3
|
+
module Strategies
|
4
|
+
class Kuaiqian
|
5
|
+
|
6
|
+
GATEWAY = "https://www.99bill.com/gateway/recvMerchantInfoAction.htm"
|
7
|
+
|
8
|
+
REQUEST_PARAM_KEYS = %w[
|
9
|
+
inputCharset bgUrl pageUrl version language signType merchantAcctId
|
10
|
+
payerName payerContactType payerContact orderId orderAmount orderTime
|
11
|
+
productName productNum productId productDesc ext1 ext2 payType redoFlag pid
|
12
|
+
]
|
13
|
+
|
14
|
+
RETURN_PARAM_KEYS = %w[
|
15
|
+
merchantAcctId version language signType payType bankId orderId orderTime
|
16
|
+
orderAmount dealId bankDealId dealTime payAmount fee ext1 ext2 payResult errorCode
|
17
|
+
]
|
18
|
+
|
19
|
+
include Midpay::Strategy
|
20
|
+
|
21
|
+
set :inputCharset, "1" #utf-8
|
22
|
+
set :version, "v2.0"
|
23
|
+
set :language, "1" #zh_CN
|
24
|
+
set :signType, "1" #MD5
|
25
|
+
set :payType, "00"
|
26
|
+
set :redoFlag, "0"
|
27
|
+
|
28
|
+
def request_phase response
|
29
|
+
response.redirect kuaiqian_request_url
|
30
|
+
end
|
31
|
+
|
32
|
+
def callback_phase pi
|
33
|
+
raise Midpay::Errors::InvalidSignature.new unless request_params[:sign] == request_params.sign(:signType){|h| kuaiqian_sign_str(RETURN_PARAM_KEYS,h) }
|
34
|
+
pi.raw_data = request_params.symbolize_keys
|
35
|
+
pi.success = (pi.raw_data['payResult'] == "10")
|
36
|
+
end
|
37
|
+
|
38
|
+
def kuaiqian_request_params
|
39
|
+
params = request_data
|
40
|
+
params.merge_if!(arguments.merge(merchantAcctId: options.app_key, pageUrl: callback_url))
|
41
|
+
params.sign!(:signMsg, kuaiqian_sign_type(params[:signType])) do |hash|
|
42
|
+
kuaiqian_sign_str(REQUEST_PARAM_KEYS, hash)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def kuaiqian_request_url
|
47
|
+
GATEWAY + '?' + kuaiqian_request_params.to_query
|
48
|
+
end
|
49
|
+
|
50
|
+
def kuaiqian_sign_str keys, hash
|
51
|
+
keys.collect{|k| hash[k].to_s.empty? ? nil : [k, hash[k]]}.compact.push(["key",options.app_secret]).collect{|i| i.join("=") }.join("&")
|
52
|
+
end
|
53
|
+
|
54
|
+
def kuaiqian_sign_type sign_type
|
55
|
+
{
|
56
|
+
"1" => "MD5"
|
57
|
+
}[sign_type.to_s]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
::Midpay[:kuaiqian] = ::Midpay::Strategies::Kuaiqian
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'midpay/kuaiqian/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "midpay_kuaiqian"
|
8
|
+
spec.version = Midpay::Kuaiqian::VERSION
|
9
|
+
spec.authors = ["xixilive"]
|
10
|
+
spec.email = ["xixilive@gmail.com"]
|
11
|
+
spec.description = %q{Payment strategy for Kuaiqian(https://www.99bill.com/) base on Midpay Middleware.}
|
12
|
+
spec.summary = %q{Payment strategy for Kuaiqian(https://www.99bill.com/) base on Midpay Middleware.}
|
13
|
+
spec.homepage = "https://github.com/xixilive/midpay_kuaiqian"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "midpay"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Midpay::Strategies::Kuaiqian do
|
4
|
+
include Rack::Test::Methods
|
5
|
+
|
6
|
+
let(:inner_app){
|
7
|
+
lambda { |env| [200, {"Content-Type" => "text/html"}, ["body"]] }
|
8
|
+
}
|
9
|
+
|
10
|
+
let(:app){
|
11
|
+
Midpay::Strategies::Kuaiqian.new(inner_app,
|
12
|
+
:app_key => "APPKEY",
|
13
|
+
:app_secret => "APPSECRET",
|
14
|
+
:request_params_proc => Proc.new{|params|
|
15
|
+
{
|
16
|
+
:orderId => params['order_id'],
|
17
|
+
:orderAmount => 1,
|
18
|
+
:orderTime => "20130710154023",
|
19
|
+
:productName => "product name",
|
20
|
+
:productNum => 1,
|
21
|
+
:productDesc=> "product desc"
|
22
|
+
}
|
23
|
+
}
|
24
|
+
)
|
25
|
+
}
|
26
|
+
|
27
|
+
let(:query_data){
|
28
|
+
{
|
29
|
+
"merchantAcctId"=>"1002109591401", "version"=>"v2.0", "language"=>"1", "signType"=>"1",
|
30
|
+
"payType"=>"10", "bankId"=>"CCB", "orderId"=>"5094e515bcc1261dc1000013", "orderTime"=>"20121103173413",
|
31
|
+
"orderAmount"=>"20500", "dealId"=>"783157316", "bankDealId"=>"121103701336", "dealTime"=>"20121103173749",
|
32
|
+
"payAmount"=>"20500", "fee"=>"123", "payResult"=>"10", "signMsg" => "777bea3ae5c45d311eda964d4c76e276"
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
let(:query){
|
37
|
+
query_data.to_a.collect{|i| i.join("=") }.join("&")
|
38
|
+
}
|
39
|
+
|
40
|
+
it 'request phase' do
|
41
|
+
get '/midpay/kuaiqian?order_id=123456'
|
42
|
+
expect(last_response.headers["Location"]).to eq("https://www.99bill.com/gateway/recvMerchantInfoAction.htm?inputCharset=1&language=1&merchantAcctId=APPKEY&orderAmount=1&orderId=123456&orderTime=20130710154023&pageUrl=http%3A%2F%2Fexample.org%2Fmidpay%2Fkuaiqian%2Fcallback&payType=00&productDesc=product+desc&productName=product+name&productNum=1&redoFlag=0&signMsg=b161c0227172e3529eb10b193ce79f62&signType=1&version=v2.0")
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'callback phase' do
|
46
|
+
get "/midpay/kuaiqian/callback?#{query}"
|
47
|
+
expect(last_request.env['midpay.callback'].pay).to eq("kuaiqian")
|
48
|
+
expect(last_request.env['midpay.callback'].raw_data).to eq(query_data)
|
49
|
+
expect(last_request.env['midpay.callback'].success?).to be_true
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding:utf-8
|
2
|
+
require 'rspec'
|
3
|
+
require 'rspec/autorun'
|
4
|
+
require 'rack/test'
|
5
|
+
require 'midpay_kuaiqian'
|
6
|
+
|
7
|
+
if %W[on yes true 1].include?(ENV['RCOV'])
|
8
|
+
require 'simplecov'
|
9
|
+
require 'simplecov-rcov'
|
10
|
+
class SimpleCov::Formatter::MergedFormatter
|
11
|
+
def format(result)
|
12
|
+
SimpleCov::Formatter::HTMLFormatter.new.format(result)
|
13
|
+
SimpleCov::Formatter::RcovFormatter.new.format(result)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
SimpleCov.formatter = SimpleCov::Formatter::MergedFormatter
|
17
|
+
|
18
|
+
SimpleCov.start "test_frameworks" do
|
19
|
+
#add_filter ''
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
Dir["spec/support/**/*.rb"].each { |f| require File.expand_path(f) }
|
24
|
+
|
25
|
+
RSpec.configure do |c|
|
26
|
+
c.before(:suite) do
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
c.before(:each) do
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
c.after(:suite) do
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: midpay_kuaiqian
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- xixilive
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-08-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: midpay
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: bundler
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '1.3'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '1.3'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Payment strategy for Kuaiqian(https://www.99bill.com/) base on Midpay
|
63
|
+
Middleware.
|
64
|
+
email:
|
65
|
+
- xixilive@gmail.com
|
66
|
+
executables: []
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- .gitignore
|
71
|
+
- .rspec
|
72
|
+
- .rvmrc
|
73
|
+
- Gemfile
|
74
|
+
- LICENSE.txt
|
75
|
+
- README.md
|
76
|
+
- Rakefile
|
77
|
+
- lib/midpay/kuaiqian/version.rb
|
78
|
+
- lib/midpay/strategies/kuaiqian.rb
|
79
|
+
- lib/midpay_kuaiqian.rb
|
80
|
+
- midpay_kuaiqian.gemspec
|
81
|
+
- spec/midpay/strategies/kuaiqian_spec.rb
|
82
|
+
- spec/spec_helper.rb
|
83
|
+
homepage: https://github.com/xixilive/midpay_kuaiqian
|
84
|
+
licenses:
|
85
|
+
- MIT
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ! '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 1.8.25
|
105
|
+
signing_key:
|
106
|
+
specification_version: 3
|
107
|
+
summary: Payment strategy for Kuaiqian(https://www.99bill.com/) base on Midpay Middleware.
|
108
|
+
test_files:
|
109
|
+
- spec/midpay/strategies/kuaiqian_spec.rb
|
110
|
+
- spec/spec_helper.rb
|