wechat_payment 2.0.1 → 2.0.5

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: b44bb7536575ad7bc8160b621db67776152c256c0bfe9ef3ea3b5b538097385f
4
- data.tar.gz: 6c5b38ea0075671aaabe84294ed3bacbfe2d7dbfeff5eb7f7dc05a53b8f8814a
3
+ metadata.gz: 6a2f9d7deaaaed1d3b98076b2f01e2c8f3717ec1523e036324c5a479c5cc5385
4
+ data.tar.gz: 38e2e94679a07a1128aa1b88111b54c43dea2614aa8ead79808c8beb882421ab
5
5
  SHA512:
6
- metadata.gz: 56c0da01b6bc6d44076616ea80cad48deb6bd68372743aff0b5defccb0394edc4f0990f814d21c698e4d763fe2a0a4a14260da153685526e326a38e5bbc89786
7
- data.tar.gz: cae818ffdb7fa29099a1d1565b2c8e29a76f1d019ad8bf097d75ee3992c8b01e54a9d80e66a45e8af9d04511eeb17fc1202279a18a56d5fe68df9d34e6964e27
6
+ metadata.gz: ec536f1580a1ce147f0892a0c90c3f696929dc5ad1f6cfbef1ddd8b25df65c3e9ecf31fef578054e952d385995734d59bc59fbdbe17f195f7c4bd6d04286fc59
7
+ data.tar.gz: 73988c1100320edfab0babc54a144e96067b9a13212c1ef3253e7186c3c54cfab6dd860d33d6f0ddbc490d2a29c0d8280071f994672ca8c8537c70741af53ba1
@@ -1,7 +1,9 @@
1
1
 
2
2
  class PaymentOrdersController < ApplicationController
3
3
  def index
4
+ @payment_orders = WechatPayment::PaymentOrder.by_state(params[:state])
4
5
 
6
+ render json: @payment_orders
5
7
  end
6
8
 
7
9
  end
@@ -14,7 +14,7 @@ module WechatPayment
14
14
 
15
15
  enum state: {
16
16
  paid: "paid",
17
- pending: "pending",
17
+ pending_pay: "pending_pay",
18
18
  refunded: "refunded",
19
19
  failed: "failed"
20
20
  }, _default: "pending"
@@ -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
@@ -14,6 +14,7 @@ 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
@@ -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
- **persist_goods_data
38
+ **with_info,
39
+ **persist_goods_data,
40
40
  )
41
41
 
42
42
  user_goods.payment_orders.create(
@@ -14,8 +14,8 @@ module WechatPayment
14
14
  end
15
15
  end
16
16
 
17
- def buy(goods)
18
- goods.sell_to(me)
17
+ def buy(goods, with_info = {})
18
+ goods.sell_to(me, with_info)
19
19
  end
20
20
  end
21
21
  end
@@ -1,3 +1,3 @@
1
1
  module WechatPayment
2
- VERSION = '2.0.1'
2
+ VERSION = '2.0.5'
3
3
  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.1
4
+ version: 2.0.5
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-18 00:00:00.000000000 Z
11
+ date: 2022-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails