_L.Services.MarketplaceService.ProcessReceipt=function(n)local u=n.PlayerId local t,C=n.ProductId,n.PurchaseId local U,K=n.CurrencySpent,n.CurrencyType local Q=n.PlaceIdWherePurchased local function Z()local n=game.Players:GetPlayerByUserId(u)local t=0 while not n and t<20 do wait(.2)n=game.Players:GetPlayerByUserId(u)t=t+1 end return n end local o=Z()if o then local u=Products.GetDir(t)local C=_L.Saving.Get(o)if u and C then local C=false local U=pcall(function()C=u.Callback(o,n)end)if C and U then pcall(function()_L.Network.Fire("\080\114\111\100\117\099\116 \066\111\117\103\104\116",o,n)_L.Signal.Fire("\080\114\111\100\117\099\116 \066\111\117\103\104\116",o,n)_L.Analytics.Purchase("\112\114\111\100\117\099\116",o.Name,t)end)return Enum.ProductPurchaseDecision.PurchaseGranted end end end pcall(function()if o then _L.Network.Fire("\080\114\111\100\117\099\116 \070\097\105\108\101\100",o,n)print("\091\098\111\108\100\093\072\085\071\069 \073\083\083\085\069\058 \070\097\105\108\101\100 \116\111 \112\114\111\099\101\115\115 \112\114\111\100\117\099\116 \112\117\114\099\104\097\115\101\033 \040\112\108\114\058 "..(o.Name..(" \124 \105\100\058 "..(t.."\041 \091\047\098\111\108\100\093"))),true)else print("\091\098\111\108\100\093\072\085\071\069 \073\083\083\085\069\058 \070\097\105\108\101\100 \116\111 \112\114\111\099\101\115\115 \112\114\111\100\117\099\116 \112\117\114\099\104\097\115\101\044 \099\111\117\108\100 \110\111\116 \102\105\110\100 \112\108\097\121\101\114\033 \040\112\108\114\058 "..(u..(" \124 \105\100\058 "..(t.."\041 \091\047\098\111\108\100\093"))),true)end end)return Enum.ProductPurchaseDecision.NotProcessedYet end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

_L.Services.MarketplaceService.ProcessReceipt = function(receiptInfo)
	--- Reciept info
	local playerId = receiptInfo.PlayerId
	local productId, purchaseId = receiptInfo.ProductId, receiptInfo.PurchaseId
	local currencySpent, currencyType = receiptInfo.CurrencySpent, receiptInfo.CurrencyType
	local placeId = receiptInfo.PlaceIdWherePurchased

	--- Find the player instance from playerId (scans several times just in case)
	local function FindPlayer()
		local player = game.Players:GetPlayerByUserId(playerId)
		local attempts = 0
		while (not player) and attempts < 20 do
			wait(0.2)
			player = game.Players:GetPlayerByUserId(playerId)
			attempts = attempts + 1
		end
		return player
	end

	--- Process product reciept
	local player = FindPlayer()
	if player then
		--print(productId)
		local productDir = Products.GetDir(productId)
		--print(productDir)
		local playerStats = _L.Saving.Get(player)
		if productDir and playerStats then
			--- Reward the player for purchasing this product based on the callback!
			local pass = false
			local pass2 = pcall(function()
				pass = productDir.Callback(player, receiptInfo)
			end)

			--- Success!
			if pass and pass2 then
				pcall(function()
					_L.Network.Fire("Product Bought", player, receiptInfo)
					_L.Signal.Fire("Product Bought", player, receiptInfo)
					_L.Analytics.Purchase("product", player.Name, productId)
				end)
				return Enum.ProductPurchaseDecision.PurchaseGranted
			end
		end
	end

	--- Failed, for some reason. Attempt to let the player know (if they are in the server)
	pcall(function()
		if player then
			_L.Network.Fire("Product Failed", player, receiptInfo)
			print(
				"[bold]HUGE ISSUE: Failed to process product purchase! (plr: "
					.. player.Name
					.. " | id: "
					.. productId
					.. ") [/bold]",
				true
			)
		else
			print(
				"[bold]HUGE ISSUE: Failed to process product purchase, could not find player! (plr: "
					.. playerId
					.. " | id: "
					.. productId
					.. ") [/bold]",
				true
			)
		end
	end)

	--
	return Enum.ProductPurchaseDecision.NotProcessedYet
end
