wechat_payment 1.0.0 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/app/controllers/wechat_payment/payment_orders_controller.rb +9 -0
- data/app/models/wechat_payment/payment_order.rb +15 -3
- 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 +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ccc823e0ae167b60ffa78ba54e98c559c95c0019167a3c2e5033db6718f741b
|
4
|
+
data.tar.gz: 68e1de8aa02ac29ebc7d6012173dfdaa0162c493dbcb08f36e55db7909ef38b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6dc4007ff8cbdd1cc8d347ed4d9193e43cddcf683192dae186ecf2b1f4511ce288acf40cffa6f10c66268382fb140f65d984ed9539a27388d6c258022f9c8b3b
|
7
|
+
data.tar.gz: 7655b449f9e31b5e481b174648ee6019753607addceb45ee0e4e848ce0d3aec11da6ddf1007694c80a51a005c817a3c927f910b3c95310830209ed1e05201d52
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
|
5
5
|
## Convention
|
6
|
-
在使用该 Engine 之前,需要先建立`用户模型`,`商品模型`,`用户商品关联模型`,用户表需要有
|
6
|
+
在使用该 Engine 之前,需要先建立`用户模型`,`商品模型`,`用户商品关联模型`,用户表需要有 openid 字段,
|
7
7
|
商品表需要有 price 和 name 字段。假设`商品模型`为`Product`,则用户和商品之间的关联模型为`UserProduct`,
|
8
8
|
关联模型属于`user`和`product`。
|
9
9
|
|
@@ -17,8 +17,8 @@
|
|
17
17
|
|
18
18
|
3. 初始化
|
19
19
|
```bash
|
20
|
-
# rails g wechat_payment:install [GoodsModel] [UserModel]
|
21
|
-
$ rails g wechat_payment:install Product User
|
20
|
+
# rails g wechat_payment:install [GoodsModel] [UserGoodRelationModel] [UserModel]
|
21
|
+
$ rails g wechat_payment:install Product UserProduct User
|
22
22
|
$ rails db:migrate
|
23
23
|
```
|
24
24
|
|
@@ -227,4 +227,4 @@ TODO 待补充
|
|
227
227
|
Contribution directions go here.
|
228
228
|
|
229
229
|
## License
|
230
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
230
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -8,6 +8,10 @@ module WechatPayment
|
|
8
8
|
before_create :gen_out_trade_no
|
9
9
|
belongs_to :goods, polymorphic: true
|
10
10
|
|
11
|
+
scope :by_state, ->(state)do
|
12
|
+
where(state: state) if state.present?
|
13
|
+
end
|
14
|
+
|
11
15
|
enum state: {
|
12
16
|
paid: "paid",
|
13
17
|
pending: "pending",
|
@@ -17,7 +21,7 @@ module WechatPayment
|
|
17
21
|
|
18
22
|
# 将部分用户信息保存至订单
|
19
23
|
def set_customer_info
|
20
|
-
self.
|
24
|
+
self.openid = customer.openid if openid.blank?
|
21
25
|
self.spbill_create_ip = customer.spbill_create_ip
|
22
26
|
end
|
23
27
|
|
@@ -50,7 +54,7 @@ module WechatPayment
|
|
50
54
|
spbill_create_ip: spbill_create_ip,
|
51
55
|
total_fee: total_fee,
|
52
56
|
body: body,
|
53
|
-
openid:
|
57
|
+
openid: openid
|
54
58
|
}
|
55
59
|
end
|
56
60
|
|
@@ -69,9 +73,16 @@ module WechatPayment
|
|
69
73
|
# "orderId": 17
|
70
74
|
# }
|
71
75
|
def pay
|
76
|
+
if payment_params.present?
|
77
|
+
return ServiceResult.new(success: true, data: payment_params, message: "获取支付参数成功")
|
78
|
+
end
|
79
|
+
|
72
80
|
order_result = WechatPayment::Service.new(self).order
|
73
81
|
if order_result.success?
|
74
82
|
payload = WechatPayment::Client.gen_js_pay_payload(order_result.data).merge(orderId: id).with_indifferent_access
|
83
|
+
|
84
|
+
update(payment_params: payload)
|
85
|
+
|
75
86
|
WechatPayment::ServiceResult.new(success: true, data: payload)
|
76
87
|
else
|
77
88
|
order_result
|
@@ -199,7 +210,8 @@ module WechatPayment
|
|
199
210
|
update(
|
200
211
|
state: :paid,
|
201
212
|
transaction_id: result["transaction_id"],
|
202
|
-
paid_at: Time.current
|
213
|
+
paid_at: Time.current,
|
214
|
+
payment_params: nil
|
203
215
|
)
|
204
216
|
|
205
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.3
|
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
|
@@ -66,6 +66,7 @@ files:
|
|
66
66
|
- app/assets/stylesheets/wechat_payment/application.css
|
67
67
|
- app/controllers/wechat_payment/application_controller.rb
|
68
68
|
- app/controllers/wechat_payment/callback_controller.rb
|
69
|
+
- app/controllers/wechat_payment/payment_orders_controller.rb
|
69
70
|
- app/helpers/wechat_payment/application_helper.rb
|
70
71
|
- app/jobs/wechat_payment/application_job.rb
|
71
72
|
- app/mailers/wechat_payment/application_mailer.rb
|