@sixtyninecommerce/admin 0.11.0 → 0.13.0
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.
- package/README.md +1509 -28
- package/dist/auth/index.d.ts +7 -1
- package/dist/auth/index.js +8 -1
- package/dist/catalog/documents.d.ts +142 -0
- package/dist/catalog/documents.js +114 -0
- package/dist/catalog/index.d.ts +48 -7
- package/dist/catalog/index.js +6 -1
- package/dist/catalog/metadata.d.ts +244 -0
- package/dist/catalog/metadata.js +220 -0
- package/dist/catalog/properties.d.ts +38 -0
- package/dist/catalog/properties.js +52 -1
- package/dist/catalog/recommendations.d.ts +33 -6
- package/dist/catalog/recommendations.js +94 -2
- package/dist/catalog/reviews.d.ts +17 -4
- package/dist/catalog/reviews.js +7 -0
- package/dist/catalog/variants.d.ts +60 -0
- package/dist/catalog/variants.js +39 -0
- package/dist/catalog/visibility.d.ts +18 -2
- package/dist/client.d.ts +29 -3
- package/dist/client.js +19 -8
- package/dist/content/assets.d.ts +3 -4
- package/dist/content/forms.d.ts +332 -1
- package/dist/content/forms.js +140 -4
- package/dist/content/items.d.ts +31 -8
- package/dist/content/items.js +1 -1
- package/dist/content/menus.d.ts +254 -0
- package/dist/content/menus.js +70 -0
- package/dist/content/strings.d.ts +137 -0
- package/dist/content/strings.js +82 -0
- package/dist/customers/delivery-terms.d.ts +44 -0
- package/dist/customers/delivery-terms.js +32 -0
- package/dist/customers/groups.d.ts +16 -5
- package/dist/customers/groups.js +6 -2
- package/dist/customers/index.d.ts +15 -0
- package/dist/customers/index.js +4 -0
- package/dist/documents/emails.d.ts +154 -0
- package/dist/documents/emails.js +220 -0
- package/dist/documents/index.d.ts +13 -0
- package/dist/documents/index.js +2 -0
- package/dist/fulfillments/create.d.ts +1 -1
- package/dist/fulfillments/create.js +5 -2
- package/dist/fulfillments/index.d.ts +119 -1
- package/dist/fulfillments/index.js +124 -4
- package/dist/fulfillments/warehouse.d.ts +29 -17
- package/dist/fulfillments/warehouse.js +32 -1
- package/dist/index.d.ts +43 -23
- package/dist/index.js +11 -5
- package/dist/integrations/exact-online-types.d.ts +542 -0
- package/dist/integrations/exact-online.d.ts +541 -5
- package/dist/integrations/exact-online.js +714 -1
- package/dist/integrations/index.d.ts +23 -8
- package/dist/integrations/index.js +9 -4
- package/dist/integrations/pipeline-discoveries.d.ts +65 -0
- package/dist/integrations/pipeline-discoveries.js +65 -0
- package/dist/integrations/pipeline-runs.d.ts +119 -0
- package/dist/integrations/pipeline-runs.js +87 -0
- package/dist/integrations/pipelines.d.ts +73 -2
- package/dist/integrations/pipelines.js +36 -1
- package/dist/integrations/price-import.d.ts +223 -0
- package/dist/integrations/price-import.js +124 -0
- package/dist/integrations/types.d.ts +221 -3
- package/dist/integrations/types.js +4 -3
- package/dist/meta/index.d.ts +10 -0
- package/dist/metafields/index.d.ts +8 -1
- package/dist/metafields/index.js +10 -0
- package/dist/orders/cancel-with-money.d.ts +10 -0
- package/dist/orders/cancel-with-money.js +2 -0
- package/dist/orders/commit-edit.d.ts +16 -0
- package/dist/orders/commit-edit.js +14 -1
- package/dist/orders/deposit-policy.d.ts +3 -1
- package/dist/orders/index.d.ts +22 -11
- package/dist/orders/index.js +5 -2
- package/dist/orders/list.d.ts +26 -5
- package/dist/orders/list.js +123 -13
- package/dist/orders/manual-discounts.d.ts +13 -5
- package/dist/orders/money-view.d.ts +149 -0
- package/dist/orders/money-view.js +99 -0
- package/dist/orders/plan-edit.d.ts +34 -2
- package/dist/orders/plan-edit.js +110 -12
- package/dist/orders/surcharges.d.ts +12 -0
- package/dist/orders/surcharges.js +34 -9
- package/dist/payments/account-credit.d.ts +17 -1
- package/dist/payments/account-credit.js +25 -2
- package/dist/payments/credit-noted-fields.d.ts +8 -1
- package/dist/payments/credit-noted-fields.js +34 -2
- package/dist/payments/customer-consent.d.ts +30 -0
- package/dist/payments/customer-consent.js +49 -0
- package/dist/payments/index.d.ts +89 -14
- package/dist/payments/index.js +22 -2
- package/dist/payments/requests.d.ts +6 -3
- package/dist/payments/requests.js +1 -0
- package/dist/pickups/index.d.ts +5 -3
- package/dist/pickups/index.js +5 -2
- package/dist/platform/email-gateways.d.ts +165 -0
- package/dist/platform/email-gateways.js +78 -0
- package/dist/platform/tax.d.ts +11 -3
- package/dist/platform/tax.js +30 -0
- package/dist/pos/exchanges.d.ts +6 -1
- package/dist/pos/index.d.ts +229 -10
- package/dist/pos/index.js +113 -4
- package/dist/pos/offline-sales.d.ts +44 -3
- package/dist/pos/offline-sales.js +57 -3
- package/dist/pos/returns.d.ts +28 -1
- package/dist/pos/returns.js +36 -6
- package/dist/pricing/price-lists.d.ts +3 -1
- package/dist/purchasing/alerts.d.ts +19 -4
- package/dist/purchasing/alerts.js +29 -3
- package/dist/purchasing/backorders.d.ts +61 -0
- package/dist/purchasing/backorders.js +92 -0
- package/dist/purchasing/index.d.ts +21 -3
- package/dist/purchasing/index.js +8 -0
- package/dist/purchasing/links.d.ts +263 -0
- package/dist/purchasing/links.js +192 -0
- package/dist/purchasing/purchase-orders.d.ts +4 -1
- package/dist/purchasing/receipts.d.ts +396 -0
- package/dist/purchasing/receipts.js +287 -0
- package/dist/purchasing/returns.d.ts +273 -0
- package/dist/purchasing/returns.js +229 -0
- package/dist/quotes/index.d.ts +20 -3
- package/dist/returns/index.d.ts +62 -1
- package/dist/returns/index.js +61 -0
- package/dist/seo/config.d.ts +128 -0
- package/dist/seo/config.js +95 -0
- package/dist/seo/redirects.d.ts +125 -0
- package/dist/seo/redirects.js +60 -1
- package/dist/seo/settings.d.ts +147 -0
- package/dist/seo/settings.js +209 -0
- package/dist/shipping/index.d.ts +6 -0
- package/dist/shipping/index.js +2 -0
- package/dist/shipping/methods.d.ts +8 -1
- package/dist/shipping/myparcel.d.ts +415 -1
- package/dist/shipping/myparcel.js +291 -3
- package/dist/shipping/rate-tables.d.ts +149 -4
- package/dist/shipping/rate-tables.js +229 -23
- package/dist/shipping/ship-to-countries.d.ts +75 -0
- package/dist/shipping/ship-to-countries.js +47 -0
- package/dist/stock/by-location.d.ts +86 -0
- package/dist/stock/by-location.js +94 -0
- package/dist/stock/index.d.ts +8 -1
- package/dist/stock/index.js +4 -0
- package/dist/stock/settings.d.ts +106 -0
- package/dist/stock/settings.js +103 -0
- package/dist/stock/transfers.d.ts +171 -10
- package/dist/stock/transfers.js +82 -4
- package/dist/stored-value/index.d.ts +98 -7
- package/dist/stored-value/index.js +71 -4
- package/dist/tax/display-policy.d.ts +105 -0
- package/dist/tax/display-policy.js +84 -0
- package/dist/tax/index.d.ts +3 -0
- package/dist/tax/index.js +2 -0
- package/dist/tenant/email-templates.d.ts +222 -1
- package/dist/tenant/email-templates.js +227 -10
- package/package.json +2 -2
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `admin.orders.moneyView(orderId, { basis })`: an order's money as rows that add up exactly to
|
|
3
|
+
* its own totals, in one basis (pricing-display-consistency, USER O12). Every surface that shows
|
|
4
|
+
* an order's money prints these rows, so an order page, an email and an invoice cannot disagree
|
|
5
|
+
* by a cent. The engine builds them (`Order.moneyView`); this module only reads them.
|
|
6
|
+
*/
|
|
7
|
+
import { type Transport } from '@sixtyninecommerce/core';
|
|
8
|
+
import type { Call } from '../types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Which prices a view shows. `GROSS` = incl. VAT, `NET` = excl. VAT. `STORE` follows how the
|
|
11
|
+
* store sets its prices; `CUSTOMER` how the shop shows prices to the order's customer. The view
|
|
12
|
+
* answers the one it used, `GROSS` or `NET`.
|
|
13
|
+
*/
|
|
14
|
+
export declare const ORDER_MONEY_BASES: readonly ["STORE", "CUSTOMER", "GROSS", "NET"];
|
|
15
|
+
export type OrderMoneyBasis = (typeof ORDER_MONEY_BASES)[number];
|
|
16
|
+
/** One order line. Money is an integer in minor units of the view's `currencyCode`. */
|
|
17
|
+
export interface OrderMoneyLine {
|
|
18
|
+
orderLineId: string;
|
|
19
|
+
quantity: number;
|
|
20
|
+
taxRate: number;
|
|
21
|
+
/**
|
|
22
|
+
* The unit price, only when the line was priced in this basis (`unitAmount × quantity =
|
|
23
|
+
* amount`); null in the other basis, where only the line total multiplies out.
|
|
24
|
+
*/
|
|
25
|
+
unitAmount: number | null;
|
|
26
|
+
/** The line total before promotions. */
|
|
27
|
+
amount: number;
|
|
28
|
+
}
|
|
29
|
+
/** A promotion, a surcharge or a shipping line. A discount is negative. */
|
|
30
|
+
export interface OrderMoneyRow {
|
|
31
|
+
/** The promotion's adjustment source, the surcharge id or the shipping line id. */
|
|
32
|
+
key: string;
|
|
33
|
+
description: string;
|
|
34
|
+
amount: number;
|
|
35
|
+
/** The row's VAT rate; null for a promotion, which can span several. */
|
|
36
|
+
taxRate: number | null;
|
|
37
|
+
}
|
|
38
|
+
/** The VAT at one rate: goods, shipping and surcharges together, a staff rounding's VAT in. */
|
|
39
|
+
export interface OrderMoneyTaxRow {
|
|
40
|
+
taxRate: number;
|
|
41
|
+
/** Excl. VAT. */
|
|
42
|
+
base: number;
|
|
43
|
+
amount: number;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Why a view gives no still-to-pay figure: `KEPT_IN_ERP`, the order was placed on a B2B account
|
|
47
|
+
* kept in an external accounting system, so print a note ("paid via your account in the
|
|
48
|
+
* accounting system") instead of an amount. A new value may be added.
|
|
49
|
+
*/
|
|
50
|
+
export type OrderMoneyStillToPayNote = 'KEPT_IN_ERP';
|
|
51
|
+
/**
|
|
52
|
+
* What has been paid and what is still to pay, gross; a zero row is not printed. An engine that
|
|
53
|
+
* answers `stillToPayNote` (null included) reads the B2B account ledger: money paid or credited on
|
|
54
|
+
* an account invoice is in `paid` and `credited`. Without it (an older engine) it is not, so an
|
|
55
|
+
* order a live account invoice bills reads its whole remainder as `stillToPay`: do not print that
|
|
56
|
+
* figure for it.
|
|
57
|
+
*/
|
|
58
|
+
export interface OrderMoneyBalance {
|
|
59
|
+
/** Money received or held by a payment provider, less refunds; never a payment still to arrive. */
|
|
60
|
+
paid: number;
|
|
61
|
+
giftCard: number;
|
|
62
|
+
storeCredit: number;
|
|
63
|
+
/** What credit notes took off the bill. */
|
|
64
|
+
credited: number;
|
|
65
|
+
/** What the order bills less the four above, never below zero. A bank-transfer or net-terms promise still counts as to pay. Zero when `stillToPayNote` is set. */
|
|
66
|
+
stillToPay: number;
|
|
67
|
+
/** Set when no still-to-pay figure can be given (print its note); null otherwise; absent on an older engine. */
|
|
68
|
+
stillToPayNote?: OrderMoneyStillToPayNote | null;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The rows and their identities: `Σ lines + Σ goodsAdjustments + Σ surcharges = subtotal`;
|
|
72
|
+
* `Σ shipping + Σ shippingAdjustments = shippingTotal`; on `GROSS` `subtotal + shippingTotal +
|
|
73
|
+
* (rounding ?? 0) = total`; on `NET` `subtotal + shippingTotal + taxTotal + (rounding ?? 0) =
|
|
74
|
+
* total`; `Σ taxes = taxTotal`; `totalExcludingTax + taxTotal = total`.
|
|
75
|
+
*/
|
|
76
|
+
export interface OrderMoneyView {
|
|
77
|
+
basis: 'GROSS' | 'NET';
|
|
78
|
+
currencyCode: string;
|
|
79
|
+
lines: OrderMoneyLine[];
|
|
80
|
+
/** One row per promotion on the goods (price-list order rules and coupons included). */
|
|
81
|
+
goodsAdjustments: OrderMoneyRow[];
|
|
82
|
+
/** Fees (positive) and staff discounts (negative). */
|
|
83
|
+
surcharges: OrderMoneyRow[];
|
|
84
|
+
subtotal: number;
|
|
85
|
+
/** Each shipping line before its promotions. */
|
|
86
|
+
shipping: OrderMoneyRow[];
|
|
87
|
+
/** One row per promotion on shipping. */
|
|
88
|
+
shippingAdjustments: OrderMoneyRow[];
|
|
89
|
+
shippingTotal: number;
|
|
90
|
+
/** Everything excl. VAT, a staff rounding's net part in: the invoice's "Total excl. VAT". */
|
|
91
|
+
totalExcludingTax: number;
|
|
92
|
+
/** One row per VAT rate. */
|
|
93
|
+
taxes: OrderMoneyTaxRow[];
|
|
94
|
+
/** True on `GROSS`: the VAT rows are inside the total, not added to it. */
|
|
95
|
+
taxIncluded: boolean;
|
|
96
|
+
taxTotal: number;
|
|
97
|
+
/** A staff rounding, printed just above the total (gross on `GROSS`, excl. VAT on `NET`). */
|
|
98
|
+
rounding: number | null;
|
|
99
|
+
/** What the order bills, incl. VAT, after a staff rounding. */
|
|
100
|
+
total: number;
|
|
101
|
+
/** The total before a staff rounding. */
|
|
102
|
+
totalBeforeRounding: number;
|
|
103
|
+
balance: OrderMoneyBalance;
|
|
104
|
+
/** False only when the order's stored totals disagree with its own rows. */
|
|
105
|
+
reconciles: boolean;
|
|
106
|
+
}
|
|
107
|
+
/** Every field of an `OrderMoneyView`, at every depth: the selection each document reads it with. */
|
|
108
|
+
export declare const ORDER_MONEY_VIEW_FIELDS = "\n basis\n currencyCode\n lines { orderLineId quantity taxRate unitAmount amount }\n goodsAdjustments { key description amount taxRate }\n surcharges { key description amount taxRate }\n subtotal\n shipping { key description amount taxRate }\n shippingAdjustments { key description amount taxRate }\n shippingTotal\n totalExcludingTax\n taxes { taxRate base amount }\n taxIncluded\n taxTotal\n rounding\n total\n totalBeforeRounding\n balance { paid giftCard storeCredit credited stillToPay stillToPayNote }\n reconciles\n";
|
|
109
|
+
export declare const ORDER_MONEY_VIEW_QUERY = "\n query OrderMoneyView($id: ID!, $basis: OrderMoneyBasis!) {\n order(id: $id) {\n id\n moneyView(basis: $basis) {\n basis\n currencyCode\n lines { orderLineId quantity taxRate unitAmount amount }\n goodsAdjustments { key description amount taxRate }\n surcharges { key description amount taxRate }\n subtotal\n shipping { key description amount taxRate }\n shippingAdjustments { key description amount taxRate }\n shippingTotal\n totalExcludingTax\n taxes { taxRate base amount }\n taxIncluded\n taxTotal\n rounding\n total\n totalBeforeRounding\n balance { paid giftCard storeCredit credited stillToPay stillToPayNote }\n reconciles\n }\n }\n }\n";
|
|
110
|
+
/** `INVALID_ORDER_MONEY_BASIS` for a basis not in `ORDER_MONEY_BASES`, before anything is sent. */
|
|
111
|
+
export declare function assertOrderMoneyBasis(basis: string): asserts basis is OrderMoneyBasis;
|
|
112
|
+
export interface OrderMoneyViewModule {
|
|
113
|
+
/**
|
|
114
|
+
* The order's money as rows that add up exactly to its stored totals, in `options.basis`
|
|
115
|
+
* (default `STORE`). Print these rows as they come, never re-derived: an amount re-computed
|
|
116
|
+
* from them, or from the order's other figures, can miss the order's own total by a cent.
|
|
117
|
+
* Needs `ReadOrder`.
|
|
118
|
+
*
|
|
119
|
+
* - A unit price (`lines[].unitAmount`) is only answered in the basis the line was priced in;
|
|
120
|
+
* show the line total alone in the other.
|
|
121
|
+
* - The VAT rows are one per rate. On a `GROSS` view they are included in the total
|
|
122
|
+
* (`taxIncluded`): label them so, never as an addition.
|
|
123
|
+
* - `balance.stillToPay` is money not received yet: a bank-transfer or net-terms payment that
|
|
124
|
+
* is promised still counts. With `balance.stillToPayNote` answered it reads the B2B account
|
|
125
|
+
* ledger; `KEPT_IN_ERP` means print its note, not a figure. Not answered (an older engine,
|
|
126
|
+
* resent without it): for an order a live account invoice bills, show the other rows only.
|
|
127
|
+
* - It reads the order as STORED: it cannot preview an edit (`planEdit`'s `preview.moneyView` does).
|
|
128
|
+
*
|
|
129
|
+
* Refused: `INVALID_ORDER_MONEY_BASIS` (`ValidationError`, 400, before sending) for a basis
|
|
130
|
+
* not in `ORDER_MONEY_BASES`; `ORDER_NOT_FOUND` (`NotFoundError`, 404) for an order this store
|
|
131
|
+
* does not hold. An engine before `Order.moneyView` refuses the document as
|
|
132
|
+
* `ValidationError` `GRAPHQL_VALIDATION_FAILED` (400): fall back to the order's own figures.
|
|
133
|
+
*
|
|
134
|
+
* @effect read
|
|
135
|
+
*/
|
|
136
|
+
moneyView(orderId: string, options?: Call & {
|
|
137
|
+
basis?: OrderMoneyBasis;
|
|
138
|
+
}): Promise<OrderMoneyView>;
|
|
139
|
+
}
|
|
140
|
+
/** `document` without `stillToPayNote`: what an engine before it accepts. */
|
|
141
|
+
export declare function withoutStillToPayNote(document: string): string;
|
|
142
|
+
/**
|
|
143
|
+
* The transport, sending a document that names `balance.stillToPayNote` (pricing-display-consistency
|
|
144
|
+
* B1c) once more without it when the engine refused it as unknown. Safe for a mutation too: a
|
|
145
|
+
* refused document never ran. The newest money-view field, so it falls away first: wrap it inside
|
|
146
|
+
* any other `*Aware` transport.
|
|
147
|
+
*/
|
|
148
|
+
export declare function stillToPayNoteAware(transport: Pick<Transport, 'graphql'>): Pick<Transport, 'graphql'>;
|
|
149
|
+
export declare function createOrderMoneyViewModule(transport: Transport): OrderMoneyViewModule;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `admin.orders.moneyView(orderId, { basis })`: an order's money as rows that add up exactly to
|
|
3
|
+
* its own totals, in one basis (pricing-display-consistency, USER O12). Every surface that shows
|
|
4
|
+
* an order's money prints these rows, so an order page, an email and an invoice cannot disagree
|
|
5
|
+
* by a cent. The engine builds them (`Order.moneyView`); this module only reads them.
|
|
6
|
+
*/
|
|
7
|
+
import { NotFoundError, ValidationError, } from '@sixtyninecommerce/core';
|
|
8
|
+
import { isUnknownFieldRejection } from '../payments/store-credit-fields.js';
|
|
9
|
+
/**
|
|
10
|
+
* Which prices a view shows. `GROSS` = incl. VAT, `NET` = excl. VAT. `STORE` follows how the
|
|
11
|
+
* store sets its prices; `CUSTOMER` how the shop shows prices to the order's customer. The view
|
|
12
|
+
* answers the one it used, `GROSS` or `NET`.
|
|
13
|
+
*/
|
|
14
|
+
export const ORDER_MONEY_BASES = ['STORE', 'CUSTOMER', 'GROSS', 'NET'];
|
|
15
|
+
const ROW_FIELDS = 'key description amount taxRate';
|
|
16
|
+
/** Every field of an `OrderMoneyView`, at every depth: the selection each document reads it with. */
|
|
17
|
+
export const ORDER_MONEY_VIEW_FIELDS = /* GraphQL */ `
|
|
18
|
+
basis
|
|
19
|
+
currencyCode
|
|
20
|
+
lines { orderLineId quantity taxRate unitAmount amount }
|
|
21
|
+
goodsAdjustments { ${ROW_FIELDS} }
|
|
22
|
+
surcharges { ${ROW_FIELDS} }
|
|
23
|
+
subtotal
|
|
24
|
+
shipping { ${ROW_FIELDS} }
|
|
25
|
+
shippingAdjustments { ${ROW_FIELDS} }
|
|
26
|
+
shippingTotal
|
|
27
|
+
totalExcludingTax
|
|
28
|
+
taxes { taxRate base amount }
|
|
29
|
+
taxIncluded
|
|
30
|
+
taxTotal
|
|
31
|
+
rounding
|
|
32
|
+
total
|
|
33
|
+
totalBeforeRounding
|
|
34
|
+
balance { paid giftCard storeCredit credited stillToPay stillToPayNote }
|
|
35
|
+
reconciles
|
|
36
|
+
`;
|
|
37
|
+
export const ORDER_MONEY_VIEW_QUERY = /* GraphQL */ `
|
|
38
|
+
query OrderMoneyView($id: ID!, $basis: OrderMoneyBasis!) {
|
|
39
|
+
order(id: $id) {
|
|
40
|
+
id
|
|
41
|
+
moneyView(basis: $basis) {${ORDER_MONEY_VIEW_FIELDS} }
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
`;
|
|
45
|
+
/** `INVALID_ORDER_MONEY_BASIS` for a basis not in `ORDER_MONEY_BASES`, before anything is sent. */
|
|
46
|
+
export function assertOrderMoneyBasis(basis) {
|
|
47
|
+
if (!ORDER_MONEY_BASES.includes(basis)) {
|
|
48
|
+
throw new ValidationError({
|
|
49
|
+
code: 'INVALID_ORDER_MONEY_BASIS',
|
|
50
|
+
message: `The basis must be one of ${ORDER_MONEY_BASES.join(', ')}.`,
|
|
51
|
+
status: 400,
|
|
52
|
+
service: 'vendure',
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const STILL_TO_PAY_NOTE_FIELD = /\bstillToPayNote\b/g;
|
|
57
|
+
/** `document` without `stillToPayNote`: what an engine before it accepts. */
|
|
58
|
+
export function withoutStillToPayNote(document) {
|
|
59
|
+
return document.replace(STILL_TO_PAY_NOTE_FIELD, '');
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The transport, sending a document that names `balance.stillToPayNote` (pricing-display-consistency
|
|
63
|
+
* B1c) once more without it when the engine refused it as unknown. Safe for a mutation too: a
|
|
64
|
+
* refused document never ran. The newest money-view field, so it falls away first: wrap it inside
|
|
65
|
+
* any other `*Aware` transport.
|
|
66
|
+
*/
|
|
67
|
+
export function stillToPayNoteAware(transport) {
|
|
68
|
+
return {
|
|
69
|
+
async graphql(call, options) {
|
|
70
|
+
try {
|
|
71
|
+
return await transport.graphql(call, options);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
const legacy = withoutStillToPayNote(call.query);
|
|
75
|
+
if (legacy === call.query || !isUnknownFieldRejection(error))
|
|
76
|
+
throw error;
|
|
77
|
+
return transport.graphql({ ...call, query: legacy }, options);
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
export function createOrderMoneyViewModule(transport) {
|
|
83
|
+
return {
|
|
84
|
+
async moneyView(orderId, options) {
|
|
85
|
+
const basis = options?.basis ?? 'STORE';
|
|
86
|
+
assertOrderMoneyBasis(basis);
|
|
87
|
+
const data = await stillToPayNoteAware(transport).graphql({ api: 'admin', query: ORDER_MONEY_VIEW_QUERY, variables: { id: orderId, basis } }, options);
|
|
88
|
+
if (!data.order) {
|
|
89
|
+
throw new NotFoundError({
|
|
90
|
+
code: 'ORDER_NOT_FOUND',
|
|
91
|
+
message: `This store has no order ${orderId}.`,
|
|
92
|
+
status: 404,
|
|
93
|
+
service: 'vendure',
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
return data.order.moneyView;
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Transport } from '@sixtyninecommerce/core';
|
|
2
2
|
import type { Call } from '../types.js';
|
|
3
|
+
import { type OrderMoneyBasis, type OrderMoneyView } from './money-view.js';
|
|
3
4
|
import type { OverpaymentOption } from './surcharges.js';
|
|
4
5
|
/**
|
|
5
6
|
* How a one-time discount is stated. A whole-order discount is `PERCENTAGE` or
|
|
@@ -376,6 +377,22 @@ export interface OrderEditPreview {
|
|
|
376
377
|
taxSummary: OrderEditTaxSummaryLine[];
|
|
377
378
|
/** The order's total with tax before the edit. */
|
|
378
379
|
totalWithTaxBefore: number;
|
|
380
|
+
/**
|
|
381
|
+
* The order's money after the edit as the order page prints it once the edit is saved
|
|
382
|
+
* (`orders.moneyView`'s rows, in `planEdit`'s `moneyBasis`), read inside the preview's run.
|
|
383
|
+
* Its `balance` is the order's payments before the plan's `refund`. Print these rows, never
|
|
384
|
+
* the figures above: they are the engine's, before a staff rounding. `null` from an engine
|
|
385
|
+
* before it; absent from `commitEdit`'s plan (read the saved order's `moneyView`).
|
|
386
|
+
*/
|
|
387
|
+
moneyView?: OrderMoneyView | null;
|
|
388
|
+
/** The order's money before the edit, read in the same run, in the same basis. */
|
|
389
|
+
moneyViewBefore?: OrderMoneyView | null;
|
|
390
|
+
/**
|
|
391
|
+
* What the edit changes the billable total by (a staff rounding included):
|
|
392
|
+
* `moneyView.total - moneyViewBefore.total`, computed by the engine. Print it as the
|
|
393
|
+
* difference; `totalWithTax - totalWithTaxBefore` ignores the rounding.
|
|
394
|
+
*/
|
|
395
|
+
totalDifference?: number | null;
|
|
379
396
|
}
|
|
380
397
|
export interface OrderEditPlan {
|
|
381
398
|
orderId: string;
|
|
@@ -422,7 +439,12 @@ export interface OrderEditPlan {
|
|
|
422
439
|
* the order-edit plan, so on an older one this call alone fails validation and
|
|
423
440
|
* no other order call does.
|
|
424
441
|
*/
|
|
425
|
-
export declare const PLAN_ORDER_EDIT_QUERY = "\n query PlanOrderEdit($orderId: ID!, $diff: OrderEditDiffInput!) {\n planOrderEdit(orderId: $orderId, diff: $diff) {\n orderId\n planHash\n orderVersion\n steps {\n kind\n input\n moneyEffect\n }\n refund {\n paymentId\n amount\n }\n overpayment {\n amount\n currencyCode\n surchargeIds\n refund {\n available\n code\n message\n book\n }\n accountCredit {\n available\n code\n message\n book\n }\n refundWhenChosen {\n paymentId\n amount\n }\n }\n returnState\n blockers {\n code\n message\n details\n }\n notices {\n code\n message\n details\n }\n payment {\n collected\n reason\n method\n }\n preview {\n currencyCode\n subTotal\n subTotalWithTax\n shipping\n shippingWithTax\n surcharges\n surchargesWithTax\n total\n totalWithTax\n taxSummary {\n description\n taxRate\n taxBase\n taxTotal\n }\n totalWithTaxBefore\n }\n }\n }\n";
|
|
442
|
+
export declare const PLAN_ORDER_EDIT_QUERY = "\n query PlanOrderEdit($orderId: ID!, $diff: OrderEditDiffInput!, $moneyBasis: OrderMoneyBasis!) {\n planOrderEdit(orderId: $orderId, diff: $diff) {\n orderId\n planHash\n orderVersion\n steps {\n kind\n input\n moneyEffect\n }\n refund {\n paymentId\n amount\n }\n overpayment {\n amount\n currencyCode\n surchargeIds\n refund {\n available\n code\n message\n book\n }\n accountCredit {\n available\n code\n message\n book\n }\n refundWhenChosen {\n paymentId\n amount\n }\n }\n returnState\n blockers {\n code\n message\n details\n }\n notices {\n code\n message\n details\n }\n payment {\n collected\n reason\n method\n }\n preview {\n currencyCode\n subTotal\n subTotalWithTax\n shipping\n shippingWithTax\n surcharges\n surchargesWithTax\n total\n totalWithTax\n taxSummary {\n description\n taxRate\n taxBase\n taxTotal\n }\n totalWithTaxBefore\n moneyView(basis: $moneyBasis) {\n basis\n currencyCode\n lines { orderLineId quantity taxRate unitAmount amount }\n goodsAdjustments { key description amount taxRate }\n surcharges { key description amount taxRate }\n subtotal\n shipping { key description amount taxRate }\n shippingAdjustments { key description amount taxRate }\n shippingTotal\n totalExcludingTax\n taxes { taxRate base amount }\n taxIncluded\n taxTotal\n rounding\n total\n totalBeforeRounding\n balance { paid giftCard storeCredit credited stillToPay stillToPayNote }\n reconciles\n }\n moneyViewBefore(basis: $moneyBasis) {\n basis\n currencyCode\n lines { orderLineId quantity taxRate unitAmount amount }\n goodsAdjustments { key description amount taxRate }\n surcharges { key description amount taxRate }\n subtotal\n shipping { key description amount taxRate }\n shippingAdjustments { key description amount taxRate }\n shippingTotal\n totalExcludingTax\n taxes { taxRate base amount }\n taxIncluded\n taxTotal\n rounding\n total\n totalBeforeRounding\n balance { paid giftCard storeCredit credited stillToPay stillToPayNote }\n reconciles\n }\n totalDifference\n }\n }\n }\n";
|
|
443
|
+
/**
|
|
444
|
+
* The document for an engine before the preview's money view (pricing-display-consistency B3):
|
|
445
|
+
* the same plan without `moneyView`, `moneyViewBefore`, `totalDifference` and their basis.
|
|
446
|
+
*/
|
|
447
|
+
export declare const PLAN_ORDER_EDIT_QUERY_BEFORE_MONEY_VIEW = "\n query PlanOrderEdit($orderId: ID!, $diff: OrderEditDiffInput!) {\n planOrderEdit(orderId: $orderId, diff: $diff) {\n orderId\n planHash\n orderVersion\n steps {\n kind\n input\n moneyEffect\n }\n refund {\n paymentId\n amount\n }\n overpayment {\n amount\n currencyCode\n surchargeIds\n refund {\n available\n code\n message\n book\n }\n accountCredit {\n available\n code\n message\n book\n }\n refundWhenChosen {\n paymentId\n amount\n }\n }\n returnState\n blockers {\n code\n message\n details\n }\n notices {\n code\n message\n details\n }\n payment {\n collected\n reason\n method\n }\n preview {\n currencyCode\n subTotal\n subTotalWithTax\n shipping\n shippingWithTax\n surcharges\n surchargesWithTax\n total\n totalWithTax\n taxSummary {\n description\n taxRate\n taxBase\n taxTotal\n }\n totalWithTaxBefore\n }\n }\n }\n";
|
|
426
448
|
export interface OrderPlanEditModule {
|
|
427
449
|
/**
|
|
428
450
|
* How an edit of a placed order would be carried out, and what the order
|
|
@@ -466,6 +488,12 @@ export interface OrderPlanEditModule {
|
|
|
466
488
|
* Keep `planHash` with what you show: `commitEdit` carries the edit out and
|
|
467
489
|
* names it, so what is saved is what the merchant saw.
|
|
468
490
|
*
|
|
491
|
+
* Show the edit's money from `preview.moneyView` (after) and `moneyViewBefore`, in
|
|
492
|
+
* `options.moneyBasis` (default `STORE`; `INVALID_ORDER_MONEY_BASIS` before sending for any
|
|
493
|
+
* other value than `ORDER_MONEY_BASES`): the same rows the order page prints once the edit is
|
|
494
|
+
* saved, each promotion, fee, VAT rate and staff rounding its own row. The difference is
|
|
495
|
+
* `preview.totalDifference`. An engine before them answers the plan without them (`null`).
|
|
496
|
+
*
|
|
469
497
|
* Refusals of the call:
|
|
470
498
|
* - `ORDER_EDIT_ORDER_NOT_FOUND`, `ORDER_EDIT_LINE_NOT_FOUND`,
|
|
471
499
|
* `ORDER_EDIT_SURCHARGE_NOT_FOUND` and `ORDER_EDIT_VARIANT_NOT_FOUND`
|
|
@@ -483,7 +511,11 @@ export interface OrderPlanEditModule {
|
|
|
483
511
|
* was made from the default channel instead of the order's own.
|
|
484
512
|
* - `ORDER_BUSY` (`ConflictError`, 409): another change of the order was
|
|
485
513
|
* still being applied. Ask again.
|
|
514
|
+
*
|
|
515
|
+
* @effect read
|
|
486
516
|
*/
|
|
487
|
-
planEdit(orderId: string, diff: OrderEditDiff, options?: Call
|
|
517
|
+
planEdit(orderId: string, diff: OrderEditDiff, options?: Call & {
|
|
518
|
+
moneyBasis?: OrderMoneyBasis;
|
|
519
|
+
}): Promise<OrderEditPlan>;
|
|
488
520
|
}
|
|
489
521
|
export declare function createOrderPlanEditModule(transport: Transport): OrderPlanEditModule;
|
package/dist/orders/plan-edit.js
CHANGED
|
@@ -1,10 +1,91 @@
|
|
|
1
|
-
import { storeCreditAware } from '../payments/store-credit-fields.js';
|
|
1
|
+
import { isUnknownFieldRejection, storeCreditAware } from '../payments/store-credit-fields.js';
|
|
2
|
+
import { assertOrderMoneyBasis, ORDER_MONEY_VIEW_FIELDS, stillToPayNoteAware, } from './money-view.js';
|
|
2
3
|
/**
|
|
3
4
|
* Its own document on purpose: `planOrderEdit` exists only on an engine with
|
|
4
5
|
* the order-edit plan, so on an older one this call alone fails validation and
|
|
5
6
|
* no other order call does.
|
|
6
7
|
*/
|
|
7
8
|
export const PLAN_ORDER_EDIT_QUERY = /* GraphQL */ `
|
|
9
|
+
query PlanOrderEdit($orderId: ID!, $diff: OrderEditDiffInput!, $moneyBasis: OrderMoneyBasis!) {
|
|
10
|
+
planOrderEdit(orderId: $orderId, diff: $diff) {
|
|
11
|
+
orderId
|
|
12
|
+
planHash
|
|
13
|
+
orderVersion
|
|
14
|
+
steps {
|
|
15
|
+
kind
|
|
16
|
+
input
|
|
17
|
+
moneyEffect
|
|
18
|
+
}
|
|
19
|
+
refund {
|
|
20
|
+
paymentId
|
|
21
|
+
amount
|
|
22
|
+
}
|
|
23
|
+
overpayment {
|
|
24
|
+
amount
|
|
25
|
+
currencyCode
|
|
26
|
+
surchargeIds
|
|
27
|
+
refund {
|
|
28
|
+
available
|
|
29
|
+
code
|
|
30
|
+
message
|
|
31
|
+
book
|
|
32
|
+
}
|
|
33
|
+
accountCredit {
|
|
34
|
+
available
|
|
35
|
+
code
|
|
36
|
+
message
|
|
37
|
+
book
|
|
38
|
+
}
|
|
39
|
+
refundWhenChosen {
|
|
40
|
+
paymentId
|
|
41
|
+
amount
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
returnState
|
|
45
|
+
blockers {
|
|
46
|
+
code
|
|
47
|
+
message
|
|
48
|
+
details
|
|
49
|
+
}
|
|
50
|
+
notices {
|
|
51
|
+
code
|
|
52
|
+
message
|
|
53
|
+
details
|
|
54
|
+
}
|
|
55
|
+
payment {
|
|
56
|
+
collected
|
|
57
|
+
reason
|
|
58
|
+
method
|
|
59
|
+
}
|
|
60
|
+
preview {
|
|
61
|
+
currencyCode
|
|
62
|
+
subTotal
|
|
63
|
+
subTotalWithTax
|
|
64
|
+
shipping
|
|
65
|
+
shippingWithTax
|
|
66
|
+
surcharges
|
|
67
|
+
surchargesWithTax
|
|
68
|
+
total
|
|
69
|
+
totalWithTax
|
|
70
|
+
taxSummary {
|
|
71
|
+
description
|
|
72
|
+
taxRate
|
|
73
|
+
taxBase
|
|
74
|
+
taxTotal
|
|
75
|
+
}
|
|
76
|
+
totalWithTaxBefore
|
|
77
|
+
moneyView(basis: $moneyBasis) {${ORDER_MONEY_VIEW_FIELDS} }
|
|
78
|
+
moneyViewBefore(basis: $moneyBasis) {${ORDER_MONEY_VIEW_FIELDS} }
|
|
79
|
+
totalDifference
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
`;
|
|
84
|
+
/**
|
|
85
|
+
* The document for an engine before the preview's money view (pricing-display-consistency B3):
|
|
86
|
+
* the same plan without `moneyView`, `moneyViewBefore`, `totalDifference` and their basis.
|
|
87
|
+
*/
|
|
88
|
+
export const PLAN_ORDER_EDIT_QUERY_BEFORE_MONEY_VIEW = /* GraphQL */ `
|
|
8
89
|
query PlanOrderEdit($orderId: ID!, $diff: OrderEditDiffInput!) {
|
|
9
90
|
planOrderEdit(orderId: $orderId, diff: $diff) {
|
|
10
91
|
orderId
|
|
@@ -80,17 +161,34 @@ export const PLAN_ORDER_EDIT_QUERY = /* GraphQL */ `
|
|
|
80
161
|
export function createOrderPlanEditModule(transport) {
|
|
81
162
|
return {
|
|
82
163
|
async planEdit(orderId, diff, options) {
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
164
|
+
const moneyBasis = options?.moneyBasis ?? 'STORE';
|
|
165
|
+
assertOrderMoneyBasis(moneyBasis);
|
|
166
|
+
const send = (query, variables) => storeCreditAware(stillToPayNoteAware(transport)).graphql(
|
|
167
|
+
// The diff goes out as given, never normalised: `orderDiscount` left
|
|
168
|
+
// out, `null` and a value are three different requests to the engine
|
|
169
|
+
// (keep, remove, set). `JSON.stringify` drops a key that is
|
|
170
|
+
// `undefined` and keeps a `null`, so a default here would turn
|
|
171
|
+
// "keep" into "remove".
|
|
172
|
+
{ api: 'admin', query, variables: { orderId, diff, ...variables } }, options);
|
|
173
|
+
try {
|
|
174
|
+
return (await send(PLAN_ORDER_EDIT_QUERY, { moneyBasis })).planOrderEdit;
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
// An engine before the preview's money refuses the document before it runs, so
|
|
178
|
+
// nothing was planned: ask again without it.
|
|
179
|
+
if (!isUnknownFieldRejection(error))
|
|
180
|
+
throw error;
|
|
181
|
+
const { planOrderEdit } = await send(PLAN_ORDER_EDIT_QUERY_BEFORE_MONEY_VIEW, {});
|
|
182
|
+
return {
|
|
183
|
+
...planOrderEdit,
|
|
184
|
+
preview: planOrderEdit.preview && {
|
|
185
|
+
...planOrderEdit.preview,
|
|
186
|
+
moneyView: null,
|
|
187
|
+
moneyViewBefore: null,
|
|
188
|
+
totalDifference: null,
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
}
|
|
94
192
|
},
|
|
95
193
|
};
|
|
96
194
|
}
|
|
@@ -53,6 +53,15 @@ export interface SurchargeRemoveCall extends Call {
|
|
|
53
53
|
* either (`ORDER_OVERPAYMENT_REFUND_UNRECONCILED`) until it is reconciled.
|
|
54
54
|
*/
|
|
55
55
|
overpayment?: OrderOverpaymentChoice;
|
|
56
|
+
/**
|
|
57
|
+
* With `ACCOUNT_CREDIT` in a store whose book is store credit (`preview`'s
|
|
58
|
+
* `accountCredit.book` `STORE_CREDIT`): whether the customer expressly agreed to store credit
|
|
59
|
+
* instead of a refund to their payment (EU consumer law, CRD art. 13(1)), as staff recorded it.
|
|
60
|
+
* The move records it on its ledger entries (`StoredValueEntry.customerAgreed`); never a
|
|
61
|
+
* condition, nothing is refused for it, and it is recorded nowhere else. Sent only when given;
|
|
62
|
+
* an engine before the field (incentives sprint 8 PR 6a) refuses a call that gives it.
|
|
63
|
+
*/
|
|
64
|
+
customerAgreed?: boolean;
|
|
56
65
|
}
|
|
57
66
|
/** Options for a surcharge write. */
|
|
58
67
|
export interface SurchargeCall extends SurchargeRemoveCall {
|
|
@@ -197,5 +206,8 @@ export declare const UPDATE_ORDER_SURCHARGE_MUTATION = "\n mutation UpdateOrder
|
|
|
197
206
|
export declare const UPDATE_ORDER_SURCHARGE_WITH_OVERPAYMENT_MUTATION = "\n mutation UpdateOrderSurchargeWithOverpayment(\n $orderId: ID!\n $surchargeId: ID!\n $input: SurchargeInput!\n $taxClass: String\n $idempotencyKey: String\n $overpayment: OrderOverpaymentChoice\n ) {\n updateOrderSurcharge(\n orderId: $orderId\n surchargeId: $surchargeId\n input: $input\n taxClass: $taxClass\n idempotencyKey: $idempotencyKey\n overpayment: $overpayment\n ) {\n \n id\n code\n currencyCode\n total\n totalWithTax\n surcharges {\n id\n description\n sku\n price\n priceWithTax\n taxRate\n }\n\n }\n }\n";
|
|
198
207
|
export declare const REMOVE_ORDER_SURCHARGE_MUTATION = "\n mutation RemoveOrderSurcharge($orderId: ID!, $surchargeId: ID!, $idempotencyKey: String) {\n removeOrderSurcharge(\n orderId: $orderId\n surchargeId: $surchargeId\n idempotencyKey: $idempotencyKey\n ) {\n \n id\n code\n currencyCode\n total\n totalWithTax\n surcharges {\n id\n description\n sku\n price\n priceWithTax\n taxRate\n }\n\n }\n }\n";
|
|
199
208
|
export declare const REMOVE_ORDER_SURCHARGE_WITH_OVERPAYMENT_MUTATION = "\n mutation RemoveOrderSurchargeWithOverpayment(\n $orderId: ID!\n $surchargeId: ID!\n $idempotencyKey: String\n $overpayment: OrderOverpaymentChoice\n ) {\n removeOrderSurcharge(\n orderId: $orderId\n surchargeId: $surchargeId\n idempotencyKey: $idempotencyKey\n overpayment: $overpayment\n ) {\n \n id\n code\n currencyCode\n total\n totalWithTax\n surcharges {\n id\n description\n sku\n price\n priceWithTax\n taxRate\n }\n\n }\n }\n";
|
|
209
|
+
export declare const ADD_ORDER_SURCHARGE_WITH_CONSENT_MUTATION: string;
|
|
210
|
+
export declare const UPDATE_ORDER_SURCHARGE_WITH_CONSENT_MUTATION: string;
|
|
211
|
+
export declare const REMOVE_ORDER_SURCHARGE_WITH_CONSENT_MUTATION: string;
|
|
200
212
|
export declare const PREVIEW_ORDER_SURCHARGE_CHANGE_QUERY = "\n query PreviewOrderSurchargeChange($orderId: ID!, $change: OrderSurchargeChangeInput!) {\n previewOrderSurchargeChange(orderId: $orderId, change: $change) {\n currencyCode\n totalBefore\n totalAfter\n overpayment {\n amount\n currencyCode\n refund { available code message book }\n accountCredit { available code message book }\n }\n }\n }\n";
|
|
201
213
|
export declare function createSurchargesModule(transport: Transport): SurchargesModule;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { customerAgreedVariable, withCustomerAgreed } from '../payments/customer-consent.js';
|
|
1
2
|
import { storeCreditAware } from '../payments/store-credit-fields.js';
|
|
2
3
|
const SURCHARGED_ORDER_FIELDS = /* GraphQL */ `
|
|
3
4
|
id
|
|
@@ -121,6 +122,15 @@ export const REMOVE_ORDER_SURCHARGE_WITH_OVERPAYMENT_MUTATION = /* GraphQL */ `
|
|
|
121
122
|
}
|
|
122
123
|
}
|
|
123
124
|
`;
|
|
125
|
+
// A third document per write, used only on a call that states the customer's answer to store
|
|
126
|
+
// credit: an engine before the argument still takes every call that does not.
|
|
127
|
+
const CONSENT_ANCHOR = {
|
|
128
|
+
declaration: '$overpayment: OrderOverpaymentChoice',
|
|
129
|
+
argument: 'overpayment: $overpayment',
|
|
130
|
+
};
|
|
131
|
+
export const ADD_ORDER_SURCHARGE_WITH_CONSENT_MUTATION = withCustomerAgreed(ADD_ORDER_SURCHARGE_WITH_OVERPAYMENT_MUTATION, CONSENT_ANCHOR);
|
|
132
|
+
export const UPDATE_ORDER_SURCHARGE_WITH_CONSENT_MUTATION = withCustomerAgreed(UPDATE_ORDER_SURCHARGE_WITH_OVERPAYMENT_MUTATION, CONSENT_ANCHOR);
|
|
133
|
+
export const REMOVE_ORDER_SURCHARGE_WITH_CONSENT_MUTATION = withCustomerAgreed(REMOVE_ORDER_SURCHARGE_WITH_OVERPAYMENT_MUTATION, CONSENT_ANCHOR);
|
|
124
134
|
const OVERPAYMENT_OPTION_FIELDS = 'available code message book';
|
|
125
135
|
export const PREVIEW_ORDER_SURCHARGE_CHANGE_QUERY = /* GraphQL */ `
|
|
126
136
|
query PreviewOrderSurchargeChange($orderId: ID!, $change: OrderSurchargeChangeInput!) {
|
|
@@ -142,6 +152,12 @@ function overpaymentVariable(options) {
|
|
|
142
152
|
const value = options?.overpayment;
|
|
143
153
|
return value === 'REFUND' || value === 'ACCOUNT_CREDIT' ? value : undefined;
|
|
144
154
|
}
|
|
155
|
+
/** The document a write sends: the plainest one that declares every argument the call states. */
|
|
156
|
+
function surchargeDocument(options, documents) {
|
|
157
|
+
if (customerAgreedVariable(options?.customerAgreed) !== undefined)
|
|
158
|
+
return documents.consent;
|
|
159
|
+
return overpaymentVariable(options) === undefined ? documents.plain : documents.overpayment;
|
|
160
|
+
}
|
|
145
161
|
/**
|
|
146
162
|
* `undefined` rather than `null` for an absent tax class: a variable explicitly
|
|
147
163
|
* set to null is still a value the engine reads, and this argument's whole
|
|
@@ -156,15 +172,18 @@ export function createSurchargesModule(transport) {
|
|
|
156
172
|
async add(orderId, input, options) {
|
|
157
173
|
const data = await transport.graphql({
|
|
158
174
|
api: 'admin',
|
|
159
|
-
query:
|
|
160
|
-
|
|
161
|
-
: ADD_ORDER_SURCHARGE_WITH_OVERPAYMENT_MUTATION,
|
|
175
|
+
query: surchargeDocument(options, {
|
|
176
|
+
plain: ADD_ORDER_SURCHARGE_MUTATION,
|
|
177
|
+
overpayment: ADD_ORDER_SURCHARGE_WITH_OVERPAYMENT_MUTATION,
|
|
178
|
+
consent: ADD_ORDER_SURCHARGE_WITH_CONSENT_MUTATION,
|
|
179
|
+
}),
|
|
162
180
|
variables: {
|
|
163
181
|
orderId,
|
|
164
182
|
input,
|
|
165
183
|
taxClass: taxClassVariable(options),
|
|
166
184
|
idempotencyKey: options?.idempotencyKey,
|
|
167
185
|
overpayment: overpaymentVariable(options),
|
|
186
|
+
customerAgreed: customerAgreedVariable(options?.customerAgreed),
|
|
168
187
|
},
|
|
169
188
|
}, options);
|
|
170
189
|
return data.addOrderSurcharge;
|
|
@@ -172,9 +191,11 @@ export function createSurchargesModule(transport) {
|
|
|
172
191
|
async update(orderId, surchargeId, input, options) {
|
|
173
192
|
const data = await transport.graphql({
|
|
174
193
|
api: 'admin',
|
|
175
|
-
query:
|
|
176
|
-
|
|
177
|
-
: UPDATE_ORDER_SURCHARGE_WITH_OVERPAYMENT_MUTATION,
|
|
194
|
+
query: surchargeDocument(options, {
|
|
195
|
+
plain: UPDATE_ORDER_SURCHARGE_MUTATION,
|
|
196
|
+
overpayment: UPDATE_ORDER_SURCHARGE_WITH_OVERPAYMENT_MUTATION,
|
|
197
|
+
consent: UPDATE_ORDER_SURCHARGE_WITH_CONSENT_MUTATION,
|
|
198
|
+
}),
|
|
178
199
|
variables: {
|
|
179
200
|
orderId,
|
|
180
201
|
surchargeId,
|
|
@@ -182,6 +203,7 @@ export function createSurchargesModule(transport) {
|
|
|
182
203
|
taxClass: taxClassVariable(options),
|
|
183
204
|
idempotencyKey: options?.idempotencyKey,
|
|
184
205
|
overpayment: overpaymentVariable(options),
|
|
206
|
+
customerAgreed: customerAgreedVariable(options?.customerAgreed),
|
|
185
207
|
},
|
|
186
208
|
}, options);
|
|
187
209
|
return data.updateOrderSurcharge;
|
|
@@ -189,14 +211,17 @@ export function createSurchargesModule(transport) {
|
|
|
189
211
|
async remove(orderId, surchargeId, options) {
|
|
190
212
|
const data = await transport.graphql({
|
|
191
213
|
api: 'admin',
|
|
192
|
-
query:
|
|
193
|
-
|
|
194
|
-
: REMOVE_ORDER_SURCHARGE_WITH_OVERPAYMENT_MUTATION,
|
|
214
|
+
query: surchargeDocument(options, {
|
|
215
|
+
plain: REMOVE_ORDER_SURCHARGE_MUTATION,
|
|
216
|
+
overpayment: REMOVE_ORDER_SURCHARGE_WITH_OVERPAYMENT_MUTATION,
|
|
217
|
+
consent: REMOVE_ORDER_SURCHARGE_WITH_CONSENT_MUTATION,
|
|
218
|
+
}),
|
|
195
219
|
variables: {
|
|
196
220
|
orderId,
|
|
197
221
|
surchargeId,
|
|
198
222
|
idempotencyKey: options?.idempotencyKey,
|
|
199
223
|
overpayment: overpaymentVariable(options),
|
|
224
|
+
customerAgreed: customerAgreedVariable(options?.customerAgreed),
|
|
200
225
|
},
|
|
201
226
|
}, options);
|
|
202
227
|
return data.removeOrderSurcharge;
|
|
@@ -56,6 +56,17 @@ export interface CreditOverpaymentInput {
|
|
|
56
56
|
/** Why, in your own words: shown on the receipt and in the order's history. */
|
|
57
57
|
reason?: string;
|
|
58
58
|
}
|
|
59
|
+
/** Options of {@link AccountCreditModule.creditOverpaymentToStoreCredit}. */
|
|
60
|
+
export interface CreditOverpaymentToStoreCreditCall extends Call {
|
|
61
|
+
/**
|
|
62
|
+
* Whether the customer expressly agreed to store credit instead of a refund to their payment
|
|
63
|
+
* (EU consumer law, CRD art. 13(1)), as staff recorded it: the move records it on its ledger
|
|
64
|
+
* entries (`StoredValueEntry.customerAgreed`). Never a condition, nothing is refused for it.
|
|
65
|
+
* Part of the request: a repeat under the same key sends the same answer. Sent only when given;
|
|
66
|
+
* an engine before the argument (incentives sprint 8 PR 6a) refuses a call that gives it.
|
|
67
|
+
*/
|
|
68
|
+
customerAgreed?: boolean;
|
|
69
|
+
}
|
|
59
70
|
export interface ApplyUnappliedCashInput {
|
|
60
71
|
unappliedCashId: string;
|
|
61
72
|
/** The AR invoice to pay. Give exactly one of `invoiceId` and `orderId`. */
|
|
@@ -151,7 +162,7 @@ export interface AccountCreditModule {
|
|
|
151
162
|
* it off `refundable` and `payments.position` no longer reports it as `overpaid`. Needs an
|
|
152
163
|
* engine with incentives sprint 8 PR 3.
|
|
153
164
|
*/
|
|
154
|
-
creditOverpaymentToStoreCredit(input: CreditOverpaymentInput, options?:
|
|
165
|
+
creditOverpaymentToStoreCredit(input: CreditOverpaymentInput, options?: CreditOverpaymentToStoreCreditCall): Promise<StoreCreditMove>;
|
|
155
166
|
/** A customer's unapplied cash in this store, oldest first. */
|
|
156
167
|
list(customerId: string, options?: Call): Promise<UnappliedCash[]>;
|
|
157
168
|
/**
|
|
@@ -189,6 +200,11 @@ export interface AccountCreditModule {
|
|
|
189
200
|
}
|
|
190
201
|
export declare const CREDIT_ORDER_OVERPAYMENT_MUTATION = "\n mutation CreditOrderOverpaymentToAccount(\n $input: CreditOrderOverpaymentInput!\n $idempotencyKey: String\n ) {\n creditOrderOverpaymentToAccount(input: $input, idempotencyKey: $idempotencyKey) {\n \n id\n customerId\n currencyCode\n amount\n applied\n refunded\n remaining\n orderId\n paymentId\n receivedOn\n reference\n notes\n createdAt\n\n }\n }\n";
|
|
191
202
|
export declare const CREDIT_ORDER_OVERPAYMENT_TO_STORE_CREDIT_MUTATION = "\n mutation CreditOrderOverpaymentToStoreCredit(\n $input: CreditOrderOverpaymentInput!\n $idempotencyKey: String\n ) {\n creditOrderOverpaymentToStoreCredit(input: $input, idempotencyKey: $idempotencyKey) {\n accountId amount currencyCode entryIds\n }\n }\n";
|
|
203
|
+
/**
|
|
204
|
+
* The same, declaring the customer's answer to store credit: sent only by a call that states it,
|
|
205
|
+
* so an engine before the argument still takes every call that does not.
|
|
206
|
+
*/
|
|
207
|
+
export declare const CREDIT_ORDER_OVERPAYMENT_TO_STORE_CREDIT_WITH_CONSENT_MUTATION = "\n mutation CreditOrderOverpaymentToStoreCredit(\n $input: CreditOrderOverpaymentInput!\n $idempotencyKey: String\n $customerAgreed: Boolean\n ) {\n creditOrderOverpaymentToStoreCredit(\n input: $input\n idempotencyKey: $idempotencyKey\n customerAgreed: $customerAgreed\n ) {\n accountId amount currencyCode entryIds\n }\n }\n";
|
|
192
208
|
export declare const UNAPPLIED_CASH_QUERY = "\n query ArUnappliedCash($customerId: ID!) {\n arUnappliedCash(customerId: $customerId) {\n \n id\n customerId\n currencyCode\n amount\n applied\n refunded\n remaining\n orderId\n paymentId\n receivedOn\n reference\n notes\n createdAt\n\n }\n }\n";
|
|
193
209
|
export declare const APPLY_UNAPPLIED_CASH_MUTATION = "\n mutation ApplyArUnappliedCash($input: ApplyArUnappliedCashInput!, $idempotencyKey: String) {\n applyArUnappliedCash(input: $input, idempotencyKey: $idempotencyKey) {\n \n id\n customerId\n currencyCode\n amount\n applied\n refunded\n remaining\n orderId\n paymentId\n receivedOn\n reference\n notes\n createdAt\n\n }\n }\n";
|
|
194
210
|
export declare const REFUND_UNAPPLIED_CASH_MUTATION = "\n mutation RefundArUnappliedCash($input: RefundArUnappliedCashInput!, $idempotencyKey: String) {\n refundArUnappliedCash(input: $input, idempotencyKey: $idempotencyKey) {\n id\n total\n state\n method\n transactionId\n reason\n }\n }\n";
|