What would be the best way to deal with Developer products using Datastore2 module?

Hello reader!

So as the title suggests, I’m currently trying to piece together developer products and datastor2, main reason being preventing player from losing the item bought, but also to make sure it doesn’t duplicate.

Note I haven’t worked with developer products even with regular data stores, let alone this module, this is my first “real” game, a game i’m proud of and can call mine (mostly :D), and it’s safe to say i jumped in the deep end with it… that being said the progress is good, but i really wouldn’t want to mess this part up, i believe you understand why.

Here’s what i have now (not including :PromptProductPurchase()):

local function receiptHandle(receipt)
	local player = players:GetPlayerByUserId(receipt.PlayerId)
	if not player then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	else
		local storeStore = ds2(StoreDS,player)
		local statsStore = ds2(StatsDS,player)
		local storeData = storeStore:GetTable(defaultStore)
		local stats = statsStore:GetTable(defaultStats)
		for amount,id in pairs(productIDs) do
			if id == receipt.ProductId then
				stats.coins = stats.coins + tonumber(amount)
				storeData.robuxCoinss = storeData.robuxCoins+ tonumber(amount)
				local function callback()
					return Enum.ProductPurchaseDecision.PurchaseGranted
				end
				ds2.SaveAll(player)
				statsStore.AfterSave(callback)
			end
		end
	end
end
marketplaceService.ProcessReceipt = receiptHandle

Am I close to a working system? What should I do to improve it?

I’m thinking I would have to save the specific purchases, instead of total, because i need to know weather it has already been processed, so it doesn’t duplicate, but i don’t know weather i would be able to get by with a single variable, or would i need tables?!

Any recommendations welcome, thanks!