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
What if you buy the medium one?
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.