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 (Money Back)',
17
+ name: 'Create Full Refund',
18
18
  value: 'create',
19
- description: 'Refund a transaction to the customer',
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: 'Full Refund?',
43
- name: 'fullRefund',
44
- type: 'boolean',
45
- default: false,
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: 'Currency',
56
- name: 'currency',
57
- type: 'string',
58
- default: 'USD',
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 Line Items',
69
- name: 'refund_line_items',
70
- type: 'fixedCollection',
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
- options: [
83
- {
84
- displayName: 'Items',
85
- name: 'item',
86
- values: [
87
- {
88
- displayName: 'Line Item ID',
89
- name: 'line_item_id',
90
- type: 'string',
91
- default: '',
92
- description: 'The ID of the product line item in the order',
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 fullRefund = this.getNodeParameter('fullRefund', i);
323
- let body = {};
324
- if (fullRefund) {
325
- const orderData = await GenericFunctions_1.shopifyApiRequest.call(this, 'GET', `/orders/${orderId}.json`, {}, {});
326
- const order = orderData.order;
327
- body = {
328
- refund: {
329
- currency: order.currency,
330
- refund_line_items: order.line_items.map((item) => ({
331
- line_item_id: item.id,
332
- quantity: item.quantity,
333
- restock_type: 'return',
334
- })),
335
- },
336
- };
337
- }
338
- else {
339
- const lineItems = this.getNodeParameter('refund_line_items', i);
340
- const currency = this.getNodeParameter('currency', i);
341
- body = {
342
- refund: {
343
- currency: currency,
344
- refund_line_items: lineItems.item.map((item) => ({
345
- line_item_id: item.line_item_id,
346
- quantity: item.quantity,
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
- responseData = await GenericFunctions_1.shopifyApiRequest.call(this, 'POST', `/orders/${orderId}/refunds.json`, body, {});
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 (Money Back)',
16
+ name: 'Create Full Refund',
17
17
  value: 'create',
18
- description: 'Refund a transaction to the customer',
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: 'Full Refund?',
43
- name: 'fullRefund',
44
- type: 'boolean',
45
- default: false,
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: 'Currency',
56
- name: 'currency',
57
- type: 'string',
58
- default: 'USD',
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 Line Items',
69
- name: 'refund_line_items',
70
- type: 'fixedCollection',
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
- options: [
83
- {
84
- displayName: 'Items',
85
- name: 'item',
86
- values: [
87
- {
88
- displayName: 'Line Item ID',
89
- name: 'line_item_id',
90
- type: 'string',
91
- default: '',
92
- description: 'The ID of the product line item in the order',
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 fullRefund = this.getNodeParameter('fullRefund', i) as boolean;
357
- let body: IDataObject = {};
358
-
359
- if (fullRefund) {
360
- const orderData = await shopifyApiRequest.call(this, 'GET', `/orders/${orderId}.json`, {}, {});
361
- const order = orderData.order;
362
-
363
- body = {
364
- refund: {
365
- currency: order.currency,
366
- refund_line_items: order.line_items.map((item: any) => ({
367
- line_item_id: item.id,
368
- quantity: item.quantity,
369
- restock_type: 'return',
370
- })),
371
- },
372
- };
373
- } else {
374
- const lineItems = this.getNodeParameter('refund_line_items', i) as IDataObject;
375
- const currency = this.getNodeParameter('currency', i) as string;
376
-
377
- body = {
378
- refund: {
379
- currency: currency,
380
- refund_line_items: (lineItems.item as any[]).map((item) => ({
381
- line_item_id: item.line_item_id,
382
- quantity: item.quantity,
383
- restock_type: 'return',
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
- responseData = await shopifyApiRequest.call(this, 'POST', `/orders/${orderId}/refunds.json`, body, {});
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-nexlogiq-commerce",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Custom n8n nodes for Shopify, WooCommerce, and NexlogiqCommerce",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",