rerobe-js-orm 4.9.17 → 4.9.18

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.
@@ -5,6 +5,7 @@ export default class RefundFormState extends FormState {
5
5
  fields: OrderRefundFormFields;
6
6
  props: CompleteRefund;
7
7
  orderHelpers: OrderHelpers;
8
+ totalRefundedManuallyEdited: boolean;
8
9
  constructor(props?: any);
9
10
  createRefund(): Refund;
10
11
  updateTotalRefunded(): void;
@@ -8,6 +8,11 @@ class RefundFormState extends FormState_1.default {
8
8
  constructor(props) {
9
9
  super();
10
10
  this.orderHelpers = new OrderHelpers_1.default();
11
+ // Once an admin types an explicit refund amount, that value is authoritative.
12
+ // Line-item / shipping edits must NOT silently recompute (and thereby wipe) it,
13
+ // because the server-side order trigger issues a REAL Stripe refund for
14
+ // `refund.totalRefunded.amount` — a clobbered value over-refunds the customer.
15
+ this.totalRefundedManuallyEdited = false;
11
16
  this.props = Object.assign(Object.assign({}, new Refund_1.default(props).toObj()), { orderMoreInfo: (props === null || props === void 0 ? void 0 : props.order) ? this.orderHelpers.getOrderInfoWithRefundsAndFulfillments(props === null || props === void 0 ? void 0 : props.order) : {} });
12
17
  this.fields.totalRefunded = this.fieldFactory('textInput', 'totalRefunded');
13
18
  this.fields.subtotalRefunded = this.fieldFactory('textInput', 'subtotalRefunded');
@@ -31,12 +36,17 @@ class RefundFormState extends FormState_1.default {
31
36
  return refundFactory.createRefund(this);
32
37
  }
33
38
  updateTotalRefunded() {
34
- this.fields.totalRefunded.inputValue = this.orderHelpers.toFixedPointPrice(Number(this.fields.subtotalRefunded.inputValue) +
35
- Number(this.fields.refundShipping.inputValue) +
36
- Number(this.fields.totalTax.inputValue));
37
- this.fields.totalRefundedPresentment.inputValue = this.orderHelpers.toFixedPointPrice(Number(this.fields.subtotalRefundedPresentment.inputValue) +
38
- Number(this.fields.refundShippingPresentment.inputValue) +
39
- Number(this.fields.totalTaxPresentment.inputValue));
39
+ // Only auto-derive the refund total from line items when the admin has NOT
40
+ // typed an explicit amount. Otherwise their entered value (e.g. full amount
41
+ // minus a withheld return fee) is preserved.
42
+ if (!this.totalRefundedManuallyEdited) {
43
+ this.fields.totalRefunded.inputValue = this.orderHelpers.toFixedPointPrice(Number(this.fields.subtotalRefunded.inputValue) +
44
+ Number(this.fields.refundShipping.inputValue) +
45
+ Number(this.fields.totalTax.inputValue));
46
+ this.fields.totalRefundedPresentment.inputValue = this.orderHelpers.toFixedPointPrice(Number(this.fields.subtotalRefundedPresentment.inputValue) +
47
+ Number(this.fields.refundShippingPresentment.inputValue) +
48
+ Number(this.fields.totalTaxPresentment.inputValue));
49
+ }
40
50
  this.fields.refundCurrency.inputValue =
41
51
  Number(this.fields.totalRefunded.inputValue) - Number(this.fields.refundCreditDiscount.inputValue);
42
52
  this.fields.refundCurrencyPresentment.inputValue =
@@ -219,6 +229,12 @@ class RefundFormState extends FormState_1.default {
219
229
  fieldKey === 'totalRefundedPresentment') {
220
230
  onChangeHandler = (val) => {
221
231
  this.fields[fieldKey].inputValue = String(val);
232
+ // Typing an explicit refund total marks it authoritative so later
233
+ // line-item / shipping edits can't recompute it away. Clearing the
234
+ // field (empty) re-enables auto-calculation from line items.
235
+ if (fieldKey === 'totalRefunded' || fieldKey === 'totalRefundedPresentment') {
236
+ this.totalRefundedManuallyEdited = String(val !== null && val !== void 0 ? val : '').trim() !== '';
237
+ }
222
238
  this.updateRelatedField(fieldKey, Number(val || 0));
223
239
  if (fieldKey === 'refundShipping' || fieldKey === 'refundShippingPresentment') {
224
240
  this.updateTotalRefunded();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rerobe-js-orm",
3
- "version": "4.9.17",
3
+ "version": "4.9.18",
4
4
  "description": "ReRobe's Javascript ORM Framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",