wechat_payment 2.0.2 → 2.0.6

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: c61c4ab32413e5389896bde1f772149d3df02e74c4cdcd76973ed942c6e25009
4
- data.tar.gz: b5d53616d2f40fa7c112ca57319f5d4c29606053ae291fb09aee8a8280674ea5
3
+ metadata.gz: 4c408e5bd232b6b23b55c5bff7f77dfe85d914cd5944df0939b43eb2491a1864
4
+ data.tar.gz: 55c60366e4261ea7f89cd6d23c1008226e1042c6531ea1dcdabc6c00b66e95b3
5
5
  SHA512:
6
- metadata.gz: 9265a884ffd5b9a544644400bac0e2c89c75b87803fb95d9542e8e0cbfce76c8688928b9aad3aeaf54c67b261a0c7cb99d0f2021a749a7207cd4a35a40380c0c
7
- data.tar.gz: 95e24b9a3941112ad5698a3cbbdf313c38f4755d0a2ecc0dcaca0c2ce4ddf62b4045bddac81b7fcdf24b394a4ede23d512b5db232436975f0165c60c08490df8
6
+ metadata.gz: 79cac1d0f255db96a6b794410801753025f32911808bcc03df2297f943f626282ff40eb1a7bd164c4feb3166ebd0519dc9c18660517b0fe91f6e6cb4545ee6e5
7
+ data.tar.gz: a22ceb04e1a5207698c7acbe02252a667c9b2b7c6a85af9cbdc25c3ff1a61cf100e33a364c2a6fe36c5f1c700aa5f54ac40c7750bff304f32efa6978c4468293
@@ -14,10 +14,10 @@ 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
- }, _default: "pending"
20
+ }, _default: "pending_pay"
21
21
 
22
22
  # 将部分用户信息保存至订单
23
23
  def set_customer_info
@@ -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
  # 发起退款
@@ -102,7 +109,7 @@ module WechatPayment
102
109
 
103
110
  # 已退款的金额(包括正在退款的金额)
104
111
  def refunded_fee
105
- refund_orders.where(state: [:pending, :refunded]).sum(:refund_fee)
112
+ refund_orders.where(state: [:pending_refund, :refunded]).sum(:refund_fee)
106
113
  end
107
114
 
108
115
  # 实际已退的金额
@@ -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
@@ -8,10 +8,10 @@ module WechatPayment
8
8
  belongs_to :customer, polymorphic: true
9
9
 
10
10
  enum state: {
11
- pending: "pending",
11
+ pending_refund: "pending_refund",
12
12
  refunded: "refunded",
13
13
  failed: "failed"
14
- }, _default: :pending
14
+ }, _default: "pending_refund"
15
15
 
16
16
  # 生成退款编号
17
17
  def gen_out_refund_no
@@ -62,7 +62,7 @@ module WechatPayment
62
62
 
63
63
  update(
64
64
  refund_id: result["refund_id"],
65
- state: :pending
65
+ state: :pending_refund
66
66
  )
67
67
 
68
68
  result
@@ -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
@@ -1,3 +1,3 @@
1
1
  module WechatPayment
2
- VERSION = '2.0.2'
2
+ VERSION = '2.0.6'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wechat_payment
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - ian