How to access developer products through datastore?

-- The core 'ProcessReceipt' callback function
local function processReceipt(receiptInfo)

    -- Determine if the product was already granted by checking the data store  
    local playerProductKey = receiptInfo.PlayerId .. "_" .. receiptInfo.PurchaseId
    print(playerProductKey)
    local purchased = false
    local success, errorMessage = pcall(function()
        purchased = purchaseHistoryStore:GetAsync(playerProductKey)
    end)
    -- If purchase was recorded, the product was already granted
    if success and purchased then
        return Enum.ProductPurchaseDecision.PurchaseGranted
    elseif not success then
        error("Data store error:" .. errorMessage)
    end

    -- Find the player who made the purchase in the server
    local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
    if not player then
        -- The player probably left the game
        -- If they come back, the callback will be called again
        return Enum.ProductPurchaseDecision.NotProcessedYet
    end

    -- Look up handler function from 'productFunctions' table above
    local handler = productFunctions[receiptInfo.ProductId]

    -- Call the handler function and catch any errors
    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

    -- Record transaction in data store so it isn't granted again
    local success, errorMessage = pcall(function()
        purchaseHistoryStore:SetAsync(playerProductKey, true)
    end)
    if not success then
        error("Cannot save purchase data: " .. errorMessage)
    end

    -- IMPORTANT: Tell Roblox that the game successfully handled the purchase
    return Enum.ProductPurchaseDecision.PurchaseGranted
end

Hello I am a not well-versed in DataStores and I’ve used the roblox default callback function for saving player’s developer products to the datastore local purchaseHistoryStore = DataStoreService:GetDataStore("TestingPurchases").

The issue is that the playerProductKey prints out a strange key, for e.g: 4787929_20493853823728d3a7 instead of 4787929_532453432.

The second one would be what I need it to say when I’m checking if the player already has the developer product.

To check for the developer product I’m using a for-loop to iterate through a dictionary of productIds like so:

for _, value in pairs(ProductID.PremiumBuildings) do

		local playerProductKey = player.UserId .. "_" .. value

		local purchased = purchaseHistoryStore:GetAsync(playerProductKey)

		if purchased then
			print(player.Name.." has "..value)
		end
end

Am I checking the playerProductKey incorrectly?

Any help would be great, thank you!

So first off, the PurchaseId is not your AssetId, which is why it looks funky.

Second, there is no way to re-access a purchase DataStore key, because the PurchaseId is uniquely generated. So no, you aren’t checking the PlayerProductKey correctly, because there is no way to check it.

Ah that makes sense why its so funky. So there’s no way to determine if a player has purchased a developer product?

It’s possible, there’s a useful resource at the developer hub which demonstrates how.

A developer product is supposed to be bought multiple times. If you want to know whenever a player has purchased a developer product before, instead of iterating through the transactions, you can save it permanently in a different data store, like using true or false.