Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
kooljay68
Level 7

Using Playduration for payment

I tried doing the following ... but not quite right I do not think ..... anyone have some input on what I should do ??


'Set Default screen values for items not in feed
item.HDBranded = false
item.IsHD = false
item.StarRating = "90"
item.ContentType = "episode"
item.cost = "0"


if item.cost = 0 then
item.PlayDuration = "60"
else
funds = tokenValidation()

if funds = 1 then
item.PlayDuration = item.PlayDuration
chargeCustomer()
else
item.PlayDuration = "0"
end if
end if

'media may be at multiple bitrates, so parse an build arrays
for idx = 0 to 4
e = curShow.media[idx]
if e <> invalid then
item.StreamBitrates.Push(strtoi(validstr(e.streamBitrate.GetText())))
item.StreamQualities.Push(validstr(e.streamQuality.GetText()))
item.StreamUrls.Push(validstr(e.streamUrl.GetText()))
endif
next idx

showCount = showCount + 1
feed.Push(item)

skipitem:

next

End Function

function tokenValidation() As Integer
sn = GetDeviceESN()
xfer = CreateObject("roURLTransfer")
xfer.SetURL("http://allbabestv.com/roku/getCredits.php?deviceID=" + sn)
response = xfer.GetToString()
xml = CreateObject("roXMLElement")
if xml.Parse(response)
if (xml.tokens > item.cost)
return 0
end if
end if
return 1
end function


function chargeCustomer()
sn = GetDeviceESN()
cost = item.cost
model = item.ContentId
xfer = CreateObject("roURLTransfer")
xfer.SetURL("http://allbabestv.com/roku/chargeCustomer.php?deviceID=" + sn + "&cost=" + cost + "&model=" + model)
response = xfer.GetToString()
end function


0 Kudos
3 REPLIES 3\
TheEndless
Level 10

Re: Using Playduration for payment

I don't know if it has anything to do with your issue (mainly, because it's not clear what you're trying to do), but both StarRating and PlayDuration should be integers, not strings.
Your code also tries to compare an item.cost value of "0" (string) with 0 (integer), which will always evaluate to false.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
kooljay68
Level 7

Re: Using Playduration for payment

Thanks for the advice ...

What I am trying to do is offer a live stream in 5 min increments and charge a certain amount of tokens for them. So if they select a certain feed I want them to get charged and then get kicked after the time is up. if it is a preview it is free and lasts 60 seconds. and if they do not have enough tokens then I want play duration to be zero.

Does that help make it any clearer ??
0 Kudos
TheEndless
Level 10

Re: Using Playduration for payment

I still think part (most?) of your problem is the string vs. integer issue in your code. Also, if you're trying to reset PlayDuration to no longer have an effect, set it to invalid instead of "0".
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos