diff --git a/core/ShopState.lua b/core/ShopState.lua index b1c1c95..275b834 100644 --- a/core/ShopState.lua +++ b/core/ShopState.lua @@ -165,6 +165,9 @@ end end end + if self.eventHooks and self.eventHooks.preStockCheck then + eventHook.execute(self.eventHooks.preStockCheck, transaction, productsPurchased, self.products) + end local available = amountPurchased for _, productPurchased in ipairs(productsPurchased) do local productSources, productAvailable = ScanInventory.findProductItems(self.products, productPurchased.product, productPurchased.quantity * amountPurchased) @@ -187,12 +190,14 @@ local err local errMessage if self.eventHooks and self.eventHooks.prePurchase then - allowPurchase, err, errMessage = eventHook.execute(self.eventHooks.prePurchase, purchasedProduct, available, refundAmount, transaction, transactionCurrency) + allowPurchase, err, errMessage, invisible = eventHook.execute(self.eventHooks.prePurchase, purchasedProduct, available, refundAmount, transaction, transactionCurrency) end if allowPurchase == false then - refund(transactionCurrency, transaction.from, meta, transaction.value, errMessage or self.config.lang.refundDenied, err) - if self.eventHooks and self.eventHooks.failedPurchase then - eventHook.execute(self.eventHooks.failedPurchase, transaction, transactionCurrency, purchasedProduct, errMessage or self.config.lang.refundDenied, err) + if not invisible then + refund(transactionCurrency, transaction.from, meta, transaction.value, errMessage or self.config.lang.refundDenied, err) + if self.eventHooks and self.eventHooks.failedPurchase then + eventHook.execute(self.eventHooks.failedPurchase, transaction, transactionCurrency, purchasedProduct, errMessage or self.config.lang.refundDenied, err) + end end return end diff --git a/eventHooks.lua b/eventHooks.lua index 1a18b9e..c5a12fe 100644 --- a/eventHooks.lua +++ b/eventHooks.lua @@ -4,7 +4,8 @@ -- If product is nil, product will be selected by the shop, -- If product is false, customer will be refunded for no product found. -- If product is false and errored is true, customer will be refunded with error message. - prePurchase = nil, -- function(product, amount, refundAmount, transaction, transactionCurrency) returns continueTransaction, errored, errorMessage + preStockCheck = nil, -- function(transaction, productsPurchased, products) + prePurchase = nil, -- function(product, amount, refundAmount, transaction, transactionCurrency) returns continueTransaction, errored, errorMessage, invisible purchase = nil, -- function(product, amount, refundAmount, transaction, transactionCurrency) failedPurchase = nil, -- function(transaction, transactionCurrency, product, errorMessage) programError = nil, -- function(err) diff --git a/radon.lua b/radon.lua index f2c022b..3419744 100644 --- a/radon.lua +++ b/radon.lua @@ -1,4 +1,4 @@ -local version = "1.3.25" +local version = "1.3.26" local configHelpers = require "util.configHelpers" local schemas = require "core.schemas" local ScanInventory = require("core.inventory.ScanInventory")