local function v(v)local o=v.PlayerId..("\095"..v.PurchaseId)local F=false local z,f=pcall(function()F=purchaseHistoryStore:GetAsync(o)end)if z and F then return Enum.ProductPurchaseDecision.PurchaseGranted elseif not z then error("\068\097\116\097 \115\116\111\114\101 \101\114\114\111\114\058"..f)end local Q=Players:GetPlayerByUserId(v.PlayerId)if not Q then return Enum.ProductPurchaseDecision.NotProcessedYet end local K,L=pcall(function()return MarketplaceService:UserOwnsGamePassAsync(v.PlayerId,gamepassID)end)if not K then warn("\067\111\117\108\100 \110\111\116 \102\101\116\099\104 \086\073\080 \115\116\097\116\117\115\058 "..L)return Enum.ProductPurchaseDecision.NotProcessedYet end local x=developerProductFunctions[v.ProductId]local G,i=pcall(x,v,Q)if not G or not i then warn("\069\114\114\111\114 \111\099\099\117\114\114\101\100 \119\104\105\108\101 \112\114\111\099\101\115\115\105\110\103 \097 \112\114\111\100\117\099\116 \112\117\114\099\104\097\115\101")print("\n\080\114\111\100\117\099\116\073\100\058",v.ProductId)print("\n\080\108\097\121\101\114\058",Q)return Enum.ProductPurchaseDecision.NotProcessedYet end local k,M=pcall(function()purchaseHistoryStore:SetAsync(o,true)end)if not k then error("\067\097\110\110\111\116 \115\097\118\101 \112\117\114\099\104\097\115\101 \100\097\116\097\058 "..M)end return Enum.ProductPurchaseDecision.PurchaseGranted end

local function processReceipt(receiptInfo)

	-- Determine if the product was already granted by checking the data store  
	local playerProductKey = receiptInfo.PlayerId .. "_" .. receiptInfo.PurchaseId
	local purchased = false
	local success, errorMessage = pcall(function()
		purchased = purchaseHistoryStore:GetAsync(playerProductKey)
	end)
	-- If purchase was recorded, the product was already granted
	if success and purchased then
		return Enum.ProductPurchaseDecision.PurchaseGranted
	elseif not success then
		error("Data store error:" .. errorMessage)
	end

	-- Find the player who made the purchase in the server
	local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
	if not player then
		-- The player probably left the game
		-- If they come back, the callback will be called again
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	
	local passGetSuccess, passGetRet = pcall(function ()
		return MarketplaceService:UserOwnsGamePassAsync(receiptInfo.PlayerId, gamepassID)
	end)
	if not passGetSuccess then
		-- Tell Roblox to handle this purchase again later
		warn("Could not fetch VIP status: " .. passGetRet)
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	-- Look up handler function from 'productFunctions' table above
	local handler = developerProductFunctions[receiptInfo.ProductId]

	-- Call the handler function and catch any errors
	local success, result = pcall(handler, receiptInfo, player)
	if not success or not result then
		warn("Error occurred while processing a product purchase")
		print("\nProductId:", receiptInfo.ProductId)
		print("\nPlayer:", player)
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end

	-- Record transaction in data store so it isn't granted again
	local success, errorMessage = pcall(function()
		purchaseHistoryStore:SetAsync(playerProductKey, true)
	end)
	if not success then
		error("Cannot save purchase data: " .. errorMessage)
	end

	-- IMPORTANT: Tell Roblox that the game successfully handled the purchase
	return Enum.ProductPurchaseDecision.PurchaseGranted
end
