wechat_payment 2.0.6 → 2.0.10
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8712e877d54c4964bc93daf8e3fa4df1bc57cbc794811cbfbf096661297d68ec
|
4
|
+
data.tar.gz: '0878c15e6c7a6b13a8aff61753bf87c31328d0d3686d5b3900ac0e5c199a2589'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4cafd39213ccee668a34e2650699663444d1df8d627e070f87e30e8a24433a695f0c2b638d135867e6bfb40dcf4e626c0110017662d429d9943ef54933683cf8
|
7
|
+
data.tar.gz: ade54ef7701156d7fa899df557d1b5b3333693790ff03d117462eea1d94b524bee9841d3ade7d51b70d10a03a00df27a129032bd519219ff7d892054d4658228
|
@@ -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,53 @@ 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
|
-
|
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
|
62
|
+
WechatPayment::ServiceResult.new(success: true, data: payment_order, message: "支付订单创建成功")
|
65
63
|
end
|
66
64
|
|
65
|
+
# 重新支付,应用场景是: 用户取消了支付后,使用最后一张订单进行支付
|
66
|
+
# @return [WechatPayment::ServiceResult]
|
67
|
+
# def repay
|
68
|
+
# # 如果不是待支付状态
|
69
|
+
# unless pending?
|
70
|
+
# WechatPayment::ServiceResult.new(message: "当前状态不可支付")
|
71
|
+
# end
|
72
|
+
|
73
|
+
# result = payment_orders.last.repay
|
74
|
+
|
75
|
+
# if result.success?
|
76
|
+
# WechatPayment::ServiceResult.new(success: true, data: result.data[:js_payload])
|
77
|
+
# else
|
78
|
+
# WechatPayment::ServiceResult.new(message: result.errors.first[:err_code_des])
|
79
|
+
# end
|
80
|
+
# end
|
81
|
+
|
67
82
|
|
68
83
|
# 退款
|
69
84
|
# @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: nil)
|
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.10
|
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
|