wechat_payment 2.0.5 → 2.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/wechat_payment/payment_order.rb +2 -2
- data/app/models/wechat_payment/refund_order.rb +3 -3
- data/app/services/wechat_payment/service.rb +2 -2
- data/lib/wechat_payment/client.rb +7 -8
- data/lib/wechat_payment/concern/goods.rb +30 -16
- data/lib/wechat_payment/service_result.rb +25 -8
- data/lib/wechat_payment/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3acba715b3e59f36af2ae3bbec80a199773f262e07fc95fff8a3a8da7fd339c8
|
4
|
+
data.tar.gz: 84fb7b364df1ac7cae171a4fafa64a1f4396336471f2637a176154de110edb99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cfd511f056ecf1b79e87eaa2a1b8d0c8eda5f73449cb95b57dbaf12cca7ad9600cad2b9d6553782c665b6781de9ec50abe8f330d3983dfb39b0e1b1c77328d71
|
7
|
+
data.tar.gz: e78ecd5f76ad88e07696a6eb14ec8d558ee91306331a0de687d8fb18392407258ceddbc5d441ec4b336fe227302cb271a868edba42d07e7146645454b4bee2f0
|
@@ -17,7 +17,7 @@ module WechatPayment
|
|
17
17
|
pending_pay: "pending_pay",
|
18
18
|
refunded: "refunded",
|
19
19
|
failed: "failed"
|
20
|
-
}, _default: "
|
20
|
+
}, _default: "pending_pay"
|
21
21
|
|
22
22
|
# 将部分用户信息保存至订单
|
23
23
|
def set_customer_info
|
@@ -109,7 +109,7 @@ module WechatPayment
|
|
109
109
|
|
110
110
|
# 已退款的金额(包括正在退款的金额)
|
111
111
|
def refunded_fee
|
112
|
-
refund_orders.where(state: [:
|
112
|
+
refund_orders.where(state: [:pending_refund, :refunded]).sum(:refund_fee)
|
113
113
|
end
|
114
114
|
|
115
115
|
# 实际已退的金额
|
@@ -8,10 +8,10 @@ module WechatPayment
|
|
8
8
|
belongs_to :customer, polymorphic: true
|
9
9
|
|
10
10
|
enum state: {
|
11
|
-
|
11
|
+
pending_refund: "pending_refund",
|
12
12
|
refunded: "refunded",
|
13
13
|
failed: "failed"
|
14
|
-
}, _default:
|
14
|
+
}, _default: "pending_refund"
|
15
15
|
|
16
16
|
# 生成退款编号
|
17
17
|
def gen_out_refund_no
|
@@ -62,7 +62,7 @@ module WechatPayment
|
|
62
62
|
|
63
63
|
update(
|
64
64
|
refund_id: result["refund_id"],
|
65
|
-
state: :
|
65
|
+
state: :pending_refund
|
66
66
|
)
|
67
67
|
|
68
68
|
result
|
@@ -44,7 +44,7 @@ module WechatPayment
|
|
44
44
|
result = WechatPayment::Client.handle_payment_notify(notify_data)
|
45
45
|
payment_order = WechatPayment::PaymentOrder.find_by(out_trade_no: notify_data["out_trade_no"])
|
46
46
|
|
47
|
-
if result.success? && payment_order.
|
47
|
+
if result.success? && payment_order.pending_pay?
|
48
48
|
payment_order.with_lock do
|
49
49
|
payment_order.payment_exec_success(result.data)
|
50
50
|
end
|
@@ -60,7 +60,7 @@ module WechatPayment
|
|
60
60
|
result = WechatPayment::Client.handle_refund_notify(notify_data)
|
61
61
|
refund_order = WechatPayment::RefundOrder.find_by(out_refund_no: result.data["out_refund_no"])
|
62
62
|
|
63
|
-
if result.success? && refund_order.
|
63
|
+
if result.success? && refund_order.pending_refund?
|
64
64
|
refund_order.with_lock do
|
65
65
|
refund_order.refund_exec_success(result.data)
|
66
66
|
end
|
@@ -39,11 +39,10 @@ module WechatPayment
|
|
39
39
|
if order_result.success?
|
40
40
|
|
41
41
|
payment_logger.info("{params: #{order_params}, result: #{order_result}}")
|
42
|
-
# WechatPayment::ServiceResult.new(success: true, data: { order_result: order_result.with_indifferent_access, js_payload: mini_program_request_params.with_indifferent_access })
|
43
42
|
WechatPayment::ServiceResult.new(success: true, data: order_result.with_indifferent_access)
|
44
43
|
else
|
45
44
|
payment_logger.error("{params: #{order_params}, result: #{order_result}}")
|
46
|
-
WechatPayment::ServiceResult.new(success: false,
|
45
|
+
WechatPayment::ServiceResult.new(success: false, error: order_result.with_indifferent_access)
|
47
46
|
end
|
48
47
|
end
|
49
48
|
|
@@ -79,17 +78,17 @@ module WechatPayment
|
|
79
78
|
def self.handle_payment_notify(notify_data)
|
80
79
|
if !WechatPayment::Sign.verify?(notify_data)
|
81
80
|
payment_logger.error("{msg: 签名验证失败, errors: #{notify_data}}")
|
82
|
-
WechatPayment::ServiceResult.new(
|
81
|
+
WechatPayment::ServiceResult.new(success: false, error: notify_data, message: "回调签名验证失败")
|
83
82
|
end
|
84
83
|
|
85
84
|
result = WechatPayment::InvokeResult.new(notify_data)
|
86
85
|
|
87
86
|
if result.success?
|
88
87
|
payment_logger.info("{callback: #{notify_data}}")
|
89
|
-
WechatPayment::ServiceResult.new(success: true, data: notify_data)
|
88
|
+
WechatPayment::ServiceResult.new(success: true, data: notify_data, message: "支付执行成功", )
|
90
89
|
else
|
91
90
|
payment_logger.error("{callback: #{notify_data}}")
|
92
|
-
WechatPayment::ServiceResult.new(
|
91
|
+
WechatPayment::ServiceResult.new(success: false, error: notify_data, message: "支付执行失败", error_type: :payment_exec_failed)
|
93
92
|
end
|
94
93
|
end
|
95
94
|
|
@@ -99,11 +98,11 @@ module WechatPayment
|
|
99
98
|
|
100
99
|
result = WechatPayment::InvokeResult.new(notify_data)
|
101
100
|
if result.success?
|
102
|
-
refund_logger.info "{callback: #{notify_data}}"
|
101
|
+
refund_logger.info "退款执行成功{callback: #{notify_data}}"
|
103
102
|
WechatPayment::ServiceResult.new(success: true, data: notify_data)
|
104
103
|
else
|
105
|
-
refund_logger.error "{callback: #{notify_data}}"
|
106
|
-
WechatPayment::ServiceResult.new(
|
104
|
+
refund_logger.error "退款执行失败: {callback: #{notify_data}}"
|
105
|
+
WechatPayment::ServiceResult.new(success:false, error: notify_data, message: "退款回调失败")
|
107
106
|
end
|
108
107
|
end
|
109
108
|
|
@@ -32,38 +32,52 @@ module WechatPayment
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
|
35
|
+
user_goods_model = self.class.user_goods_model.constantize
|
36
|
+
|
37
|
+
user_goods = user_goods_model.new(
|
36
38
|
self.class.goods_ref_field => self,
|
37
39
|
self.class.user_ref_field => user,
|
38
40
|
**with_info,
|
39
41
|
**persist_goods_data,
|
40
42
|
)
|
41
43
|
|
42
|
-
user_goods.
|
44
|
+
unless user_goods.save
|
45
|
+
return WechatPayment::ServiceResult.new(success: false,
|
46
|
+
error: user_goods.errors,
|
47
|
+
message: "商品中间表 #{user_goods_model.table_name} 插入数据失败",
|
48
|
+
error_type: :create_user_goods_failed)
|
49
|
+
end
|
50
|
+
|
51
|
+
payment_order = user_goods.payment_orders.new(
|
43
52
|
body: name,
|
44
53
|
total_fee: price,
|
45
54
|
trade_type: :JSAPI,
|
46
55
|
customer: user
|
47
56
|
)
|
48
|
-
end
|
49
57
|
|
50
|
-
|
51
|
-
|
52
|
-
def repay
|
53
|
-
# 如果不是待支付状态
|
54
|
-
unless pending?
|
55
|
-
WechatPayment::ServiceResult.new(message: "当前状态不可支付")
|
58
|
+
unless payment_order.save
|
59
|
+
return WechatPayment::ServiceResult.new(success: false, error: user_goods.errors, message: "支付订单创建失败")
|
56
60
|
end
|
57
61
|
|
58
|
-
result = payment_orders.last.repay
|
59
|
-
|
60
|
-
if result.success?
|
61
|
-
WechatPayment::ServiceResult.new(success: true, data: result.data[:js_payload])
|
62
|
-
else
|
63
|
-
WechatPayment::ServiceResult.new(message: result.errors.first[:err_code_des])
|
64
|
-
end
|
65
62
|
end
|
66
63
|
|
64
|
+
# 重新支付,应用场景是: 用户取消了支付后,使用最后一张订单进行支付
|
65
|
+
# @return [WechatPayment::ServiceResult]
|
66
|
+
# def repay
|
67
|
+
# # 如果不是待支付状态
|
68
|
+
# unless pending?
|
69
|
+
# WechatPayment::ServiceResult.new(message: "当前状态不可支付")
|
70
|
+
# end
|
71
|
+
|
72
|
+
# result = payment_orders.last.repay
|
73
|
+
|
74
|
+
# if result.success?
|
75
|
+
# WechatPayment::ServiceResult.new(success: true, data: result.data[:js_payload])
|
76
|
+
# else
|
77
|
+
# WechatPayment::ServiceResult.new(message: result.errors.first[:err_code_des])
|
78
|
+
# end
|
79
|
+
# end
|
80
|
+
|
67
81
|
|
68
82
|
# 退款
|
69
83
|
# @param [Integer] refund_fee
|
@@ -1,19 +1,28 @@
|
|
1
1
|
module WechatPayment
|
2
2
|
class ServiceResult
|
3
3
|
attr_accessor :success,
|
4
|
-
:
|
4
|
+
:error,
|
5
5
|
:data,
|
6
6
|
:message,
|
7
|
-
:message_type
|
7
|
+
:message_type,
|
8
|
+
:error_type
|
8
9
|
|
9
10
|
def initialize(success: false,
|
10
|
-
|
11
|
+
error: nil,
|
11
12
|
message: nil,
|
12
13
|
message_type: nil,
|
13
|
-
data: nil
|
14
|
+
data: nil,
|
15
|
+
error_type)
|
14
16
|
self.success = success
|
15
|
-
|
16
|
-
self.
|
17
|
+
|
18
|
+
self.data = data.presence || {}
|
19
|
+
|
20
|
+
if self.data.is_a? Hash
|
21
|
+
self.data = self.data.with_indifferent_access
|
22
|
+
end
|
23
|
+
|
24
|
+
self.error = error
|
25
|
+
|
17
26
|
self.message = message
|
18
27
|
self.message_type = message_type
|
19
28
|
end
|
@@ -36,14 +45,22 @@ module WechatPayment
|
|
36
45
|
if message_type.present?
|
37
46
|
message_type.to_sym
|
38
47
|
elsif success?
|
39
|
-
:
|
48
|
+
:info
|
40
49
|
else
|
41
50
|
:error
|
42
51
|
end
|
43
52
|
end
|
44
53
|
|
45
54
|
def as_json(options = {})
|
46
|
-
data.as_json(options)
|
55
|
+
# data.as_json(options)
|
56
|
+
{
|
57
|
+
success: success,
|
58
|
+
data: data,
|
59
|
+
message: message,
|
60
|
+
message_type: get_message_type,
|
61
|
+
error: error,
|
62
|
+
error_type: error_type
|
63
|
+
}
|
47
64
|
end
|
48
65
|
end
|
49
66
|
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: 2.0.
|
4
|
+
version: 2.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-01-
|
11
|
+
date: 2022-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|