@ns8/ns8-shopify-switches
Advanced tools
Comparing version 1.0.152 to 1.0.153
@@ -18,3 +18,3 @@ "use strict"; | ||
exports.orderCanBeCanceled = orderCanBeCanceled; | ||
const cancelFullyPaidOrder = async (shopifyClient, order) => { | ||
const cancelFullyPaidOrder = async (shopifyClient, order, email = false) => { | ||
const { id, total_price_set: { presentment_money: { amount, currency_code: currency, }, }, } = order; | ||
@@ -24,4 +24,5 @@ const params = { | ||
currency, | ||
email, | ||
restock: true, | ||
reason: 'fraud', | ||
email: false, | ||
}; | ||
@@ -32,10 +33,10 @@ const results = await shopifyClient.order.cancel(id, Object.assign({}, params)) | ||
}; | ||
const cancelRefundedOrder = async (shopifyClient, orderId) => { | ||
const results = await shopifyClient.order.cancel(orderId, { reason: 'fraud', email: false }) | ||
const cancelRefundedOrder = async (shopifyClient, orderId, email = false) => { | ||
const results = await shopifyClient.order.cancel(orderId, { email, restock: true, reason: 'fraud' }) | ||
.catch((error) => new Error(`Unable to cancel refunded order. ${JSON.stringify(error)}`)); | ||
return results instanceof Error ? results : 'Refunded order canceled.'; | ||
}; | ||
const cancelUnpaidOrder = async (shopifyClient, orderId) => (await shopifyClient.order.cancel(orderId, { reason: 'fraud', email: false }) | ||
const cancelUnpaidOrder = async (shopifyClient, orderId, email = false) => (await shopifyClient.order.cancel(orderId, { email, restock: true, reason: 'fraud' }) | ||
.catch((error) => new Error(`Unable to cancel unpaid order. ${JSON.stringify(error)}`))); | ||
const voidAuthorizedOrder = async (shopifyClient, order) => { | ||
const voidAuthorizedOrder = async (shopifyClient, order, email = false) => { | ||
let returnMessage; | ||
@@ -62,3 +63,3 @@ let voidTransactionResults; | ||
} | ||
cancelOrderResults = await cancelUnpaidOrder(shopifyClient, id); | ||
cancelOrderResults = await cancelUnpaidOrder(shopifyClient, id, email); | ||
if (cancelOrderResults instanceof Error) { | ||
@@ -72,3 +73,3 @@ returnMessage = `${returnMessage} --- ${cancelOrderResults}`; | ||
}; | ||
const cancelShopifyOrder = async (shopifyClient, orderId) => { | ||
const cancelShopifyOrder = async (shopifyClient, orderId, emailOnCancel = false) => { | ||
let returnMessage; | ||
@@ -82,9 +83,9 @@ const order = await getOrder(shopifyClient, orderId); | ||
if (financial_status === 'paid') { | ||
returnMessage = await cancelFullyPaidOrder(shopifyClient, order); | ||
returnMessage = await cancelFullyPaidOrder(shopifyClient, order, emailOnCancel); | ||
} | ||
else if (financial_status === 'refunded') { | ||
returnMessage = await cancelRefundedOrder(shopifyClient, orderId); | ||
returnMessage = await cancelRefundedOrder(shopifyClient, orderId, emailOnCancel); | ||
} | ||
else { | ||
returnMessage = await voidAuthorizedOrder(shopifyClient, order); | ||
returnMessage = await voidAuthorizedOrder(shopifyClient, order, emailOnCancel); | ||
} | ||
@@ -91,0 +92,0 @@ } |
@@ -25,3 +25,3 @@ "use strict"; | ||
if (status === ns8_protect_models_1.Status.CANCELLED) { | ||
cancelShopifyOrderResults = await cancelShopifyOrder_1.default(client, orderId); | ||
cancelShopifyOrderResults = await cancelShopifyOrder_1.default(client, orderId, profile.emailOnCancel); | ||
console.log('cancelShopifyOrderResults', cancelShopifyOrderResults.toString()); | ||
@@ -28,0 +28,0 @@ } |
{ | ||
"name": "@ns8/ns8-shopify-switches", | ||
"version": "1.0.152", | ||
"version": "1.0.153", | ||
"description": "Custom switches for the shopify integration", | ||
@@ -34,6 +34,6 @@ "main": "dist/index.js", | ||
"isomorphic-fetch": "^2.2.1", | ||
"ns8-protect-models": "^1.0.187", | ||
"ns8-switchboard-interfaces": "^1.0.71", | ||
"ns8-protect-models": "^1.0.190", | ||
"ns8-switchboard-interfaces": "^1.0.72", | ||
"shopify-api-node": "2.20.1" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
72356
850