Process Receipt Not Being Called

I have a code that prompts a product purchase, and I used the wiki product handler to check if the player purchased it. The product handler is in the server so I can give players abilities from the server when they buy it.

Here is my LocalScript:

script.Parent.MouseButton1Down:Connect(function)
    MarketplaceService:PromptProductPurchase(game.Players.LocalPlayer, 00000)
end)

Here is my ServerScript:

local MarketplaceService = game:GetService("MarketplaceService")
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")

local purchaseHistoryStore = DataStoreService:GetDataStore("PurchaseHistory")

local productFunctions = {}

productFunctions[00000] = function(receipt, player)
	print(1)
	if player then
		print(1)
return true
	end
end

local function processReceipt(receiptInfo)

	local playerProductKey = receiptInfo.PlayerId .. "_" .. receiptInfo.PurchaseId
	local purchased = false
	local success, errorMessage = pcall(function()
		purchased = purchaseHistoryStore:GetAsync(playerProductKey)
	end)
	if success and purchased then
		return Enum.ProductPurchaseDecision.PurchaseGranted
	elseif not success then
		error("Data store error:" .. errorMessage)
	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

	local success, errorMessage = pcall(function()
		purchaseHistoryStore:SetAsync(playerProductKey, true)
	end)
	if not success then
		error("Cannot save purchase data: " .. errorMessage)
	end

	return Enum.ProductPurchaseDecision.PurchaseGranted
end

MarketplaceService.ProcessReceipt = processReceipt

When I purchase the product, nothing gets printed, and there is no errors, any advise? Thank you!

1 Like

You never did MarketplaceService.ProcessReceipt = processReceipt.

1 Like

Ah I forgot to include it in the script when copying the code to the forum, edited the post!

Can you add a print at the top of the processReceipt function?

1 Like

Good idea! When I ran the code with print("Passed") and purchased the product, it printed!
image

I tried out this code and it worked!

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

MarketplaceService.ProcessReceipt = function(receiptInfo)
	if receiptInfo.ProductId == 0000 then
		local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
		if player then
			print(1)
			return Enum.ProductPurchaseDecision.PurchaseGranted
		else
			return Enum.ProductPurchaseDecision.NotProcessedYet
		end
	end
end
4 Likes