@porulle/adapter-woocommerce 0.76.0 → 0.77.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/dist/orders.d.ts +4 -0
- package/dist/orders.js +15 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/webhooks.js +6 -0
- package/package.json +4 -4
- package/src/orders.ts +14 -1
- package/src/webhooks.ts +6 -0
package/dist/orders.d.ts
CHANGED
|
@@ -18,6 +18,10 @@ export declare const wooOrderSchema: z.ZodObject<{
|
|
|
18
18
|
quantity: z.ZodNumber;
|
|
19
19
|
total: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
20
20
|
}, z.core.$strip>>>;
|
|
21
|
+
shipping_lines: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
22
|
+
id: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<string, string | number>>;
|
|
23
|
+
total: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
24
|
+
}, z.core.$strip>>>;
|
|
21
25
|
refunds: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
22
26
|
id: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<string, string | number>>;
|
|
23
27
|
total: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
package/dist/orders.js
CHANGED
|
@@ -10,6 +10,7 @@ export const wooOrderSchema = z.object({
|
|
|
10
10
|
date_created_gmt: z.string().nullish(),
|
|
11
11
|
meta_data: z.array(z.object({ key: z.string(), value: z.unknown() })).default([]),
|
|
12
12
|
line_items: z.array(z.object({ id, product_id: id, variation_id: id, quantity: z.number(), total: z.string().nullish() })).default([]),
|
|
13
|
+
shipping_lines: z.array(z.object({ id, total: z.string().nullish() })).default([]),
|
|
13
14
|
refunds: z.array(z.object({ id, total: z.string().nullish() })).default([]),
|
|
14
15
|
});
|
|
15
16
|
/** The meta key naming the marketplace order a store order was created for: how a retry finds it. */
|
|
@@ -97,7 +98,12 @@ export async function pushOrder(client, slice, options) {
|
|
|
97
98
|
}
|
|
98
99
|
const currency = slice.currency;
|
|
99
100
|
const decimals = client.credentials.priceDecimals;
|
|
100
|
-
|
|
101
|
+
// The platform's own per-line discount when it sends one, so the store's line totals are what the
|
|
102
|
+
// platform refunds a line at; otherwise the slice's discount split here.
|
|
103
|
+
const shares = slice.lines.map((line) => line.discountAmount ?? 0);
|
|
104
|
+
const discounts = slice.discount !== undefined && shares.reduce((sum, share) => sum + share, 0) === slice.discount.amount
|
|
105
|
+
? shares
|
|
106
|
+
: allocate(slice.lines.map((line) => line.totalPrice), slice.discount?.amount ?? 0);
|
|
101
107
|
const [firstName = "", ...rest] = slice.customer.name.trim().split(/\s+/);
|
|
102
108
|
const source = slice.customer.shippingAddress;
|
|
103
109
|
const address = {
|
|
@@ -204,6 +210,14 @@ export async function recordRefund(client, remoteId, input) {
|
|
|
204
210
|
return Err({ code: "CHANNEL_MAPPING_MISSING", message: `Order ${remoteId} has no line for ${line.externalVariantId}.`, retriable: false });
|
|
205
211
|
lineItems.push({ id: storeLine.id, quantity: line.quantity, refund_total: moneyString(line.amount, currency, decimals) });
|
|
206
212
|
}
|
|
213
|
+
// Delivery is refunded against the order's shipping item, as wp-admin does it.
|
|
214
|
+
const shippingAmount = input.shippingAmount ?? 0;
|
|
215
|
+
if (shippingAmount > 0) {
|
|
216
|
+
const shippingLine = order.shipping_lines[0];
|
|
217
|
+
if (!shippingLine)
|
|
218
|
+
return Err({ code: "CHANNEL_MAPPING_MISSING", message: `Order ${remoteId} has no delivery line to refund.`, retriable: false });
|
|
219
|
+
lineItems.push({ id: shippingLine.id, quantity: 0, refund_total: moneyString(shippingAmount, currency, decimals) });
|
|
220
|
+
}
|
|
207
221
|
const created = await client.send("POST", `/wc/v3/orders/${encodeURIComponent(remoteId)}/refunds`, {
|
|
208
222
|
amount: moneyString(input.amount, currency, decimals),
|
|
209
223
|
reason: input.reason,
|