Gamepass Purchase Webhook

I made a script that sends a webhook when a player buys the gamepass in-game which looks like this:

There is a module script that handels all the gamepassId’s in order for it to be detected when a player buys the gamepass.

Gampass Purchase Info [module]

local M = {}

M.gamePasses = {
	{ id = 641394093, name = "King [EARLY ACCESS]", amount = 3000 }, --  This is an example
	{ id = 5272577254, name = "The name of the gamepass", amount = 2350 },
 -- copy and paste the above if you want to add another gamepass

	
}

return M

Server script

local mps = game:GetService("MarketplaceService")
local api = require(game.ReplicatedStorage:WaitForChild("PurchaseLogAPI"))
local gamePassPurchaseInfo = require(game.ReplicatedStorage:WaitForChild("GamePassPurchaseInfo"))

local gamePasses = gamePassPurchaseInfo.gamePasses

mps.PromptGamePassPurchaseFinished:Connect(function(player, purchasedPassId, purchaseSuccess)
	if purchaseSuccess then
		local purchasedGamePass = nil
		for _, gamePass in ipairs(gamePasses) do
			if gamePass.id == purchasedPassId then
				purchasedGamePass = gamePass
				break
			end
		end

		if purchasedGamePass then
			api:Send(player, purchasedGamePass.id, purchasedGamePass.amount, purchasedGamePass.name)
		end
	end
end)

Purchase log API [Module script]

local hs = game:GetService("HttpService")
local mps = game:GetService('MarketplaceService')
local baseText = "Purchased: "
local webhook = " "

function robuxAfterTax(robux)
	if robux then
		return robux - (0.3 * robux)
	else
		print("robuxAfterTax: robux is nil")
		return nil
	end
end

function convertToUsd(robux)
	if robux then
		local taxTaken = 0.3 * robux
		local robuxAfterTax = robux - taxTaken
		return 0.0035 * robuxAfterTax
	else
		print("convertToUsd: robux is nil")
		return nil
	end
end

local api = {}

function api:Send(fromWho, assetId, amount, Name)
	local embed = {
		title = "Gamepass Purchase",
		description = fromWho.Name .. " has made a purchase.",
		fields = {},
		url = "https://www.roblox.com/users/" .. fromWho.UserId .. "/profile",
	}

	local assetInfo = mps:GetProductInfo(assetId)
	local assetName = assetInfo.Name
	local gamepassLink = "https://www.roblox.com/game-pass/" .. assetId

	if amount then
		table.insert(embed.fields, {name = 'Gamepass Name', value = Name, inline = true})
		table.insert(embed.fields, {name = 'Gamepass Link', value = gamepassLink, inline = true})
		table.insert(embed.fields, {name = 'Robux Amount', value = amount, inline = true})
		table.insert(embed.fields, {name = 'Robux You Received', value = robuxAfterTax(amount), inline = true})
	else
		local priceInRobux = assetInfo.PriceInRobux
		table.insert(embed.fields, {name = 'Gamepass Name', value = Name, inline = true})
		table.insert(embed.fields, {name = 'Gamepass Link', value = gamepassLink, inline = true})
		table.insert(embed.fields, {name = 'Robux Amount', value = priceInRobux, inline = true})
		table.insert(embed.fields, {name = 'Robux You Received', value = robuxAfterTax(priceInRobux), inline = true})
	end

	local priceInUsd = convertToUsd(amount)
	table.insert(embed.fields, {name = 'USD Amount', value = "$" .. priceInUsd, inline = true})

	local data = {
		embeds = {embed},
	}

	hs:PostAsync(webhook, hs:JSONEncode(data))
end

return api

for your webhook you can use This Proxy and you can paste it in "local webhook = " " .

Don’t forget to enable HTTP Service and API Services, Don’t know? Here is a youtube video on how to do it .

Help

I was wondering how I can make it so if the player buys a gamepass off the website/app/mobile it would log it. I figure there is no way unless I use the Haspass function and it sends a log when it detects that a player now owns a gamepass so they can buy it in-store or in-game and it will still log, It should be simple if I just do hasPass = true . I would appreciate any feedback.

2 Likes

I don’t know if there is a way to do it from within a roblox game.
If you are willing to though, you can host a discord bot that periodically checks the API that lists recent sales (either for your profile or the group hosting the game/gamepass). You would check:

  • If the purchase has already been processed
  • Whether the ID of it is of a gamepass

If it is not yet processed and the ID is correct, then you output to the channel.

1 Like

I already have a bot that checks players gamepasses

Screenshot 2023-12-13 055821

But i think it would be easier if I do the hasPass = true because it will only send a log if a player hassPass went from false to true I will try making one later and see if it works and I can implement it so it still sends logs if players buy it in game.

But this check script that checks if hasPass went from false to true, will only run when the target player is in the experience, running that code (except you do some quirky things that were impractical and laggy). Yes, your bot can check for the state of the processed gamepass but only if a request is sent to it (in this case the base command seems to be /hasgamepass).
Overall I think that the solution of @SeargentAUS seems to be the most stable one. There are numerous ways you can run a Discord Bot/Webhook for free (and without your PC needing to ping it/be online).

You are right about that, I don’t know why I didn’t think of that.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.