wechat_payment 1.0.1 → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2100fe24861a1d75ca04e949abd877f1103264cb81d14d95a4f19b53063d34fc
4
- data.tar.gz: 2350aab94044a8ad51625c078dc462a9bfa8905c1f2365b6b3c330ab003035ff
3
+ metadata.gz: e310951e27fb21bc10f6f7c014d311dbef25b86229fb13c7f509e2670173185d
4
+ data.tar.gz: f8385506631a6d621ad60a81cf3a7eca42bdfb27f811765e3b2c850fb97cde0a
5
5
  SHA512:
6
- metadata.gz: ee743747eada08f87dd41e74e36b3032dc1230dedbb9c8cd0fb0a02369ff5afb596e5ec362f39f991602d34bb1e7920abb30277889c6c0687ab80c4388475b07
7
- data.tar.gz: '094f7231dc3225b4d3c66b7f5bc596d3cf1a8c005230701afdee104a6c952e5e20341987ad483663d4405abf3271c934d9456b7a3ac2dd2528652b56149bbc5b'
6
+ metadata.gz: 2e7ad1adc3f4e8cc1b720cc8cc78986320e76638ae66518657c0bf844dd21facc1e3bd83c65a1421b491780e2ccc2a33d19935a1279623da64bbce69c70f21cf
7
+ data.tar.gz: b97d318c5628de5eeeb183f9a1dbb4dc37ba0a210534f302ba1c9e1c2e7950ed7208c1e2db9b91d12cbb4f12d60e6ffe4f573fc123a8fcb8469bd06bb69fa64a
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
 
5
5
  ## Convention
6
- 在使用该 Engine 之前,需要先建立`用户模型`,`商品模型`,`用户商品关联模型`,用户表需要有 open_id 字段,
6
+ 在使用该 Engine 之前,需要先建立`用户模型`,`商品模型`,`用户商品关联模型`,用户表需要有 openid 字段,
7
7
  商品表需要有 price 和 name 字段。假设`商品模型`为`Product`,则用户和商品之间的关联模型为`UserProduct`,
8
8
  关联模型属于`user`和`product`。
9
9
 
@@ -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
@@ -21,7 +21,7 @@ module WechatPayment
21
21
 
22
22
  # 将部分用户信息保存至订单
23
23
  def set_customer_info
24
- self.open_id = customer.open_id if open_id.blank?
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: open_id
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 :open_id
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, :open_id
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
- **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 = '1.0.1'
2
+ VERSION = '2.0.4'
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: 1.0.1
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-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