wechat_payment 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +215 -13
- data/Rakefile +5 -0
- data/app/assets/config/wechat_payment_manifest.js +1 -0
- data/app/assets/stylesheets/wechat_payment/application.css +15 -0
- data/app/controllers/wechat_payment/application_controller.rb +5 -0
- data/app/controllers/wechat_payment/callback_controller.rb +30 -0
- data/app/helpers/wechat_payment/application_helper.rb +4 -0
- data/app/jobs/wechat_payment/application_job.rb +4 -0
- data/app/mailers/wechat_payment/application_mailer.rb +6 -0
- data/app/models/wechat_payment/application_record.rb +5 -0
- data/app/models/wechat_payment/payment_order.rb +228 -0
- data/app/models/wechat_payment/refund_order.rb +127 -0
- data/app/services/wechat_payment/service.rb +74 -0
- data/app/views/layouts/wechat_payment/application.html.erb +15 -0
- data/config/routes.rb +4 -0
- data/db/migrate/20210706075217_create_wechat_payment_payment_orders.rb +22 -0
- data/db/migrate/20210706095205_create_wechat_payment_refund_orders.rb +20 -0
- data/lib/generators/wechat_payment/goods/USAGE +8 -0
- data/lib/generators/wechat_payment/goods/goods_generator.rb +5 -0
- data/lib/generators/wechat_payment/install/USAGE +8 -0
- data/lib/generators/wechat_payment/install/install_generator.rb +86 -0
- data/lib/generators/wechat_payment/install/templates/initializer.rb +19 -0
- data/lib/generators/wechat_payment/routes/USAGE +8 -0
- data/lib/generators/wechat_payment/routes/routes_generator.rb +7 -0
- data/lib/tasks/wechat_payment_tasks.rake +10 -0
- data/lib/wechat_payment.rb +40 -2
- data/lib/wechat_payment/client.rb +272 -0
- data/lib/wechat_payment/concern/goods.rb +80 -0
- data/lib/wechat_payment/concern/user.rb +22 -0
- data/lib/wechat_payment/concern/user_goods.rb +14 -0
- data/lib/wechat_payment/engine.rb +7 -0
- data/lib/wechat_payment/invoke_result.rb +35 -0
- data/lib/wechat_payment/missing_key_error.rb +4 -0
- data/lib/wechat_payment/r_logger.rb +36 -0
- data/lib/wechat_payment/service_result.rb +49 -0
- data/lib/wechat_payment/sign.rb +41 -0
- data/lib/wechat_payment/version.rb +1 -1
- metadata +68 -9
- data/lib/wechat_payment/railtie.rb +0 -4
@@ -0,0 +1,49 @@
|
|
1
|
+
module WechatPayment
|
2
|
+
class ServiceResult
|
3
|
+
attr_accessor :success,
|
4
|
+
:errors,
|
5
|
+
:data,
|
6
|
+
:message,
|
7
|
+
:message_type
|
8
|
+
|
9
|
+
def initialize(success: false,
|
10
|
+
errors: nil,
|
11
|
+
message: nil,
|
12
|
+
message_type: nil,
|
13
|
+
data: nil)
|
14
|
+
self.success = success
|
15
|
+
self.data = data
|
16
|
+
self.errors = errors.is_a?(Enumerable) ? errors : [errors]
|
17
|
+
self.message = message
|
18
|
+
self.message_type = message_type
|
19
|
+
end
|
20
|
+
|
21
|
+
alias success? :success
|
22
|
+
|
23
|
+
def failure?
|
24
|
+
!success?
|
25
|
+
end
|
26
|
+
|
27
|
+
def on_success
|
28
|
+
yield(self) if success?
|
29
|
+
end
|
30
|
+
|
31
|
+
def on_failure
|
32
|
+
yield(self) if failure?
|
33
|
+
end
|
34
|
+
|
35
|
+
def get_message_type
|
36
|
+
if message_type.present?
|
37
|
+
message_type.to_sym
|
38
|
+
elsif success?
|
39
|
+
:notice
|
40
|
+
else
|
41
|
+
:error
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def as_json(options = {})
|
46
|
+
data.as_json(options)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'digest/md5'
|
2
|
+
|
3
|
+
module WechatPayment
|
4
|
+
module Sign
|
5
|
+
|
6
|
+
SIGN_TYPE_MD5 = 'MD5'
|
7
|
+
SIGN_TYPE_HMAC_SHA256 = 'HMAC-SHA256'
|
8
|
+
|
9
|
+
def self.generate(params, sign_type = SIGN_TYPE_MD5)
|
10
|
+
key = params.delete(:key)
|
11
|
+
|
12
|
+
new_key = params["key"] #after
|
13
|
+
key = params.delete("key") if params["key"] #after
|
14
|
+
|
15
|
+
query = params.sort.map do |k, v|
|
16
|
+
"#{k}=#{v}" if v.to_s != ''
|
17
|
+
end.compact.join('&')
|
18
|
+
|
19
|
+
string_sign_temp = "#{query}&key=#{key || new_key || WechatPayment.key}" #after
|
20
|
+
|
21
|
+
if sign_type == SIGN_TYPE_MD5
|
22
|
+
Digest::MD5.hexdigest(string_sign_temp).upcase
|
23
|
+
elsif sign_type == SIGN_TYPE_HMAC_SHA256
|
24
|
+
OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), key, string_sign_temp).upcase
|
25
|
+
else
|
26
|
+
warn("WxPay Warn: unknown sign_type : #{sign_type}")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.verify?(params, options = {})
|
31
|
+
params = params.dup
|
32
|
+
params["appid"] = options[:appid] if options[:appid]
|
33
|
+
params["mch_id"] = options[:mch_id] if options[:mch_id]
|
34
|
+
params["key"] = options[:key] if options[:key]
|
35
|
+
|
36
|
+
sign = params.delete('sign') || params.delete(:sign)
|
37
|
+
|
38
|
+
generate(params, options[:sign_type] || SIGN_TYPE_MD5) == sign
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wechat_payment
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -24,7 +24,35 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 6.1.4
|
27
|
-
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: wx_pay
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rexml
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Description of WechatPayment.
|
28
56
|
email:
|
29
57
|
- ianlynxk@gmail.com
|
30
58
|
executables: []
|
@@ -34,17 +62,48 @@ files:
|
|
34
62
|
- MIT-LICENSE
|
35
63
|
- README.md
|
36
64
|
- Rakefile
|
65
|
+
- app/assets/config/wechat_payment_manifest.js
|
66
|
+
- app/assets/stylesheets/wechat_payment/application.css
|
67
|
+
- app/controllers/wechat_payment/application_controller.rb
|
68
|
+
- app/controllers/wechat_payment/callback_controller.rb
|
69
|
+
- app/helpers/wechat_payment/application_helper.rb
|
70
|
+
- app/jobs/wechat_payment/application_job.rb
|
71
|
+
- app/mailers/wechat_payment/application_mailer.rb
|
72
|
+
- app/models/wechat_payment/application_record.rb
|
73
|
+
- app/models/wechat_payment/payment_order.rb
|
74
|
+
- app/models/wechat_payment/refund_order.rb
|
75
|
+
- app/services/wechat_payment/service.rb
|
76
|
+
- app/views/layouts/wechat_payment/application.html.erb
|
77
|
+
- config/routes.rb
|
78
|
+
- db/migrate/20210706075217_create_wechat_payment_payment_orders.rb
|
79
|
+
- db/migrate/20210706095205_create_wechat_payment_refund_orders.rb
|
80
|
+
- lib/generators/wechat_payment/goods/USAGE
|
81
|
+
- lib/generators/wechat_payment/goods/goods_generator.rb
|
82
|
+
- lib/generators/wechat_payment/install/USAGE
|
83
|
+
- lib/generators/wechat_payment/install/install_generator.rb
|
84
|
+
- lib/generators/wechat_payment/install/templates/initializer.rb
|
85
|
+
- lib/generators/wechat_payment/routes/USAGE
|
86
|
+
- lib/generators/wechat_payment/routes/routes_generator.rb
|
37
87
|
- lib/tasks/wechat_payment_tasks.rake
|
38
88
|
- lib/wechat_payment.rb
|
39
|
-
- lib/wechat_payment/
|
89
|
+
- lib/wechat_payment/client.rb
|
90
|
+
- lib/wechat_payment/concern/goods.rb
|
91
|
+
- lib/wechat_payment/concern/user.rb
|
92
|
+
- lib/wechat_payment/concern/user_goods.rb
|
93
|
+
- lib/wechat_payment/engine.rb
|
94
|
+
- lib/wechat_payment/invoke_result.rb
|
95
|
+
- lib/wechat_payment/missing_key_error.rb
|
96
|
+
- lib/wechat_payment/r_logger.rb
|
97
|
+
- lib/wechat_payment/service_result.rb
|
98
|
+
- lib/wechat_payment/sign.rb
|
40
99
|
- lib/wechat_payment/version.rb
|
41
|
-
homepage: https://
|
100
|
+
homepage: https://github.com/bkyz/wechat_payment
|
42
101
|
licenses:
|
43
102
|
- MIT
|
44
103
|
metadata:
|
45
|
-
homepage_uri: https://
|
46
|
-
source_code_uri: https://github.com/
|
47
|
-
changelog_uri: https://github.com/
|
104
|
+
homepage_uri: https://github.com/bkyz/wechat_payment
|
105
|
+
source_code_uri: https://github.com/bkyz/wechat_payment
|
106
|
+
changelog_uri: https://github.com/bkyz/wechat_payment/CHANGELOG.md
|
48
107
|
post_install_message:
|
49
108
|
rdoc_options: []
|
50
109
|
require_paths:
|
@@ -63,5 +122,5 @@ requirements: []
|
|
63
122
|
rubygems_version: 3.2.15
|
64
123
|
signing_key:
|
65
124
|
specification_version: 4
|
66
|
-
summary:
|
125
|
+
summary: Summary of WechatPayment.
|
67
126
|
test_files: []
|