local function v(v)local N=v.PlayerId..("\095"..v.PurchaseId)local u=false local j,a=pcall(function()u=purchaseHistoryStore:GetAsync(N)end)if j and u then return Enum.ProductPurchaseDecision.PurchaseGranted end local l=Players:GetPlayerByUserId(v.PlayerId)if not l then return Enum.ProductPurchaseDecision.NotProcessedYet end local J=_G.HandlePurchase local q,h=pcall(J,v,v.PlayerId)if not q or not h 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",l)_G.FinishedPurchase(v.PlayerId,0,false)return Enum.ProductPurchaseDecision.NotProcessedYet end local T,K=pcall(function()purchaseHistoryStore:SetAsync(N,true)end)if not T 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 "..K)end return Enum.ProductPurchaseDecision.PurchaseGranted end
-- The core 'ProcessReceipt' callback function
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
	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

	-- Look up handler function from 'productFunctions' table above
	local handler = _G.HandlePurchase

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

		_G.FinishedPurchase(receiptInfo.PlayerId, 0, false)

		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
