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: ์ํ IDstring
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: ์์์ฆ Idstring
PlayerId: Player์ UserIdnumber
ProductId: ์ํ Idnumber
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
MarketplaceLast updated