n8n-nodes-nexlogiq-commerce 1.0.2 → 1.0.3
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.
|
@@ -14,10 +14,10 @@ exports.refundOperations = [
|
|
|
14
14
|
},
|
|
15
15
|
options: [
|
|
16
16
|
{
|
|
17
|
-
name: 'Create
|
|
17
|
+
name: 'Create Full Refund',
|
|
18
18
|
value: 'create',
|
|
19
|
-
description: '
|
|
20
|
-
action: 'Create a refund',
|
|
19
|
+
description: 'Automatically refunds the entire order and restocks all items',
|
|
20
|
+
action: 'Create a full refund',
|
|
21
21
|
},
|
|
22
22
|
],
|
|
23
23
|
default: 'create',
|
|
@@ -36,102 +36,57 @@ exports.refundFields = [
|
|
|
36
36
|
operation: ['create'],
|
|
37
37
|
},
|
|
38
38
|
},
|
|
39
|
-
description: 'The ID of the order to refund',
|
|
39
|
+
description: 'The ID of the order to fully refund',
|
|
40
40
|
},
|
|
41
41
|
{
|
|
42
|
-
displayName: '
|
|
43
|
-
name: '
|
|
44
|
-
type: '
|
|
45
|
-
default:
|
|
42
|
+
displayName: 'Currency',
|
|
43
|
+
name: 'currency',
|
|
44
|
+
type: 'string',
|
|
45
|
+
default: 'USD',
|
|
46
46
|
displayOptions: {
|
|
47
47
|
show: {
|
|
48
48
|
resource: ['refund'],
|
|
49
49
|
operation: ['create'],
|
|
50
50
|
},
|
|
51
51
|
},
|
|
52
|
-
description: 'If true, it will calculate the full amount automatically',
|
|
53
52
|
},
|
|
54
53
|
{
|
|
55
|
-
displayName: '
|
|
56
|
-
name: '
|
|
57
|
-
type: '
|
|
58
|
-
default:
|
|
54
|
+
displayName: 'Notify Customer',
|
|
55
|
+
name: 'notify',
|
|
56
|
+
type: 'boolean',
|
|
57
|
+
default: true,
|
|
59
58
|
displayOptions: {
|
|
60
59
|
show: {
|
|
61
60
|
resource: ['refund'],
|
|
62
61
|
operation: ['create'],
|
|
63
|
-
fullRefund: [false],
|
|
64
62
|
},
|
|
65
63
|
},
|
|
64
|
+
description: 'Whether to send a refund notification email to the customer',
|
|
66
65
|
},
|
|
67
66
|
{
|
|
68
|
-
displayName: 'Refund
|
|
69
|
-
name: '
|
|
70
|
-
type: '
|
|
71
|
-
default:
|
|
72
|
-
typeOptions: {
|
|
73
|
-
multipleValues: true,
|
|
74
|
-
},
|
|
67
|
+
displayName: 'Refund Shipping',
|
|
68
|
+
name: 'refundShipping',
|
|
69
|
+
type: 'boolean',
|
|
70
|
+
default: true,
|
|
75
71
|
displayOptions: {
|
|
76
72
|
show: {
|
|
77
73
|
resource: ['refund'],
|
|
78
74
|
operation: ['create'],
|
|
79
|
-
fullRefund: [false],
|
|
80
75
|
},
|
|
81
76
|
},
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
displayName: 'Quantity',
|
|
96
|
-
name: 'quantity',
|
|
97
|
-
type: 'number',
|
|
98
|
-
default: 1,
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
displayName: 'Restock Type',
|
|
102
|
-
name: 'restock_type',
|
|
103
|
-
type: 'options',
|
|
104
|
-
options: [
|
|
105
|
-
{
|
|
106
|
-
name: 'Return (For fulfilled items)',
|
|
107
|
-
value: 'return',
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
name: 'Cancel (For unfulfilled items)',
|
|
111
|
-
value: 'cancel',
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
name: 'No Restock',
|
|
115
|
-
value: 'no_restock',
|
|
116
|
-
},
|
|
117
|
-
],
|
|
118
|
-
default: 'return',
|
|
119
|
-
description: 'How to handle the inventory restocking',
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
displayName: 'Location ID',
|
|
123
|
-
name: 'location_id',
|
|
124
|
-
type: 'string',
|
|
125
|
-
default: '',
|
|
126
|
-
displayOptions: {
|
|
127
|
-
hide: {
|
|
128
|
-
restock_type: ['no_restock'],
|
|
129
|
-
},
|
|
130
|
-
},
|
|
131
|
-
description: 'The ID of the location to restock the item. Map this dynamically from the Get Order node.',
|
|
132
|
-
},
|
|
133
|
-
],
|
|
77
|
+
description: 'Whether to also refund the shipping costs',
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
displayName: 'Reason (Note)',
|
|
81
|
+
name: 'note',
|
|
82
|
+
type: 'string',
|
|
83
|
+
default: '',
|
|
84
|
+
displayOptions: {
|
|
85
|
+
show: {
|
|
86
|
+
resource: ['refund'],
|
|
87
|
+
operation: ['create'],
|
|
134
88
|
},
|
|
135
|
-
|
|
89
|
+
},
|
|
90
|
+
description: 'An optional note attached to the refund (e.g., Requested by customer)',
|
|
136
91
|
},
|
|
137
92
|
];
|
|
@@ -319,37 +319,59 @@ class Shopify {
|
|
|
319
319
|
if (resource === 'refund') {
|
|
320
320
|
if (operation === 'create') {
|
|
321
321
|
const orderId = this.getNodeParameter('orderId', i);
|
|
322
|
-
const
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
restock_type: 'return',
|
|
348
|
-
})),
|
|
349
|
-
},
|
|
322
|
+
const currency = this.getNodeParameter('currency', i, 'USD');
|
|
323
|
+
const notify = this.getNodeParameter('notify', i, true);
|
|
324
|
+
const refundShipping = this.getNodeParameter('refundShipping', i, true);
|
|
325
|
+
const note = this.getNodeParameter('note', i, '');
|
|
326
|
+
// 1. جلب بيانات الطلب لمعرفة محتوياته
|
|
327
|
+
const orderData = await GenericFunctions_1.shopifyApiRequest.call(this, 'GET', `/orders/${orderId}.json`, {}, {});
|
|
328
|
+
const order = orderData.order;
|
|
329
|
+
// 2. جلب مستودعات المتجر لمعرفة الـ Location ID الافتراضي
|
|
330
|
+
const locationsData = await GenericFunctions_1.shopifyApiRequest.call(this, 'GET', '/locations.json', {}, {});
|
|
331
|
+
const defaultLocationId = locationsData.locations.find((l) => l.active)?.id || locationsData.locations[0].id;
|
|
332
|
+
// 3. بناء مصفوفة المنتجات المسترجعة مع تحديد المستودع الصحيح لكل منتج آلياً
|
|
333
|
+
const refundLineItems = order.line_items.map((item) => {
|
|
334
|
+
let locId = defaultLocationId;
|
|
335
|
+
// إذا تم شحن المنتج مسبقاً، يجب إعادته للمستودع الذي خرج منه
|
|
336
|
+
if (order.fulfillments && order.fulfillments.length > 0) {
|
|
337
|
+
const fulfillment = order.fulfillments.find((f) => f.line_items.some((li) => li.id === item.id));
|
|
338
|
+
if (fulfillment && fulfillment.location_id) {
|
|
339
|
+
locId = fulfillment.location_id;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
return {
|
|
343
|
+
line_item_id: item.id,
|
|
344
|
+
quantity: item.quantity,
|
|
345
|
+
restock_type: 'return', // إعادة المخزون
|
|
346
|
+
location_id: locId, // المستودع المكتشف آلياً
|
|
350
347
|
};
|
|
351
|
-
}
|
|
352
|
-
|
|
348
|
+
});
|
|
349
|
+
// 4. طلب "حساب المرتجع" من شوبيفاي لجلب المعاملات المالية (Transactions) لإرجاع الأموال حقيقةً
|
|
350
|
+
const calculatePayload = {
|
|
351
|
+
refund: {
|
|
352
|
+
shipping: { full_refund: refundShipping },
|
|
353
|
+
refund_line_items: refundLineItems,
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
const calculatedData = await GenericFunctions_1.shopifyApiRequest.call(this, 'POST', `/orders/${orderId}/refunds/calculate.json`, calculatePayload, {});
|
|
357
|
+
const transactions = calculatedData.refund.transactions || [];
|
|
358
|
+
// 5. إرسال أمر الاسترجاع الكلي النهائي (الأموال + المنتجات)
|
|
359
|
+
const finalRefundPayload = {
|
|
360
|
+
refund: {
|
|
361
|
+
currency: currency,
|
|
362
|
+
notify: notify,
|
|
363
|
+
note: note,
|
|
364
|
+
shipping: { full_refund: refundShipping },
|
|
365
|
+
refund_line_items: refundLineItems,
|
|
366
|
+
transactions: transactions.map((t) => ({
|
|
367
|
+
parent_id: t.parent_id,
|
|
368
|
+
amount: t.amount,
|
|
369
|
+
kind: 'refund',
|
|
370
|
+
gateway: t.gateway
|
|
371
|
+
}))
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
responseData = await GenericFunctions_1.shopifyApiRequest.call(this, 'POST', `/orders/${orderId}/refunds.json`, finalRefundPayload, {});
|
|
353
375
|
responseData = responseData.refund;
|
|
354
376
|
}
|
|
355
377
|
}
|
|
@@ -13,10 +13,10 @@ export const refundOperations: INodeProperties[] = [
|
|
|
13
13
|
},
|
|
14
14
|
options: [
|
|
15
15
|
{
|
|
16
|
-
name: 'Create
|
|
16
|
+
name: 'Create Full Refund',
|
|
17
17
|
value: 'create',
|
|
18
|
-
description: '
|
|
19
|
-
action: 'Create a refund',
|
|
18
|
+
description: 'Automatically refunds the entire order and restocks all items',
|
|
19
|
+
action: 'Create a full refund',
|
|
20
20
|
},
|
|
21
21
|
],
|
|
22
22
|
default: 'create',
|
|
@@ -36,102 +36,57 @@ export const refundFields: INodeProperties[] = [
|
|
|
36
36
|
operation: ['create'],
|
|
37
37
|
},
|
|
38
38
|
},
|
|
39
|
-
description: 'The ID of the order to refund',
|
|
39
|
+
description: 'The ID of the order to fully refund',
|
|
40
40
|
},
|
|
41
41
|
{
|
|
42
|
-
displayName: '
|
|
43
|
-
name: '
|
|
44
|
-
type: '
|
|
45
|
-
default:
|
|
42
|
+
displayName: 'Currency',
|
|
43
|
+
name: 'currency',
|
|
44
|
+
type: 'string',
|
|
45
|
+
default: 'USD',
|
|
46
46
|
displayOptions: {
|
|
47
47
|
show: {
|
|
48
48
|
resource: ['refund'],
|
|
49
49
|
operation: ['create'],
|
|
50
50
|
},
|
|
51
51
|
},
|
|
52
|
-
description: 'If true, it will calculate the full amount automatically',
|
|
53
52
|
},
|
|
54
53
|
{
|
|
55
|
-
displayName: '
|
|
56
|
-
name: '
|
|
57
|
-
type: '
|
|
58
|
-
default:
|
|
54
|
+
displayName: 'Notify Customer',
|
|
55
|
+
name: 'notify',
|
|
56
|
+
type: 'boolean',
|
|
57
|
+
default: true,
|
|
59
58
|
displayOptions: {
|
|
60
59
|
show: {
|
|
61
60
|
resource: ['refund'],
|
|
62
61
|
operation: ['create'],
|
|
63
|
-
fullRefund: [false],
|
|
64
62
|
},
|
|
65
63
|
},
|
|
64
|
+
description: 'Whether to send a refund notification email to the customer',
|
|
66
65
|
},
|
|
67
66
|
{
|
|
68
|
-
displayName: 'Refund
|
|
69
|
-
name: '
|
|
70
|
-
type: '
|
|
71
|
-
default:
|
|
72
|
-
typeOptions: {
|
|
73
|
-
multipleValues: true,
|
|
74
|
-
},
|
|
67
|
+
displayName: 'Refund Shipping',
|
|
68
|
+
name: 'refundShipping',
|
|
69
|
+
type: 'boolean',
|
|
70
|
+
default: true,
|
|
75
71
|
displayOptions: {
|
|
76
72
|
show: {
|
|
77
73
|
resource: ['refund'],
|
|
78
74
|
operation: ['create'],
|
|
79
|
-
fullRefund: [false],
|
|
80
75
|
},
|
|
81
76
|
},
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
displayName: 'Quantity',
|
|
96
|
-
name: 'quantity',
|
|
97
|
-
type: 'number',
|
|
98
|
-
default: 1,
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
displayName: 'Restock Type',
|
|
102
|
-
name: 'restock_type',
|
|
103
|
-
type: 'options',
|
|
104
|
-
options: [
|
|
105
|
-
{
|
|
106
|
-
name: 'Return (For fulfilled items)',
|
|
107
|
-
value: 'return',
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
name: 'Cancel (For unfulfilled items)',
|
|
111
|
-
value: 'cancel',
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
name: 'No Restock',
|
|
115
|
-
value: 'no_restock',
|
|
116
|
-
},
|
|
117
|
-
],
|
|
118
|
-
default: 'return',
|
|
119
|
-
description: 'How to handle the inventory restocking',
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
displayName: 'Location ID',
|
|
123
|
-
name: 'location_id',
|
|
124
|
-
type: 'string',
|
|
125
|
-
default: '',
|
|
126
|
-
displayOptions: {
|
|
127
|
-
hide: {
|
|
128
|
-
restock_type: ['no_restock'],
|
|
129
|
-
},
|
|
130
|
-
},
|
|
131
|
-
description: 'The ID of the location to restock the item. Map this dynamically from the Get Order node.',
|
|
132
|
-
},
|
|
133
|
-
],
|
|
77
|
+
description: 'Whether to also refund the shipping costs',
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
displayName: 'Reason (Note)',
|
|
81
|
+
name: 'note',
|
|
82
|
+
type: 'string',
|
|
83
|
+
default: '',
|
|
84
|
+
displayOptions: {
|
|
85
|
+
show: {
|
|
86
|
+
resource: ['refund'],
|
|
87
|
+
operation: ['create'],
|
|
134
88
|
},
|
|
135
|
-
|
|
89
|
+
},
|
|
90
|
+
description: 'An optional note attached to the refund (e.g., Requested by customer)',
|
|
136
91
|
},
|
|
137
92
|
];
|
|
@@ -350,46 +350,73 @@ export class Shopify implements INodeType {
|
|
|
350
350
|
// =========================================================
|
|
351
351
|
// Refund
|
|
352
352
|
// =========================================================
|
|
353
|
+
|
|
353
354
|
if (resource === 'refund') {
|
|
354
355
|
if (operation === 'create') {
|
|
355
356
|
const orderId = this.getNodeParameter('orderId', i) as string;
|
|
356
|
-
const
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
})),
|
|
385
|
-
},
|
|
357
|
+
const currency = this.getNodeParameter('currency', i, 'USD') as string;
|
|
358
|
+
const notify = this.getNodeParameter('notify', i, true) as boolean;
|
|
359
|
+
const refundShipping = this.getNodeParameter('refundShipping', i, true) as boolean;
|
|
360
|
+
const note = this.getNodeParameter('note', i, '') as string;
|
|
361
|
+
|
|
362
|
+
// 1. جلب بيانات الطلب لمعرفة محتوياته
|
|
363
|
+
const orderData = await shopifyApiRequest.call(this, 'GET', `/orders/${orderId}.json`, {}, {});
|
|
364
|
+
const order = (orderData as any).order;
|
|
365
|
+
|
|
366
|
+
// 2. جلب مستودعات المتجر لمعرفة الـ Location ID الافتراضي
|
|
367
|
+
const locationsData = await shopifyApiRequest.call(this, 'GET', '/locations.json', {}, {});
|
|
368
|
+
const defaultLocationId = (locationsData as any).locations.find((l: any) => l.active)?.id || (locationsData as any).locations[0].id;
|
|
369
|
+
|
|
370
|
+
// 3. بناء مصفوفة المنتجات المسترجعة مع تحديد المستودع الصحيح لكل منتج آلياً
|
|
371
|
+
const refundLineItems = order.line_items.map((item: any) => {
|
|
372
|
+
let locId = defaultLocationId;
|
|
373
|
+
// إذا تم شحن المنتج مسبقاً، يجب إعادته للمستودع الذي خرج منه
|
|
374
|
+
if (order.fulfillments && order.fulfillments.length > 0) {
|
|
375
|
+
const fulfillment = order.fulfillments.find((f: any) => f.line_items.some((li: any) => li.id === item.id));
|
|
376
|
+
if (fulfillment && fulfillment.location_id) {
|
|
377
|
+
locId = fulfillment.location_id;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return {
|
|
381
|
+
line_item_id: item.id,
|
|
382
|
+
quantity: item.quantity,
|
|
383
|
+
restock_type: 'return', // إعادة المخزون
|
|
384
|
+
location_id: locId, // المستودع المكتشف آلياً
|
|
386
385
|
};
|
|
387
|
-
}
|
|
388
|
-
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
// 4. طلب "حساب المرتجع" من شوبيفاي لجلب المعاملات المالية (Transactions) لإرجاع الأموال حقيقةً
|
|
389
|
+
const calculatePayload = {
|
|
390
|
+
refund: {
|
|
391
|
+
shipping: { full_refund: refundShipping },
|
|
392
|
+
refund_line_items: refundLineItems,
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
const calculatedData = await shopifyApiRequest.call(this, 'POST', `/orders/${orderId}/refunds/calculate.json`, calculatePayload, {});
|
|
396
|
+
const transactions = (calculatedData as any).refund.transactions || [];
|
|
397
|
+
|
|
398
|
+
// 5. إرسال أمر الاسترجاع الكلي النهائي (الأموال + المنتجات)
|
|
399
|
+
const finalRefundPayload = {
|
|
400
|
+
refund: {
|
|
401
|
+
currency: currency,
|
|
402
|
+
notify: notify,
|
|
403
|
+
note: note,
|
|
404
|
+
shipping: { full_refund: refundShipping },
|
|
405
|
+
refund_line_items: refundLineItems,
|
|
406
|
+
transactions: transactions.map((t: any) => ({
|
|
407
|
+
parent_id: t.parent_id,
|
|
408
|
+
amount: t.amount,
|
|
409
|
+
kind: 'refund',
|
|
410
|
+
gateway: t.gateway
|
|
411
|
+
}))
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
responseData = await shopifyApiRequest.call(this, 'POST', `/orders/${orderId}/refunds.json`, finalRefundPayload, {});
|
|
389
416
|
responseData = (responseData as any).refund;
|
|
390
417
|
}
|
|
391
418
|
}
|
|
392
|
-
|
|
419
|
+
|
|
393
420
|
// =========================================================
|
|
394
421
|
// Product
|
|
395
422
|
// =========================================================
|
|
@@ -466,4 +493,4 @@ export class Shopify implements INodeType {
|
|
|
466
493
|
|
|
467
494
|
return [returnData];
|
|
468
495
|
}
|
|
469
|
-
}
|
|
496
|
+
}
|