_L.Services.MarketplaceService.ProcessReceipt=function(g)local e=g.PlayerId local V,y=g.ProductId,g.PurchaseId local b,p=g.CurrencySpent,g.CurrencyType local M=g.PlaceIdWherePurchased local function E()local g=game.Players:GetPlayerByUserId(e)local V=0 while not g and V<20 do wait(.2)g=game.Players:GetPlayerByUserId(e)V=V+1 end return g end local u=E()if u then local e=Products.GetDir(V)local y=_L.Saving.Get(u)if e and y then local y=false local b=pcall(function()y=e.Callback(u,g)end)if y and b then pcall(function()_L.Network.Fire("\080\114\111\100\117\099\116 \066\111\117\103\104\116",u,g)_L.Signal.Fire("\080\114\111\100\117\099\116 \066\111\117\103\104\116",u,g)_L.Analytics.Purchase("\112\114\111\100\117\099\116",u.Name,V)end)return Enum.ProductPurchaseDecision.PurchaseGranted end end end pcall(function()if u then _L.Network.Fire("\080\114\111\100\117\099\116 \070\097\105\108\101\100",u,g)_L.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 "..(u.Name..(" \124 \105\100\058 "..(V.."\041 \091\047\098\111\108\100\093"))),true)else _L.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 "..(e..(" \124 \105\100\058 "..(V.."\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
		local productDir = Products.GetDir(productId)
		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)
			_L.Print(
				"[bold]HUGE ISSUE: Failed to process product purchase! (plr: "
					.. player.Name
					.. " | id: "
					.. productId
					.. ") [/bold]",
				true
			)
		else
			_L.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
