How to make PromptProductPurchase not deduct the robux when having error with ProcessReceipt?

Question: The processReceipt function will return “Enum.ProductPurchaseDecision.NotProcessedYet” when the handler or success return false, however I’m not sure why the player still got deduct robux when the processReceipt is error or not successful. (Sorry i’m not good in english)
Any ideas?

My code:

function processReceipt(receiptInfo)
	local playerProductKey = receiptInfo.PlayerId .. "_" .. receiptInfo.PurchaseId
	local purchased = false
	local success, errorMessage = pcall(function()
		purchased = purchaseHistoryStore:GetAsync(playerProductKey)
	end)

	if success and purchased then
		return Enum.ProductPurchaseDecision.PurchaseGranted
	elseif not success then
		error("Data store error:" .. errorMessage)
	end

	local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)

	if not player then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end

	local handler = productFunctions[receiptInfo.ProductId]

	local success, functionResult = pcall(function()
		return handler(receiptInfo, player)
	end)

	if success and functionResult then
		local dataSuccess, errorMessage = pcall(function()
			purchaseHistoryStore:SetAsync(playerProductKey, true)
		end)

		if not dataSuccess then
			error("Cannot save purchase data: " .. errorMessage)
		end

		return Enum.ProductPurchaseDecision.PurchaseGranted
	elseif success and not functionResult then
		print("Not Success Because Function Error")
		return Enum.ProductPurchaseDecision.NotProcessedYet
	elseif not success then
		print(functionResult)
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
end

MarketplaceService.ProcessReceipt = processReceipt
1 Like

Im having the same issue, I tried it in-game to see if it will deduct when the enum returned is NotProcessedYet. It still deducted.