oak-pay-business 2.5.1 → 2.5.2

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.
@@ -1,69 +1,69 @@
1
- .card {
2
- width: 100%;
3
-
4
- .content {
5
- display: flex;
6
- flex-direction: column;
7
- align-items: stretch;
8
-
9
-
10
- .oper {
11
- align-self: center;
12
- width: 70%;
13
- margin-bottom: 28px;
14
- display: flex;
15
- flex-direction: column;
16
- align-items: stretch;
17
-
18
- .title {
19
- margin-bottom: 28px;
20
- align-self: flex-start;
21
- color: var(--oak-color-primary3);
22
- font-size: var(--oak-font-size-title-medium);
23
- }
24
- }
25
- }
26
- }
27
-
28
- .grid {
29
- min-width: 133px;
30
- border-radius: 6px;
31
- padding: 16px;
32
- display: flex;
33
- flex-direction: column;
34
- margin: 13px;
35
-
36
- .label {
37
- font-size: 16px;
38
- font-weight: 400;
39
- color: var(--oak-color-primary);
40
- margin-bottom: 12px;
41
- }
42
-
43
- .value {
44
- font-size: 24px;
45
- font-weight: 600;
46
- color: var(--oak-color-primary);
47
- line-height: 33.6px;
48
- }
49
- }
50
-
51
- .fortify {
52
- background-color: var(--oak-color-primary-light);
53
-
54
- .label {
55
- font-weight: 900;
56
- }
57
-
58
- .value {
59
- font-weight: bolder;
60
- }
61
- }
62
-
63
- .uf {
64
- margin: 12px;
65
- display: flex;
66
- flex-direction: column;
67
- align-items: center;
68
- padding: 12px;
1
+ .card {
2
+ width: 100%;
3
+
4
+ .content {
5
+ display: flex;
6
+ flex-direction: column;
7
+ align-items: stretch;
8
+
9
+
10
+ .oper {
11
+ align-self: center;
12
+ width: 70%;
13
+ margin-bottom: 28px;
14
+ display: flex;
15
+ flex-direction: column;
16
+ align-items: stretch;
17
+
18
+ .title {
19
+ margin-bottom: 28px;
20
+ align-self: flex-start;
21
+ color: var(--oak-color-primary3);
22
+ font-size: var(--oak-font-size-title-medium);
23
+ }
24
+ }
25
+ }
26
+ }
27
+
28
+ .grid {
29
+ min-width: 133px;
30
+ border-radius: 6px;
31
+ padding: 16px;
32
+ display: flex;
33
+ flex-direction: column;
34
+ margin: 13px;
35
+
36
+ .label {
37
+ font-size: 16px;
38
+ font-weight: 400;
39
+ color: var(--oak-color-primary);
40
+ margin-bottom: 12px;
41
+ }
42
+
43
+ .value {
44
+ font-size: 24px;
45
+ font-weight: 600;
46
+ color: var(--oak-color-primary);
47
+ line-height: 33.6px;
48
+ }
49
+ }
50
+
51
+ .fortify {
52
+ background-color: var(--oak-color-primary-light);
53
+
54
+ .label {
55
+ font-weight: 900;
56
+ }
57
+
58
+ .value {
59
+ font-weight: bolder;
60
+ }
61
+ }
62
+
63
+ .uf {
64
+ margin: 12px;
65
+ display: flex;
66
+ flex-direction: column;
67
+ align-items: center;
68
+ padding: 12px;
69
69
  }
@@ -1,11 +1,11 @@
1
1
  import Styles from './info.module.less';
2
2
  export default function Info(props) {
3
3
  const { price, t } = props;
4
- return (<div className={Styles.info}>
5
- <div className={Styles.should}>{t('price')}</div>
6
- <div className={Styles.price}>
7
- <div>{t('common::pay.symbol')}</div>
8
- <div>{price}</div>
9
- </div>
4
+ return (<div className={Styles.info}>
5
+ <div className={Styles.should}>{t('price')}</div>
6
+ <div className={Styles.price}>
7
+ <div>{t('common::pay.symbol')}</div>
8
+ <div>{price}</div>
9
+ </div>
10
10
  </div>);
11
11
  }
@@ -1,25 +1,25 @@
1
-
2
- .info {
3
- margin: 8px;
4
- height: 140px;
5
- display: flex;
6
- flex-direction: column;
7
- align-items: center;
8
- justify-content: center;
9
- background-color: var(--oak-color-info);
10
-
11
- .should {
12
- font-size: large;
13
- font-weight: bold;
14
- }
15
-
16
- .price {
17
- display: flex;
18
- flex-direction: row;
19
- padding: 3px;
20
- font-size: xx-large;
21
- font-weight: bolder;
22
- color: var(--oak-color-primary);
23
- align-items: baseline;
24
- }
1
+
2
+ .info {
3
+ margin: 8px;
4
+ height: 140px;
5
+ display: flex;
6
+ flex-direction: column;
7
+ align-items: center;
8
+ justify-content: center;
9
+ background-color: var(--oak-color-info);
10
+
11
+ .should {
12
+ font-size: large;
13
+ font-weight: bold;
14
+ }
15
+
16
+ .price {
17
+ display: flex;
18
+ flex-direction: row;
19
+ padding: 3px;
20
+ font-size: xx-large;
21
+ font-weight: bolder;
22
+ color: var(--oak-color-primary);
23
+ align-items: baseline;
24
+ }
25
25
  }
@@ -1,36 +1,36 @@
1
- .container {
2
- width: 100%;
3
- height: 100%;
4
- display: flex;
5
- flex-direction: column;
6
- align-items: stretch;
7
- background-color: var(--oak-bg-color-page);
8
- // min-height: 500px;
9
-
10
- .ctrl {
11
- margin: 8px;
12
- margin-top: 10px;
13
- flex: 1;
14
-
15
- .pc1 {
16
- width: 100%;
17
- height: 100%;
18
- display: flex;
19
- flex-direction: column;
20
- margin-top: 4px;
21
-
22
- .content {
23
- background-color: var(--oak-bg-color-container);
24
- padding: 4px;
25
- border-radius: 2px;
26
- padding: 16px;
27
-
28
- .tips {
29
- color: var(--oak-color-warning);
30
- font-size: small;
31
- margin-top: 3px;
32
- }
33
- }
34
- }
35
- }
1
+ .container {
2
+ width: 100%;
3
+ height: 100%;
4
+ display: flex;
5
+ flex-direction: column;
6
+ align-items: stretch;
7
+ background-color: var(--oak-bg-color-page);
8
+ // min-height: 500px;
9
+
10
+ .ctrl {
11
+ margin: 8px;
12
+ margin-top: 10px;
13
+ flex: 1;
14
+
15
+ .pc1 {
16
+ width: 100%;
17
+ height: 100%;
18
+ display: flex;
19
+ flex-direction: column;
20
+ margin-top: 4px;
21
+
22
+ .content {
23
+ background-color: var(--oak-bg-color-container);
24
+ padding: 4px;
25
+ border-radius: 2px;
26
+ padding: 16px;
27
+
28
+ .tips {
29
+ color: var(--oak-color-warning);
30
+ font-size: small;
31
+ margin-top: 3px;
32
+ }
33
+ }
34
+ }
35
+ }
36
36
  }
@@ -1,36 +1,36 @@
1
- .container {
2
- width: 100%;
3
- height: 100%;
4
- display: flex;
5
- flex-direction: column;
6
- align-items: stretch;
7
- background-color: var(--oak-bg-color-page);
8
- // min-height: 500px;
9
-
10
- .ctrl {
11
- margin: 8px;
12
- margin-top: 10px;
13
- flex: 1;
14
-
15
- .pc1 {
16
- width: 100%;
17
- height: 100%;
18
- display: flex;
19
- flex-direction: column;
20
- margin-top: 4px;
21
-
22
- .content {
23
- background-color: var(--oak-bg-color-container);
24
- padding: 4px;
25
- border-radius: 2px;
26
- padding: 16px;
27
-
28
- .tips {
29
- color: var(--oak-color-warning);
30
- font-size: small;
31
- margin-left: 10px;
32
- }
33
- }
34
- }
35
- }
1
+ .container {
2
+ width: 100%;
3
+ height: 100%;
4
+ display: flex;
5
+ flex-direction: column;
6
+ align-items: stretch;
7
+ background-color: var(--oak-bg-color-page);
8
+ // min-height: 500px;
9
+
10
+ .ctrl {
11
+ margin: 8px;
12
+ margin-top: 10px;
13
+ flex: 1;
14
+
15
+ .pc1 {
16
+ width: 100%;
17
+ height: 100%;
18
+ display: flex;
19
+ flex-direction: column;
20
+ margin-top: 4px;
21
+
22
+ .content {
23
+ background-color: var(--oak-bg-color-container);
24
+ padding: 4px;
25
+ border-radius: 2px;
26
+ padding: 16px;
27
+
28
+ .tips {
29
+ color: var(--oak-color-warning);
30
+ font-size: small;
31
+ margin-left: 10px;
32
+ }
33
+ }
34
+ }
35
+ }
36
36
  }
@@ -1,5 +1,5 @@
1
- .container {
2
- display: flex;
3
- flex-direction: column;
4
- width: 100%;
1
+ .container {
2
+ display: flex;
3
+ flex-direction: column;
4
+ width: 100%;
5
5
  }
@@ -1,11 +1,11 @@
1
- .empty {
2
- min-height: 600px;
3
- }
4
-
5
- .container {
6
- width: 100%;
7
- display: flex;
8
- flex-direction: column;
9
- align-items: center;
10
- justify-content: center;
1
+ .empty {
2
+ min-height: 600px;
3
+ }
4
+
5
+ .container {
6
+ width: 100%;
7
+ display: flex;
8
+ flex-direction: column;
9
+ align-items: center;
10
+ justify-content: center;
11
11
  }
@@ -44,7 +44,7 @@ const attrUpdateMatrix = {
44
44
  actions: ['refundPartially', 'refundAll'],
45
45
  },
46
46
  refundable: {
47
- actions: ['succeedPaying', 'closeRefund'],
47
+ actions: ['succeedPaying', 'closeRefund', 'stopRefunding', 'refundPartially'],
48
48
  },
49
49
  forbidRefundAt: {
50
50
  actions: ['succeedPaying'],
package/es/data/i18n.js CHANGED
@@ -798,7 +798,9 @@ const i18ns = [
798
798
  },
799
799
  "refund": {
800
800
  "create": {
801
- "hasAnotherRefunding": "您有一笔退款正在进行中"
801
+ "hasAnotherRefunding": "您有一笔退款正在进行中",
802
+ "exceedMax": "退款额度大于可用值",
803
+ "payUnrefundable": "支付已经不可退款"
802
804
  }
803
805
  }
804
806
  }
@@ -19,7 +19,9 @@
19
19
  },
20
20
  "refund": {
21
21
  "create": {
22
- "hasAnotherRefunding": "您有一笔退款正在进行中"
22
+ "hasAnotherRefunding": "您有一笔退款正在进行中",
23
+ "exceedMax": "退款额度大于可用值",
24
+ "payUnrefundable": "支付已经不可退款"
23
25
  }
24
26
  }
25
27
  }
@@ -44,8 +44,7 @@ async function changeOrderStateByPay(filter, context, option) {
44
44
  break;
45
45
  }
46
46
  }
47
- if (paid && iState === 'paid') {
48
- //已支付完成的订单的paid
47
+ if (paid) { //对iState是否为paid的判断会影响退款,先去掉
49
48
  payPaid += paid;
50
49
  }
51
50
  if (refunded) {
@@ -72,7 +71,7 @@ async function changeOrderStateByPay(filter, context, option) {
72
71
  }
73
72
  }
74
73
  else if (hasRefunding) {
75
- assert(!hasPaying && payPaid === orderPrice && payPaid === orderPaid && payRefunded < orderPrice);
74
+ assert(!hasPaying && payPaid === orderPrice && payRefunded < orderPrice);
76
75
  if (orderIState !== 'refunding' || orderRefunded !== payRefunded) {
77
76
  await context.operate('order', {
78
77
  id: await generateNewIdAsync(),
@@ -504,17 +503,6 @@ const triggers = [
504
503
  action: 'create',
505
504
  }
506
505
  ];
507
- await context.operate('deposit', {
508
- id: await generateNewIdAsync(),
509
- action: 'succeed',
510
- data: {
511
- accountOper$entity: accountOpers,
512
- },
513
- filter: {
514
- id: depositId,
515
- },
516
- }, {});
517
- cnt++;
518
506
  if (loss > 0) {
519
507
  // 如果有loss就充入system的account账户
520
508
  const [account] = await context.select('account', {
@@ -539,6 +527,17 @@ const triggers = [
539
527
  });
540
528
  cnt++;
541
529
  }
530
+ await context.operate('deposit', {
531
+ id: await generateNewIdAsync(),
532
+ action: 'succeed',
533
+ data: {
534
+ accountOper$entity: accountOpers,
535
+ },
536
+ filter: {
537
+ id: depositId,
538
+ },
539
+ }, {});
540
+ cnt++;
542
541
  }
543
542
  return cnt;
544
543
  },
@@ -2,6 +2,7 @@ import { generateNewId, generateNewIdAsync } from 'oak-domain/lib/utils/uuid';
2
2
  import { getAccountEntity, getPayClazz } from '../utils/payClazz';
3
3
  import assert from 'assert';
4
4
  import { updateWithdrawState } from './withdraw';
5
+ import { RefundExceedMax, PayUnRefundable } from '../types/Exception';
5
6
  /**
6
7
  * 开始退款的逻辑
7
8
  * @param context
@@ -15,6 +16,9 @@ async function startRefunding(context, data) {
15
16
  paid: 1,
16
17
  refunded: 1,
17
18
  iState: 1,
19
+ entity: 1,
20
+ entityId: 1,
21
+ refundable: 1,
18
22
  deposit: {
19
23
  id: 1,
20
24
  accountId: 1,
@@ -29,10 +33,32 @@ async function startRefunding(context, data) {
29
33
  }
30
34
  }, { dontCollect: true });
31
35
  const { paid, refunded, deposit, order } = pay;
32
- assert(paid - refunded >= data.price);
36
+ if (paid - refunded < data.price) {
37
+ throw new RefundExceedMax();
38
+ }
39
+ if (!pay.refundable) {
40
+ throw new PayUnRefundable();
41
+ }
33
42
  if (deposit) {
34
- // 是提现,其Account相应的计算在withdraw进行
35
- assert(data.withdrawId);
43
+ // 充值不可能从account渠道支付
44
+ assert(pay.entity !== 'account');
45
+ if (!data.withdrawId && !order?.id) {
46
+ //充值退款需创建关联的accountOper,若为提现则在withdraw中创建
47
+ data.accountOper$entity = [
48
+ {
49
+ id: await generateNewIdAsync(),
50
+ action: 'create',
51
+ data: {
52
+ id: await generateNewIdAsync(),
53
+ accountId: deposit.accountId,
54
+ type: 'refund',
55
+ totalPlus: -data.price,
56
+ availPlus: -data.price,
57
+ refundablePlus: -data.price,
58
+ },
59
+ }
60
+ ];
61
+ }
36
62
  }
37
63
  else {
38
64
  assert(order);
@@ -121,24 +147,45 @@ async function succeedRefunding(context, refundId) {
121
147
  id: pay.id,
122
148
  }
123
149
  }, {});
124
- const payClazz = await getPayClazz(entity, entityId, context);
125
- // 实际执行的退款的额度应该是price - loss
126
- const [delta, sysAccountEntity, sysAccountEntityId] = payClazz.calcRefundTax(refundPrice - refundLoss);
127
- // sysAccount上减掉实际退款的额度-税费
128
- await context.operate('sysAccountOper', {
129
- id: await generateNewIdAsync(),
130
- action: 'create',
131
- data: {
150
+ let d = undefined; //退回至account的退款无渠道退款补偿
151
+ if (entity === 'account') {
152
+ //退回至account中的退款,创建accountOper,更新account余额
153
+ await context.operate('accountOper', {
132
154
  id: await generateNewIdAsync(),
133
- delta: refundLoss - refundPrice - delta,
134
- entity: sysAccountEntity,
135
- entityId: sysAccountEntityId,
136
- refundId: refund.id,
137
- type: 'refund',
138
- }
139
- }, {});
155
+ action: 'create',
156
+ data: {
157
+ id: await generateNewIdAsync(),
158
+ accountId: pay.entityId,
159
+ entity: 'refund',
160
+ entityId: refund.id,
161
+ type: 'consumeBack',
162
+ totalPlus: refundPrice - refundLoss,
163
+ availPlus: refundPrice - refundLoss,
164
+ }
165
+ }, {});
166
+ }
167
+ else {
168
+ //订单退回至非account的退款会使得系统对应账户的资金发生流出
169
+ const payClazz = await getPayClazz(entity, entityId, context);
170
+ // 实际执行的退款的额度应该是price - loss
171
+ const [delta, sysAccountEntity, sysAccountEntityId] = payClazz.calcRefundTax(refundPrice - refundLoss);
172
+ // sysAccount上减掉实际退款的额度-税费
173
+ await context.operate('sysAccountOper', {
174
+ id: await generateNewIdAsync(),
175
+ action: 'create',
176
+ data: {
177
+ id: await generateNewIdAsync(),
178
+ delta: refundLoss - refundPrice - delta,
179
+ entity: sysAccountEntity,
180
+ entityId: sysAccountEntityId,
181
+ refundId: refund.id,
182
+ type: 'refund',
183
+ }
184
+ }, {});
185
+ d = delta;
186
+ }
140
187
  let cnt = 2;
141
- if (refundLoss || delta) {
188
+ if (refundLoss || d) {
142
189
  // 如果有退回或者要缴纳的税费,进入system相关联的account账户
143
190
  const [account] = await context.select('account', {
144
191
  data: {
@@ -149,16 +196,16 @@ async function succeedRefunding(context, refundId) {
149
196
  entityId: application.systemId,
150
197
  },
151
198
  }, { dontCollect: true });
152
- if (delta) {
199
+ if (d) {
153
200
  await context.operate('accountOper', {
154
201
  id: await generateNewIdAsync(),
155
202
  action: 'create',
156
203
  data: {
157
204
  id: await generateNewIdAsync(),
158
205
  accountId: account.id,
159
- type: delta < 0 ? 'taxRefund' : 'tax',
160
- totalPlus: -delta,
161
- availPlus: -delta,
206
+ type: d < 0 ? 'taxRefund' : 'tax',
207
+ totalPlus: -d,
208
+ availPlus: -d,
162
209
  entity: 'refund',
163
210
  entityId: refund.id,
164
211
  },
@@ -16,6 +16,9 @@ export declare class ExternalPayUtilException<ED extends EntityDict> extends Oak
16
16
  export declare class RefundExceedMax<ED extends EntityDict> extends OakException<ED> {
17
17
  constructor(message?: string);
18
18
  }
19
+ export declare class PayUnRefundable<ED extends EntityDict> extends OakException<ED> {
20
+ constructor(message?: string);
21
+ }
19
22
  export declare class StartPayFailure<ED extends EntityDict> extends OakException<ED> {
20
23
  constructor(message: string);
21
24
  }
@@ -16,7 +16,12 @@ export class ExternalPayUtilException extends OakException {
16
16
  }
17
17
  export class RefundExceedMax extends OakException {
18
18
  constructor(message) {
19
- super(message || '可退款的总额不足');
19
+ super(message || 'error::refund.create.exceedMax');
20
+ }
21
+ }
22
+ export class PayUnRefundable extends OakException {
23
+ constructor(message) {
24
+ super(message || 'error::refund.create.payUnrefundable');
20
25
  }
21
26
  }
22
27
  export class StartPayFailure extends OakException {
@@ -46,7 +46,7 @@ const attrUpdateMatrix = {
46
46
  actions: ['refundPartially', 'refundAll'],
47
47
  },
48
48
  refundable: {
49
- actions: ['succeedPaying', 'closeRefund'],
49
+ actions: ['succeedPaying', 'closeRefund', 'stopRefunding', 'refundPartially'],
50
50
  },
51
51
  forbidRefundAt: {
52
52
  actions: ['succeedPaying'],
package/lib/data/i18n.js CHANGED
@@ -800,7 +800,9 @@ const i18ns = [
800
800
  },
801
801
  "refund": {
802
802
  "create": {
803
- "hasAnotherRefunding": "您有一笔退款正在进行中"
803
+ "hasAnotherRefunding": "您有一笔退款正在进行中",
804
+ "exceedMax": "退款额度大于可用值",
805
+ "payUnrefundable": "支付已经不可退款"
804
806
  }
805
807
  }
806
808
  }
@@ -19,7 +19,9 @@
19
19
  },
20
20
  "refund": {
21
21
  "create": {
22
- "hasAnotherRefunding": "您有一笔退款正在进行中"
22
+ "hasAnotherRefunding": "您有一笔退款正在进行中",
23
+ "exceedMax": "退款额度大于可用值",
24
+ "payUnrefundable": "支付已经不可退款"
23
25
  }
24
26
  }
25
27
  }
@@ -47,8 +47,7 @@ async function changeOrderStateByPay(filter, context, option) {
47
47
  break;
48
48
  }
49
49
  }
50
- if (paid && iState === 'paid') {
51
- //已支付完成的订单的paid
50
+ if (paid) { //对iState是否为paid的判断会影响退款,先去掉
52
51
  payPaid += paid;
53
52
  }
54
53
  if (refunded) {
@@ -75,7 +74,7 @@ async function changeOrderStateByPay(filter, context, option) {
75
74
  }
76
75
  }
77
76
  else if (hasRefunding) {
78
- (0, assert_1.default)(!hasPaying && payPaid === orderPrice && payPaid === orderPaid && payRefunded < orderPrice);
77
+ (0, assert_1.default)(!hasPaying && payPaid === orderPrice && payRefunded < orderPrice);
79
78
  if (orderIState !== 'refunding' || orderRefunded !== payRefunded) {
80
79
  await context.operate('order', {
81
80
  id: await (0, uuid_1.generateNewIdAsync)(),
@@ -507,17 +506,6 @@ const triggers = [
507
506
  action: 'create',
508
507
  }
509
508
  ];
510
- await context.operate('deposit', {
511
- id: await (0, uuid_1.generateNewIdAsync)(),
512
- action: 'succeed',
513
- data: {
514
- accountOper$entity: accountOpers,
515
- },
516
- filter: {
517
- id: depositId,
518
- },
519
- }, {});
520
- cnt++;
521
509
  if (loss > 0) {
522
510
  // 如果有loss就充入system的account账户
523
511
  const [account] = await context.select('account', {
@@ -542,6 +530,17 @@ const triggers = [
542
530
  });
543
531
  cnt++;
544
532
  }
533
+ await context.operate('deposit', {
534
+ id: await (0, uuid_1.generateNewIdAsync)(),
535
+ action: 'succeed',
536
+ data: {
537
+ accountOper$entity: accountOpers,
538
+ },
539
+ filter: {
540
+ id: depositId,
541
+ },
542
+ }, {});
543
+ cnt++;
545
544
  }
546
545
  return cnt;
547
546
  },
@@ -5,6 +5,7 @@ const uuid_1 = require("oak-domain/lib/utils/uuid");
5
5
  const payClazz_1 = require("../utils/payClazz");
6
6
  const assert_1 = tslib_1.__importDefault(require("assert"));
7
7
  const withdraw_1 = require("./withdraw");
8
+ const Exception_1 = require("../types/Exception");
8
9
  /**
9
10
  * 开始退款的逻辑
10
11
  * @param context
@@ -18,6 +19,9 @@ async function startRefunding(context, data) {
18
19
  paid: 1,
19
20
  refunded: 1,
20
21
  iState: 1,
22
+ entity: 1,
23
+ entityId: 1,
24
+ refundable: 1,
21
25
  deposit: {
22
26
  id: 1,
23
27
  accountId: 1,
@@ -32,10 +36,32 @@ async function startRefunding(context, data) {
32
36
  }
33
37
  }, { dontCollect: true });
34
38
  const { paid, refunded, deposit, order } = pay;
35
- (0, assert_1.default)(paid - refunded >= data.price);
39
+ if (paid - refunded < data.price) {
40
+ throw new Exception_1.RefundExceedMax();
41
+ }
42
+ if (!pay.refundable) {
43
+ throw new Exception_1.PayUnRefundable();
44
+ }
36
45
  if (deposit) {
37
- // 是提现,其Account相应的计算在withdraw进行
38
- (0, assert_1.default)(data.withdrawId);
46
+ // 充值不可能从account渠道支付
47
+ (0, assert_1.default)(pay.entity !== 'account');
48
+ if (!data.withdrawId && !order?.id) {
49
+ //充值退款需创建关联的accountOper,若为提现则在withdraw中创建
50
+ data.accountOper$entity = [
51
+ {
52
+ id: await (0, uuid_1.generateNewIdAsync)(),
53
+ action: 'create',
54
+ data: {
55
+ id: await (0, uuid_1.generateNewIdAsync)(),
56
+ accountId: deposit.accountId,
57
+ type: 'refund',
58
+ totalPlus: -data.price,
59
+ availPlus: -data.price,
60
+ refundablePlus: -data.price,
61
+ },
62
+ }
63
+ ];
64
+ }
39
65
  }
40
66
  else {
41
67
  (0, assert_1.default)(order);
@@ -124,24 +150,45 @@ async function succeedRefunding(context, refundId) {
124
150
  id: pay.id,
125
151
  }
126
152
  }, {});
127
- const payClazz = await (0, payClazz_1.getPayClazz)(entity, entityId, context);
128
- // 实际执行的退款的额度应该是price - loss
129
- const [delta, sysAccountEntity, sysAccountEntityId] = payClazz.calcRefundTax(refundPrice - refundLoss);
130
- // sysAccount上减掉实际退款的额度-税费
131
- await context.operate('sysAccountOper', {
132
- id: await (0, uuid_1.generateNewIdAsync)(),
133
- action: 'create',
134
- data: {
153
+ let d = undefined; //退回至account的退款无渠道退款补偿
154
+ if (entity === 'account') {
155
+ //退回至account中的退款,创建accountOper,更新account余额
156
+ await context.operate('accountOper', {
135
157
  id: await (0, uuid_1.generateNewIdAsync)(),
136
- delta: refundLoss - refundPrice - delta,
137
- entity: sysAccountEntity,
138
- entityId: sysAccountEntityId,
139
- refundId: refund.id,
140
- type: 'refund',
141
- }
142
- }, {});
158
+ action: 'create',
159
+ data: {
160
+ id: await (0, uuid_1.generateNewIdAsync)(),
161
+ accountId: pay.entityId,
162
+ entity: 'refund',
163
+ entityId: refund.id,
164
+ type: 'consumeBack',
165
+ totalPlus: refundPrice - refundLoss,
166
+ availPlus: refundPrice - refundLoss,
167
+ }
168
+ }, {});
169
+ }
170
+ else {
171
+ //订单退回至非account的退款会使得系统对应账户的资金发生流出
172
+ const payClazz = await (0, payClazz_1.getPayClazz)(entity, entityId, context);
173
+ // 实际执行的退款的额度应该是price - loss
174
+ const [delta, sysAccountEntity, sysAccountEntityId] = payClazz.calcRefundTax(refundPrice - refundLoss);
175
+ // sysAccount上减掉实际退款的额度-税费
176
+ await context.operate('sysAccountOper', {
177
+ id: await (0, uuid_1.generateNewIdAsync)(),
178
+ action: 'create',
179
+ data: {
180
+ id: await (0, uuid_1.generateNewIdAsync)(),
181
+ delta: refundLoss - refundPrice - delta,
182
+ entity: sysAccountEntity,
183
+ entityId: sysAccountEntityId,
184
+ refundId: refund.id,
185
+ type: 'refund',
186
+ }
187
+ }, {});
188
+ d = delta;
189
+ }
143
190
  let cnt = 2;
144
- if (refundLoss || delta) {
191
+ if (refundLoss || d) {
145
192
  // 如果有退回或者要缴纳的税费,进入system相关联的account账户
146
193
  const [account] = await context.select('account', {
147
194
  data: {
@@ -152,16 +199,16 @@ async function succeedRefunding(context, refundId) {
152
199
  entityId: application.systemId,
153
200
  },
154
201
  }, { dontCollect: true });
155
- if (delta) {
202
+ if (d) {
156
203
  await context.operate('accountOper', {
157
204
  id: await (0, uuid_1.generateNewIdAsync)(),
158
205
  action: 'create',
159
206
  data: {
160
207
  id: await (0, uuid_1.generateNewIdAsync)(),
161
208
  accountId: account.id,
162
- type: delta < 0 ? 'taxRefund' : 'tax',
163
- totalPlus: -delta,
164
- availPlus: -delta,
209
+ type: d < 0 ? 'taxRefund' : 'tax',
210
+ totalPlus: -d,
211
+ availPlus: -d,
165
212
  entity: 'refund',
166
213
  entityId: refund.id,
167
214
  },
@@ -16,6 +16,9 @@ export declare class ExternalPayUtilException<ED extends EntityDict> extends Oak
16
16
  export declare class RefundExceedMax<ED extends EntityDict> extends OakException<ED> {
17
17
  constructor(message?: string);
18
18
  }
19
+ export declare class PayUnRefundable<ED extends EntityDict> extends OakException<ED> {
20
+ constructor(message?: string);
21
+ }
19
22
  export declare class StartPayFailure<ED extends EntityDict> extends OakException<ED> {
20
23
  constructor(message: string);
21
24
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeException = exports.StartPayFailure = exports.RefundExceedMax = exports.ExternalPayUtilException = void 0;
3
+ exports.makeException = exports.StartPayFailure = exports.PayUnRefundable = exports.RefundExceedMax = exports.ExternalPayUtilException = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const types_1 = require("oak-domain/lib/types");
6
6
  const DependentExceptions_1 = tslib_1.__importDefault(require("./DependentExceptions"));
@@ -21,10 +21,16 @@ class ExternalPayUtilException extends types_1.OakException {
21
21
  exports.ExternalPayUtilException = ExternalPayUtilException;
22
22
  class RefundExceedMax extends types_1.OakException {
23
23
  constructor(message) {
24
- super(message || '可退款的总额不足');
24
+ super(message || 'error::refund.create.exceedMax');
25
25
  }
26
26
  }
27
27
  exports.RefundExceedMax = RefundExceedMax;
28
+ class PayUnRefundable extends types_1.OakException {
29
+ constructor(message) {
30
+ super(message || 'error::refund.create.payUnrefundable');
31
+ }
32
+ }
33
+ exports.PayUnRefundable = PayUnRefundable;
28
34
  class StartPayFailure extends types_1.OakException {
29
35
  constructor(message) {
30
36
  super(message);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oak-pay-business",
3
- "version": "2.5.1",
3
+ "version": "2.5.2",
4
4
  "description": "",
5
5
  "files": [
6
6
  "lib/**/*",
@@ -29,9 +29,9 @@
29
29
  "dependencies": {
30
30
  "classnames": "^2.3.1",
31
31
  "dayjs": "^1.11.5",
32
- "oak-domain": "^5.1.2",
33
- "oak-frontend-base": "^5.3.10",
34
- "oak-general-business": "~5.5.1",
32
+ "oak-domain": "^5.1.5",
33
+ "oak-frontend-base": "^5.3.13",
34
+ "oak-general-business": "~5.5.3",
35
35
  "wechat-pay-nodejs": "^0.2.3"
36
36
  },
37
37
  "peerDependencies": {