Error with processing receipts

I’m trying to process a receipt, but I keep getting this error:

Transform function error ServerScriptService.ProcessReceipts:248: Failed to process a product purchase for ProductId: 1353158718 Player: 62penguins Error: nil

Here’s the function that processes receipts:

local function processReceipt(receiptInfo)
	print("purchase", receiptInfo)
	print("callback fired")	
	local productKey = receiptInfo.PlayerId.."_"..receiptInfo.PurchaseId
	local purchased = false
	local success, result, errorMessage
	print("Variables found")
	
	success, errorMessage = pcall(function()
		purchased = purchaseHistoryStore:GetAsync(productKey)
	end)
	if success and purchased then
		print("Purchase Granted")
		return Enum.ProductPurchaseDecision.PurchaseGranted
	elseif not success then
		error("Data store error:"..errorMessage)
	end
	
	local success, isPurchaseRecorded = pcall(function()
		return purchaseHistoryStore:UpdateAsync(productKey, function(alreadyPurchased)
			if alreadyPurchased then
				print("already purchased")
				return true
			end
			
			local plr = Players:GetPlayerByUserId(receiptInfo.PlayerId)
			if not plr then
				print("player not found")
				return nil
			end
			
			local handler = productFunctions[receiptInfo.ProductId]
			print("product function found")
			
			local success, result = pcall(handler, receiptInfo, plr)
			if not success or not result then
				error("Failed to process a product purchase for ProductId: "..tostring(receiptInfo.ProductId).." Player: "..tostring(plr).." Error: "..tostring(result))
				return nil
			end	
			print("pcall for product function done")
			return true
		end)
	end)
	
	if not success then
		error("Failed to process receipt due to data store error.")
		return Enum.ProductPurchaseDecision.NotProcessedYet
	elseif isPurchaseRecorded == nil then
		print("not processed yet")
		return Enum.ProductPurchaseDecision.NotProcessedYet
	else
		print("purchase granted")
		return Enum.ProductPurchaseDecision.PurchaseGranted
	end
end

MarketplaceService.ProcessReceipt = processReceipt

Why does this keep happening?

1 Like

Are you ever returning anything from handler? If not you need to change if not success or not result to if not success

1 Like

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