qtpay 0.0.1 → 0.0.2
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/LICENSE +22 -0
- data/lib/qtpay/service.rb +77 -11
- data/lib/qtpay/version.rb +1 -1
- metadata +3 -2
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015, April Tsang
|
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/lib/qtpay/service.rb
CHANGED
@@ -33,32 +33,98 @@ module Qtpay
|
|
33
33
|
make_request(:post, create_pre_order_url(params, options))
|
34
34
|
end
|
35
35
|
|
36
|
+
# ==== params ====
|
37
|
+
# (required)
|
38
|
+
# token: auth token created in get_user_token
|
39
|
+
# order_token: order token created in create_pre_order
|
40
|
+
# total_amt: total payment amount in cents
|
41
|
+
# pay_type: payment type (1: alipay, 2: wechat)
|
42
|
+
# pay_source: payment source (4: scan code)
|
43
|
+
# goods_name: name of goods
|
44
|
+
#
|
45
|
+
# (optional)
|
46
|
+
# pay_amt: payment amount
|
47
|
+
# balance_amt
|
48
|
+
# coupon_amt
|
49
|
+
# coupon_code
|
50
|
+
# point_amt
|
51
|
+
# point_num
|
52
|
+
# goods_info
|
53
|
+
# mobile
|
54
|
+
# openid: openid when creating wechat qrcode
|
55
|
+
# limit_pay
|
56
|
+
|
57
|
+
def self.create_order(params, options = {})
|
58
|
+
make_request(:post, create_order_url(params, options))
|
59
|
+
end
|
60
|
+
|
61
|
+
# ==== params ====
|
62
|
+
# (optional)
|
63
|
+
# token: auth token created in get_user_token, required when caller is app or h5
|
64
|
+
# order_id: either order_id or out_sn is required
|
65
|
+
# out_sn: either order_id or out_sn is required
|
66
|
+
|
67
|
+
def self.get_order(params, options ={})
|
68
|
+
make_request(:get, get_order_url(params, options))
|
69
|
+
end
|
70
|
+
|
71
|
+
# ==== params ====
|
72
|
+
# (required)
|
73
|
+
# order_id
|
74
|
+
#
|
75
|
+
# (optional)
|
76
|
+
# amt: amount
|
77
|
+
|
78
|
+
def self.refund_order(params, options = {})
|
79
|
+
make_request(:post, refund_order_url(params, options))
|
80
|
+
end
|
81
|
+
|
36
82
|
GET_USER_TOKEN_REQUIRED_PARAMS = %w( out_user )
|
37
83
|
def self.get_user_token_url(params, options = {})
|
38
|
-
params =
|
39
|
-
check_required_params(params, GET_USER_TOKEN_REQUIRED_PARAMS)
|
40
|
-
|
41
|
-
params = {
|
42
|
-
'caller' => 'server',
|
43
|
-
'app_code' => options[:app_code] || Qtpay.app_code,
|
44
|
-
}.merge(params)
|
84
|
+
params = handle_params(params, GET_USER_TOKEN_REQUIRED_PARAMS, options)
|
45
85
|
|
46
86
|
request_uri('/auth/v1/token', params, options)
|
47
87
|
end
|
48
88
|
|
49
89
|
CREATE_PRE_ORDER_REQUIRED_PARAMS = %w( total_amt out_sn )
|
50
90
|
def self.create_pre_order_url(params, options = {})
|
91
|
+
params = handle_params(params, CREATE_PRE_ORDER_REQUIRED_PARAMS, options)
|
92
|
+
|
93
|
+
request_uri('/order/v1/pre_create', params, options)
|
94
|
+
end
|
95
|
+
|
96
|
+
CREATE_ORDER_REQUIRED_PARAMS = %w( token order_token total_amt pay_type pay_source goods_name )
|
97
|
+
def self.create_order_url(params, options = {})
|
98
|
+
params = handle_params(params, CREATE_ORDER_REQUIRED_PARAMS, options)
|
99
|
+
|
100
|
+
request_uri('/order/v1/create', params, options)
|
101
|
+
end
|
102
|
+
|
103
|
+
GET_ORDER_REQUIRED_PARAMS = %w()
|
104
|
+
def self.get_order_url(params, options = {})
|
105
|
+
params = handle_params(params, GET_ORDER_REQUIRED_PARAMS, options)
|
106
|
+
|
107
|
+
request_uri('/order/v1/query', params, options)
|
108
|
+
end
|
109
|
+
|
110
|
+
REFUND_ORDER_REQUIRED_PARAMS = %w(order_id)
|
111
|
+
def self.refund_order_url(params, options = {})
|
112
|
+
params = handle_params(params, REFUND_ORDER_REQUIRED_PARAMS, options)
|
113
|
+
|
114
|
+
request_uri('/order/v1/refund', params, options)
|
115
|
+
end
|
116
|
+
|
117
|
+
def self.handle_params(params, required_params, options = {})
|
51
118
|
params = Utils.stringify_keys(params)
|
52
|
-
check_required_params(params,
|
119
|
+
check_required_params(params, required_params)
|
53
120
|
|
54
|
-
|
121
|
+
{
|
55
122
|
'caller' => 'server',
|
56
123
|
'app_code' => options[:app_code] || Qtpay.app_code,
|
57
124
|
}.merge(params)
|
58
|
-
|
59
|
-
request_uri('/order/v1/pre_create', params, options)
|
60
125
|
end
|
61
126
|
|
127
|
+
|
62
128
|
def self.request_uri(path, params, options = {})
|
63
129
|
uri = URI("#{Qtpay.gateway_url}#{path}")
|
64
130
|
uri.query = URI.encode_www_form(sign_params(params, options))
|
data/lib/qtpay/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qtpay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-12-
|
12
|
+
date: 2015-12-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -84,6 +84,7 @@ extra_rdoc_files: []
|
|
84
84
|
files:
|
85
85
|
- .gitignore
|
86
86
|
- Gemfile
|
87
|
+
- LICENSE
|
87
88
|
- lib/qtpay.rb
|
88
89
|
- lib/qtpay/service.rb
|
89
90
|
- lib/qtpay/sign.rb
|