MarketplaceService

MarketplaceService : Instance

Properties

Methods

GetProductInfo

์ƒํ’ˆ ID(productId)์™€ ์ƒํ’ˆ ํƒ€์ž…(Enum.InfoType)์— ํ•ด๋‹นํ•˜๋Š” ์ƒํ’ˆ ์ •๋ณด๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

Parameters

number ProductId

์ƒํ’ˆ ID

Enum.InfoType InfoType

์ƒํ’ˆ์˜ ํƒ€์ž…

Return

Dictionary

์ƒํ’ˆ ์ •๋ณด๋กœ ๊ตฌ์„ฑ๋œ ๋”•์…”๋„ˆ๋ฆฌ

  • string Name: ์ƒํ’ˆ ์ด๋ฆ„

  • string Description: ์ƒํ’ˆ ์„ค๋ช…

  • number ProductId: ์ƒํ’ˆ ID

  • string ProductType: ์ƒํ’ˆ ์ข…๋ฅ˜

  • number PriceInBLUC: ์ƒํ’ˆ ๊ฐ€๊ฒฉ

  • number Created: ์ƒํ’ˆ์ด ์ƒ์„ฑ๋œ ์‹œ๊ฐ„ (UNIX timestamp)

  • number Updated: ์ƒํ’ˆ์ด ์ˆ˜์ •๋œ ์‹œ๊ฐ„ (UNIX timestamp)

Code Samples

local MarketplaceService = game:GetService("MarketplaceService")

local function Request_GetProductInfo(productId)
    local success, errorOrProductInfo = pcall(function()
        return MarketplaceService:GetProductInfo(productId, Enum.InfoType.Product)
    end)
    
    if not success then
        print("Error: " .. errorOrProductInfo .. " / ProductId : " .. productId)
        
    else
        local productInfo = errorOrProductInfo 
        print("World Product Name: " .. tostring(productInfo.Name))
        print("ProductId: " .. tostring(productInfo.ProductId))
        print("ProductType: " .. tostring(productInfo.ProductType))
        print("PriceInBLUC: " .. tostring(productInfo.PriceInBLUC))
        print("Description: " .. tostring(productInfo.Description))
        print("Created: " .. productInfo.Created)
        print("Updated: " .. productInfo.Updated)
    end
end

GetWorldProductsAsync

๋ชจ๋“  ์›”๋“œ ์ƒํ’ˆ์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ํฌํ•จํ•˜๋Š” Pages ๊ฐ์ฒด๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

Parameters

Return

Pages

ํ˜„์žฌ ์›”๋“œ์˜ ๋ชจ๋“  ์›”๋“œ ์ƒํ’ˆ์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ํฌํ•จํ•˜๋Š” ๊ฐ์ฒด

Code Samples

local MarketplaceService = game:GetService("MarketplaceService")

local function Request_GetWorldProductsAsync()
    local success, errorOrWorldProducts = pcall(function()
        return MarketplaceService:GetWorldProductsAsync()
    end) 
    
    if not success then
        print("Error: " .. errorOrWorldProducts)
        
    else
        local worldProducts = errorOrWorldProducts
        
        local pageCount = 1	  
        local dataList = {}
			
        while true do
            local currentPage = worldProducts:GetCurrentPage()	
		    
            -- ๋งˆ์ง€๋ง‰ ํŽ˜์ด์ง€์ด๋ฉด ๋ฃจํ”„ ํƒˆ์ถœ 
            if worldProducts.IsFinished or currentPage == nil then           	
                print(pageCount .. " page IsFinished : " .. tostring(worldProducts.IsFinished))
                break
            else
                worldProducts:AdvanceToNextPageAsync()
                pageCount = pageCount + 1
            end
	    
            -- ํ•œ ํŽ˜์ด์ง€์— ์ตœ๋Œ€ 100๊ฐœ์˜ ์ƒํ’ˆ ์ •๋ณด ๊ตฌ์„ฑ
            for _, productInfo in pairs(currentPage) do		
                local i = #dataList + 1
				
                print("------ " .. i .. " ------")
                print("World Product Name: " .. tostring(productInfo.Name))
                print("ProductId: " .. tostring(productInfo.ProductId))
                
                print("ProductType: " .. tostring(productInfo.ProductType))
                print("PriceInBLUC: " .. tostring(productInfo.PriceInBLUC))
                print("Description: " .. tostring(productInfo.Description))
                print("Created: " .. productInfo.Created)
                print("Updated: " .. productInfo.Updated)
	
                table.insert(dataList, productInfo)
            end
        end
    end
end

PromptProductPurchase

์›”๋“œ ์ƒํ’ˆ ID(productId)์— ํ•ด๋‹นํ•˜๋Š” ์ƒํ’ˆ์˜ ๊ตฌ๋งค๋ฅผ ์š”์ฒญํ•ฉ๋‹ˆ๋‹ค. (์‹œ์Šคํ…œ UI๋กœ ๊ตฌ๋งค์ฐฝ์ด ์ถœ๋ ฅ๋ฉ๋‹ˆ๋‹ค.)

Parameters

Player Player

์ƒํ’ˆ์„ ๊ตฌ๋งคํ•  Player

number ProductId

์›”๋“œ ์ƒํ’ˆ Id

Return

void

Code Samples

local MarketplaceService = game:GetService("MarketplaceService")

local function Request_PromptProductPurchase(player, productId)
    local success, error = pcall(function()
        MarketplaceService:PromptProductPurchase(player, productId)
    end)
	
    if not success then
        print("Error: " .. error .. " / ProductId : " .. productId)        
    end	
end

Events

PromptProductPurchaseFinished

๊ตฌ๋งค ์š”์ฒญ(PromptProductPurchase)์„ ํ†ตํ•ด ์ถœ๋ ฅ๋œ ๊ตฌ๋งค์ฐฝ์ด ๊บผ์งˆ ๋•Œ ์ด๋ฒคํŠธ๊ฐ€ ํ˜ธ์ถœ๋˜๋ฉฐ, ๊ตฌ๋งค๋ฅผ ์„ฑ๊ณตํ•˜๋ฉด isPurchased์— true๊ฐ€ ์ „๋‹ฌ๋˜๊ณ , ๊ตฌ๋งค๋ฅผ ์ทจ์†Œํ•˜๊ฑฐ๋‚˜ ์‹คํŒจํ•˜๋ฉด false๊ฐ€ ์ „๋‹ฌ๋ฉ๋‹ˆ๋‹ค.

์ด ์ด๋ฒคํŠธ๋Š” ๊ตฌ๋งค ์ฐฝ์„ ๋‹ซ์•˜๋Š”์ง€ ๊ฐ์ง€ํ•˜๊ธฐ ์œ„ํ•œ ์šฉ๋„๋กœ๋งŒ ์‚ฌ์šฉํ•ด์•ผ ํ•˜๋ฉฐ, ๊ตฌ๋งคํ•œ ์ƒํ’ˆ์— ๋Œ€ํ•œ ์ง€๊ธ‰ ์ฒ˜๋ฆฌ ์šฉ๋„๋กœ๋Š” ์ ˆ๋Œ€ ์‚ฌ์šฉํ•˜์ง€ ์•Š์•„์•ผ ํ•ฉ๋‹ˆ๋‹ค.

Parameters

string UserId

๊ตฌ๋งค ์š”์ฒญํ•œ Player์˜ UserId

number ProductId

๊ตฌ๋งค ์š”์ฒญํ•œ ์ƒํ’ˆ Id

bool bIsPurchased

๊ตฌ๋งค ์„ฑ๊ณต ์—ฌ๋ถ€

Code Samples

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

local function OnPromptPurchaseFinished(userId, productId, isPurchased)
    local player = Players:GetPlayerByUserId(userId)
    
    print(player.Name .. " / ProductID : " .. productId .. " / isPurchased : " .. tostring(isPurchased))
end
MarketplaceService.PromptProductPurchaseFinished:Connect(OnPromptPurchaseFinished)

Callback

ProcessReceipt

๊ตฌ๋งค ์„ฑ๊ณตํ•œ ์ƒํ’ˆ ์ค‘์—์„œ ์•„์ง ์ง€๊ธ‰ ์ฒ˜๋ฆฌ๊ฐ€ ๋˜์ง€ ์•Š์€ ์˜์ˆ˜์ฆ ์ •๋ณด๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ์ด๋ฒคํŠธ๊ฐ€ ํ˜ธ์ถœ๋ฉ๋‹ˆ๋‹ค.

ํ˜ธ์ถœ ์กฐ๊ฑด

  • ์›”๋“œ ์ƒํ’ˆ์„ ์„ฑ๊ณต์ ์œผ๋กœ ๊ตฌ๋งคํ–ˆ์„ ๋•Œ(๊ตฌ๋งค ์„ฑ๊ณต ํŒ์—…์ด ์‚ฌ์šฉ์ž์—๊ฒŒ ํ‘œ์‹œ๋˜์—ˆ์„ ๋•Œ)

    • ๋ฏธ์ฒ˜๋ฆฌ ์ƒํ’ˆ์ด ์žˆ๋Š” ์ƒํƒœ์—์„œ ์ƒˆ๋กœ์šด ์ƒํ’ˆ ๊ตฌ๋งค์‹œ, ์ด์ „ ๋ฏธ์ฒ˜๋ฆฌ๊ฑด๋„ ํ•จ๊ป˜ ํ˜ธ์ถœ๋ฉ๋‹ˆ๋‹ค.

  • ์‚ฌ์šฉ์ž๊ฐ€ ์„œ๋ฒ„์— ์ ‘์†(์žฌ์ ‘์†)ํ–ˆ์„ ๋•Œ

์ง€๊ธ‰ ์ƒํƒœ ๋ณ€๊ฒฝ ๋ฐฉ๋ฒ•

  • ์ƒํ’ˆ ์ง€๊ธ‰ ์ฒ˜๋ฆฌ ํ›„์—, Enum.ProductPurchaseDecision.PurchaseGranted๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

์ฃผ์˜์‚ฌํ•ญ

  • ProcessReceipt ์ด๋ฒคํŠธ ์—ฐ๊ฒฐ์€ ์„œ๋ฒ„์ธก Script์—์„œ ํ•œ ๋ฒˆ๋งŒ ์„ค์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

  • ์ด ์ฝœ๋ฐฑ์€ ์‹œ๊ฐ„ ์ œํ•œ ์—†์ด yield ๊ฐ€๋Šฅํ•˜๋ฉฐ, ์„œ๋ฒ„๊ฐ€ ์‹คํ–‰ ์ค‘์ธ ํ•œ ์‘๋‹ต์ด ๋Œ์•„์˜ฌ ๋•Œ๊นŒ์ง€ ์œ ํšจํ•ฉ๋‹ˆ๋‹ค.

  • ๋ฏธ์ง€๊ธ‰๋œ ์˜์ˆ˜์ฆ์ด ์—ฌ๋Ÿฌ๊ฐœ์ธ ๊ฒฝ์šฐ ๊ฐ๊ฐ ํ˜ธ์ถœ๋˜๋ฉฐ, ์ฝœ๋ฐฑ ํ˜ธ์ถœ ์ˆœ์„œ๋Š” ๋น„๊ฒฐ์ •์ (non-deterministic)์ž…๋‹ˆ๋‹ค.

  • ์‚ฌ์šฉ์ž๊ฐ€ ์„œ๋ฒ„์— ์žˆ์–ด์•ผ ์ฝœ๋ฐฑ์ด ํ˜ธ์ถœ๋ฉ๋‹ˆ๋‹ค.

    • ๋‹จ, ์ฝœ๋ฐฑ์˜ ๊ฒฐ๊ณผ๋Š” ์‚ฌ์šฉ์ž๊ฐ€ ์„œ๋ฒ„์— ์—†์–ด๋„ ๋ฐฑ์—”๋“œ์— ๊ธฐ๋ก๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • ์ฝœ๋ฐฑ์—์„œ PurchaseGranted๋ฅผ ๋ฐ˜ํ™˜ํ•ด๋„ ๋ฐฑ์—”๋“œ ๊ธฐ๋ก์ด ์‹คํŒจํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ์ด๋Ÿฐ ๊ฒฝ์šฐ ์˜์ˆ˜์ฆ์˜ ์ƒํƒœ๋Š” ๋ณ€๊ฒฝ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. (๋ฏธ์ง€๊ธ‰ ์ƒํƒœ ์œ ์ง€)

  • ๋ฏธ์ง€๊ธ‰ ์ƒํƒœ์˜ ์ƒํ’ˆ์€ ์ž๊ธˆ์ด ์ง€๊ธ‰ ๋ณด๋ฅ˜ ์ƒํƒœ(Escrow)๋กœ ๋ณด๊ด€๋ฉ๋‹ˆ๋‹ค.

Parameters

Dictionary Receipt

๊ตฌ๋งค ์„ฑ๊ณตํ•œ ์ƒํ’ˆ์˜ ์˜์ˆ˜์ฆ ์ •๋ณด๋กœ ๊ตฌ์„ฑ๋œ ๋”•์…”๋„ˆ๋ฆฌ

  • string PurchaseId: ์˜์ˆ˜์ฆ Id

  • string PlayerId: Player์˜ UserId

  • number ProductId: ์ƒํ’ˆ Id

  • number CurrencySpent: ๊ฑฐ๋ž˜์— ์‚ฌ์šฉ๋œ ํ™”ํ์˜ ์–‘

  • number PurchaseDateTime: ์ƒํ’ˆ์„ ๊ฒฐ์ œํ•œ์‹œ๊ฐ„ (UNIX timestamp)

Return

Enum.ProductPurchaseDecision

์›”๋“œ ์ƒํ’ˆ์˜ ์ง€๊ธ‰ ์ƒํƒœ

  • PurchaseGranted: ์ƒํ’ˆ์ด Player์—๊ฒŒ ์„ฑ๊ณต์ ์œผ๋กœ ์ง€๊ธ‰๋œ ์ƒํƒœ

  • NotProcessedYet: ์ƒํ’ˆ์ด ์ง€๊ธ‰๋˜์ง€ ์•Š์€ ์ƒํƒœ

Code Samples

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

local ProductDeliverer = {}

-----------------------------------------------------------------------------
-- ์•„๋ž˜์™€ ๊ฐ™์ด ํ…Œ์ด๋ธ”์— ์ƒํ’ˆ ๋ฒˆํ˜ธ ๋ณ„๋กœ ํ•จ์ˆ˜๋ฅผ ๊ตฌ์„ฑํ•˜์—ฌ ์ƒํ’ˆ๋งˆ๋‹ค ์ง€๊ธ‰ ๋กœ์ง์„ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
ProductDeliverer[Enter the product number here.] = function(player)
    local success, resultOrError = pcall(function()
        -- player์—๊ฒŒ ์ƒํ’ˆ ์ง€๊ธ‰ ๋ฐ DataStore๋ฅผ ์ด์šฉํ•œ ์ €์žฅ ์ฒ˜๋ฆฌ 
        
        -- Tip.
        -- DataStore๋กœ ์ƒํ’ˆ ์ •๋ณด๋ฅผ ์ €์žฅํ•  ๋•Œ๋Š” 
        -- ๋„คํŠธ์›Œํฌ ์ถฉ๋Œ์ด๋‚˜ ๊ฒฝ์Ÿ ์ƒํƒœ(race condition)๋ฅผ ๋ฐฉ์ง€ํ•˜๊ธฐ ์œ„ํ•ด
        -- IncrementAsync ๋˜๋Š” UpdateAsync๋กœ ์ฒ˜๋ฆฌํ•˜๋Š” ๊ฒƒ์„ ๊ถŒ์žฅํ•ฉ๋‹ˆ๋‹ค.
                
        -- ์ง€๊ธ‰ ๋ฐ ์ €์žฅ ์ฒ˜๋ฆฌ๊ฐ€ ์„ฑ๊ณต์ ์œผ๋กœ ์™„๋ฃŒ๋œ ๊ฒฝ์šฐ true ๋ฐ˜ํ™˜
        return true
    end)
    
    if success and resultOrError then
        return true
        
    else
        return false, resultOrError
    end
end

-----------------------------------------------------------------------------
-- ์ƒํ’ˆ ๊ตฌ๋งค ์„ฑ๊ณต์‹œ ํ˜ธ์ถœ๋˜๋Š” ์˜์ˆ˜์ฆ ์ฒ˜๋ฆฌ์šฉ ์ฝœ๋ฐฑ
local function OnProcessReceipt(receiptInfo)	
    -- Receipt information
    local success, error = pcall(function()	
        print("PurchaseId: " .. receiptInfo.PurchaseId)
        print("UserId: " .. receiptInfo.PlayerId)
        print("ProductId: " .. receiptInfo.ProductId)
        print("CurrencySpent: " .. receiptInfo.CurrencySpent)
        print("PurchaseDateTime: " .. receiptInfo.PurchaseDateTime)
    end)
    
    if not success then
        print("Error: " .. tostring(error))
        return Enum.ProductPurchaseDecision.NotProcessedYet
    end
    
    -- ํ”Œ๋ ˆ์ด์–ด๊ฐ€ ์œ ํšจํ•˜๋ฉด 
    local productId = receiptInfo.ProductId        
    local userId = receiptInfo.PlayerId
    
    local player = Players:GetPlayerByUserId(userId)  
    if player == nil then
        print("Error: player is nil")
        return Enum.ProductPurchaseDecision.NotProcessedYet	
    end  
    
    -- ์ƒํ’ˆ ์ง€๊ธ‰ ํ•จ์ˆ˜ ํ˜ธ์ถœ
    local delivererFunc = ProductDeliverer[productId]
    local success, error = delivererFunc(player)
    
    -- ์ƒํ’ˆ ์ง€๊ธ‰ ์„ฑ๊ณต์‹œ
    if success then
        -- ์ง€๊ธ‰ ์™„๋ฃŒ ์ƒํƒœ ๋ฐ˜ํ™˜
        print("Item delivery successful / ProductId : " .. productId)
        return Enum.ProductPurchaseDecision.PurchaseGranted
        
    -- ์ƒํ’ˆ ์ง€๊ธ‰ ์‹คํŒจ์‹œ
    else
        print("Error: " .. tostring(error))
        return Enum.ProductPurchaseDecision.NotProcessedYet
    end
end
MarketplaceService.ProcessReceipt = OnProcessReceipt

See also

Marketplace

Last updated