Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
5

Why doesn't ProcessReceipt Fire?

Asked by
ZeroBits 142
9 years ago

I've tried everything I could think of, but the function won't fire when I buy the dev product. sometimes after I rejoin the place, it recognises that I bought the item, but I'd like it to recognise instantly.

the place with the script in question is here

and here is the script in question, all variable references are to existing items

if game.ServerScriptService:FindFirstChild("VaporPurchaseHandler") ~= nil then
    script.Parent = game.ServerScriptService
else
    script:Destroy()
end

-- debugging code added by ihaveamac
enable_debug_print = true
function print_d(m)
    if enable_debug_print then
        print("<debug> "..m)
    end
end

print_d("DEBUG MODE ACTIVE")

local MarketplaceService = game:GetService("MarketplaceService")
local PurchaseHistory = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
local data = game:GetService("DataStoreService"):GetDataStore("VaporData")

print_d("psready")

MarketplaceService.ProcessReceipt = function(receiptInfo) 
    print_d("purchased")
    local playerProductKey = receiptInfo.PlayerId .. ":" .. receiptInfo.PurchaseId
    if PurchaseHistory:GetAsync(playerProductKey) then
        return Enum.ProductPurchaseDecision.PurchaseGranted
    end
    print_d("RUNNING: for i, player in ipairs(game.Players:GetPlayers()) do")
    for i, player in ipairs(game.Players:GetPlayers()) do
        print_d("RUNNING: if player.userId == receiptInfo.PlayerId then")
        if player.userId == receiptInfo.PlayerId then
                print_d("condition successful")

                local vapor = player.PlayerGui:FindFirstChild("Vapor")
                local props = vapor.Properties
                local GameId = props.ProductId.Value
                local suffix = props.DataSuffix.Value
                local main = vapor.Window

            if receiptInfo.ProductId == GameId then
                print(player.Name)
                print(main.Name)
                main.Buy.Visible = false
                main.Load.Visible = true
                print_d("gameIdAffirmative")
                if main.Buy:FindFirstChild("Gift") ~= nil and main.Buy:FindFirstChild("Gift").isGift.Value == true then
                    print_d("isGift")
                    local text = string.lower(main.Buy:FindFirstChild("Gift").GiftBox.Text)
                    local giftlist = data:GetAsync("giftlist"..suffix)
                    if giftlist ~= nil then
                        local gifted = false
                        for i = 1,#giftlist do
                            if giftlist[i] == text then
                                print_d("already gifted to "..text)
                                gifted = true
                            end
                        end

                        if gifted == false then
                            print_d("gifted")
                            table.insert(giftlist,text)
                            data:SetAsync_d("giftlist"..suffix,giftlist)
                            main.Load.Text.Text = "Gift Sent.."
                        end                     

                    end

                    wait(1)
                    main.Load.Text.Text = "Processing.."
                    main.Load.Visible = false
                    main:FindFirstChild("Buy").Visible = true

                elseif main.Buy:FindFirstChild("Gift").isGift.Value == false then

                print_d("notgift")
                data:SetAsync(player.userId..suffix,true)
                main.Load.Text.Text = "Purchase Complete.."
                wait(1)
                main.Load.Text.Text = "Processing.."
                wait(1)
                main.Load.Visible = false
                main.Buy.Visible = true
                main.Visible = false
                vapor.Back.Visible = false
                print_d("buydone")

                else print_d("notgift, and not notgift")

                end
            end
        else
            print_d("condition failed")
        end
        print_d("if statement completed")
    end
    PurchaseHistory:SetAsync(playerProductKey, true)    
    print_d("purchasefinish")
    return Enum.ProductPurchaseDecision.PurchaseGranted 
end

print_d("purchase handler is ready")
1
Just a tip for testing this: make this a named function, and have ProcessReceipt call that function, passing in the receipt itself as an argument. This lets you create a "spoof" receipt that bypasses actually purchasing anything to check your code. adark 5487 — 9y
1
Just skimming this I don't see anything wrong. You used ProcessReceipt as a callback and not an event, which is correct. My only guess is that the datastore stuff is causing it the break without properly erroring. adark 5487 — 9y
0
That was my first guess, but if it were the data stores, the function should have at least run up to the point where datastores were used, currently it doesn't run at all between lines 23, and 100 ZeroBits 142 — 9y
1
I've had this problem too. Especially when I have multiple products. I'm not sure why it doesn't work right :/ lightpower26 399 — 9y
View all comments (4 more)
0
Is this in a Server Script? Goulstem 8144 — 9y
0
yes. ZeroBits 142 — 9y
0
Could this be roblox sided, not you? Teeter11 281 — 9y
0
yes. ZeroBits 142 — 9y

1 answer

Log in to vote
1
Answered by 9 years ago

I would try using PromptPurchaseFinished it is a secondary way to solve the problem. http://wiki.roblox.com/index.php?title=API:Class/MarketplaceService/PromptPurchaseFinished

0
While the project has long since been scrapped, I appreciate the help, and thank you for pointing me to this wonderful event, I'll probably use it a lot. ZeroBits 142 — 9y
Ad

Answer this question