diff --git a/core/ShopState.lua b/core/ShopState.lua index 275b834..55a6f60 100644 --- a/core/ShopState.lua +++ b/core/ShopState.lua @@ -166,7 +166,16 @@ end end if self.eventHooks and self.eventHooks.preStockCheck then - eventHook.execute(self.eventHooks.preStockCheck, transaction, productsPurchased, self.products) + local allowPurchase, err, errMessage, invisible = eventHook.execute(self.eventHooks.preStockCheck, transaction, productsPurchased, self.products) + if allowPurchase == false then + 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 end local available = amountPurchased for _, productPurchased in ipairs(productsPurchased) do diff --git a/eventHooks.lua b/eventHooks.lua index c5a12fe..49c6c51 100644 --- a/eventHooks.lua +++ b/eventHooks.lua @@ -4,7 +4,7 @@ -- 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. - preStockCheck = nil, -- function(transaction, productsPurchased, products) + preStockCheck = nil, -- function(transaction, productsPurchased, products) returns continueTransaction, errored, errorMessage, invisible 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)