wechat_payment 1.0.1 → 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/app/controllers/wechat_payment/payment_orders_controller.rb +2 -0
- data/app/models/wechat_payment/payment_order.rb +13 -5
- data/db/migrate/20210706075217_create_wechat_payment_payment_orders.rb +3 -2
- data/lib/wechat_payment/concern/goods.rb +3 -3
- data/lib/wechat_payment/concern/user.rb +2 -2
- 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: e310951e27fb21bc10f6f7c014d311dbef25b86229fb13c7f509e2670173185d
|
4
|
+
data.tar.gz: f8385506631a6d621ad60a81cf3a7eca42bdfb27f811765e3b2c850fb97cde0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e7ad1adc3f4e8cc1b720cc8cc78986320e76638ae66518657c0bf844dd21facc1e3bd83c65a1421b491780e2ccc2a33d19935a1279623da64bbce69c70f21cf
|
7
|
+
data.tar.gz: b97d318c5628de5eeeb183f9a1dbb4dc37ba0a210534f302ba1c9e1c2e7950ed7208c1e2db9b91d12cbb4f12d60e6ffe4f573fc123a8fcb8469bd06bb69fa64a
|
data/README.md
CHANGED
@@ -21,7 +21,7 @@ module WechatPayment
|
|
21
21
|
|
22
22
|
# 将部分用户信息保存至订单
|
23
23
|
def set_customer_info
|
24
|
-
self.
|
24
|
+
self.openid = customer.openid if openid.blank?
|
25
25
|
self.spbill_create_ip = customer.spbill_create_ip
|
26
26
|
end
|
27
27
|
|
@@ -54,7 +54,7 @@ module WechatPayment
|
|
54
54
|
spbill_create_ip: spbill_create_ip,
|
55
55
|
total_fee: total_fee,
|
56
56
|
body: body,
|
57
|
-
openid:
|
57
|
+
openid: openid
|
58
58
|
}
|
59
59
|
end
|
60
60
|
|
@@ -72,10 +72,17 @@ module WechatPayment
|
|
72
72
|
# "paySign": "1F5CBC345B86E5DD055F235A22961422",
|
73
73
|
# "orderId": 17
|
74
74
|
# }
|
75
|
-
def pay
|
75
|
+
def pay(repay: false)
|
76
|
+
if payment_params.present? && !repay
|
77
|
+
return ServiceResult.new(success: true, data: payment_params, message: "获取支付参数成功")
|
78
|
+
end
|
79
|
+
|
76
80
|
order_result = WechatPayment::Service.new(self).order
|
77
81
|
if order_result.success?
|
78
82
|
payload = WechatPayment::Client.gen_js_pay_payload(order_result.data).merge(orderId: id).with_indifferent_access
|
83
|
+
|
84
|
+
update(payment_params: payload)
|
85
|
+
|
79
86
|
WechatPayment::ServiceResult.new(success: true, data: payload)
|
80
87
|
else
|
81
88
|
order_result
|
@@ -86,7 +93,7 @@ module WechatPayment
|
|
86
93
|
def repay
|
87
94
|
gen_out_trade_no
|
88
95
|
save
|
89
|
-
pay
|
96
|
+
pay(repay: true)
|
90
97
|
end
|
91
98
|
|
92
99
|
# 发起退款
|
@@ -203,7 +210,8 @@ module WechatPayment
|
|
203
210
|
update(
|
204
211
|
state: :paid,
|
205
212
|
transaction_id: result["transaction_id"],
|
206
|
-
paid_at: Time.current
|
213
|
+
paid_at: Time.current,
|
214
|
+
payment_params: nil
|
207
215
|
)
|
208
216
|
|
209
217
|
if goods.respond_to? :payment_exec_success
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class CreateWechatPaymentPaymentOrders < ActiveRecord::Migration[6.1]
|
2
2
|
def change
|
3
3
|
create_table :wechat_payment_payment_orders do |t|
|
4
|
-
t.string :
|
4
|
+
t.string :openid
|
5
5
|
t.string :out_trade_no
|
6
6
|
t.references :goods, polymorphic: true, null: false
|
7
7
|
t.references :customer, polymorphic: true, null: false
|
@@ -14,9 +14,10 @@ class CreateWechatPaymentPaymentOrders < ActiveRecord::Migration[6.1]
|
|
14
14
|
t.string :state
|
15
15
|
t.datetime :paid_at
|
16
16
|
t.datetime :refunded_at
|
17
|
+
t.jsonb :payment_params
|
17
18
|
|
18
19
|
t.timestamps
|
19
20
|
end
|
20
|
-
add_index :wechat_payment_payment_orders, :
|
21
|
+
add_index :wechat_payment_payment_orders, :openid
|
21
22
|
end
|
22
23
|
end
|
@@ -25,8 +25,7 @@ module WechatPayment
|
|
25
25
|
# 售出
|
26
26
|
# @param [User] user
|
27
27
|
# @return [WechatPaymentOrder]
|
28
|
-
def sell_to(user)
|
29
|
-
|
28
|
+
def sell_to(user, with_info = {})
|
30
29
|
persist_goods_data = {}.tap do |h|
|
31
30
|
self.class.persist_goods_attrs.each do |attr|
|
32
31
|
h[attr] = send(attr)
|
@@ -36,7 +35,8 @@ module WechatPayment
|
|
36
35
|
user_goods = self.class.user_goods_model.constantize.create(
|
37
36
|
self.class.goods_ref_field => self,
|
38
37
|
self.class.user_ref_field => user,
|
39
|
-
**
|
38
|
+
**with_info,
|
39
|
+
**persist_goods_data,
|
40
40
|
)
|
41
41
|
|
42
42
|
user_goods.payment_orders.create(
|
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:
|
4
|
+
version: 2.0.4
|
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-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|