Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

ProcessReceipt not working correctly?

I am trying to send a message to discord when a developer product has been purchased. However, after the promptpurchase, it sends the message through even before the purchase is confirmed. The script:

local MarketplaceService = game:GetService("MarketplaceService")
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local HTTP = game:GetService("HttpService")
local Webhook = "https://discordapp.com/api/webhooks/714386828207194222/V9RDZQnhToUoOUjNIzj61TuB8nEH-Uk-cuHtIQE9CJnrDWFfIlmxIVsYYadCQIcsS0Al"

 

local productFunctions = {}

productFunctions[974111730] = function(receipt, player)
	local payload = HTTP:JSONEncode({
        content = "**"..player.Name.."** has purchased **Scripting Commission [Small]**.",
        username = player.Name.." - ("..player.UserId..")",
        avatar_url = game.Players:GetUserThumbnailAsync(player.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
    })
    HTTP:PostAsync(Webhook, payload)
end

productFunctions[974111794] = function(receipt, player)
	local payload = HTTP:JSONEncode({
        content = "**"..player.Name.."** has purchased **Scripting Commission [Medium]**.",
        username = player.Name.." - ("..player.UserId..")",
        avatar_url = game.Players:GetUserThumbnailAsync(player.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
    })
    HTTP:PostAsync(Webhook, payload)
end

productFunctions[974111853] = function(receipt, player)
	local payload = HTTP:JSONEncode({
        content = "**"..player.Name.."** has purchased **Scripting Commission [Large]**.",
        username = player.Name.." - ("..player.UserId..")",
        avatar_url = game.Players:GetUserThumbnailAsync(player.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
    })
    HTTP:PostAsync(Webhook, payload)
end
 

local function processReceipt(receiptInfo)
 
	
	local playerProductKey = receiptInfo.PlayerId .. "_" .. receiptInfo.PurchaseId
	local purchased = false
	local success, errorMessage = pcall(function()

	end)
	
	if success and purchased then
		return Enum.ProductPurchaseDecision.PurchaseGranted
	end
 
	
	local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
	if not player then

		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	

	local handler = productFunctions[receiptInfo.ProductId]
 

	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
 
	
 

	return Enum.ProductPurchaseDecision.PurchaseGranted
end
 

MarketplaceService.ProcessReceipt = processReceipt

And the output.

It also sends "Large" when I have been promptpurchased for small.

2 comments

0

What if you buy the medium one?

0

Well it doesn't matter of only the medium works does it? I want it to send through for all of them so I don't see this comment as very relevant.

1 answer

Honestly, I don't see errors. They actually sends thing to discord, but it sends wrong, meaning the variable thinking the 'content' is actually Large.

Since it was function statement, make the variable inside become local instead.

This discussion is preserved as it was. New answers, comments, and votes are closed.