Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
DDock
Visitor

In App purchase question

Is it possible to have an in App Purchase in a free channel that unlocks a paid premium version in another channel? I guess a direct link to the Channel page of the premium version would work. Any suggestions?

So far having major headaches trying to get the InApp stuff figured out.
0 Kudos
3 REPLIES 3
RokuJoel
Binge Watcher

Re: In App purchase question

If you package both channels with the same devID / Password then the two channels will be able to access each-other's registry information which makes something like what you are talking about possible.

The other way is to use launch parameters so that if one channel launches the other it can send specific instructions. However, there is nothing preventing someone with a LAN sniffer from figuring out what those instructions are.

- Joel
0 Kudos
RokuMarkn
Visitor

Re: In App purchase question

The most direct way to do this is to use In-App Upgrade rather than In-App Purchase. Create the paid channel first and when you create the free channel, set its "Upgrade Channel" to the paid channel. Then you can use ifChannelStore.DoUpgrade to upgrade the channel. The online documentation of this is unfortunately incomplete, but here are the ifChannelStore methods you would use.


GetUpgrade() as Void

Requests information about the upgrade for the current channel. Each channel may have one "In-Channel Upgrade" channel associated with it.

If successful, a later roChannelStoreEvent will be received which contains an roList of roAssociativeArray items where each item contains the following following parameter names with specified value type:

String code
String name
String description
String SDPosterUrl
String HDPosterUrl
String cost (Localized cost with local currency symbol)

If the current channel has no In-Channel Upgrade, an empty roList is returned.



DoUpgrade() as String

Displays the Roku Channel Store Product Purchase Screen populated with information about the "In-Channel Upgrade" available for the currently running channel. The user can then either approve and complete the purchase or cancel the purchase. If the purchase was completed successfully, the return value is the item code of the purchased upgrade; otherwise it is an empty string. If a code is returned, then the new channel has already been downloaded and installed on the unit, and the currently running channel will be automatically deleted when the user exits it.

You must call GetUpgrade() on the same roChannelStore object before calling DoUpgrade().
0 Kudos
RokuMarkn
Visitor

Re: In App purchase question

Here's some more information about how to use these methods. Normally your app will have a screen that offers the option to upgrade. Before displaying this screen, you would call GetUpgrade and wait for the ChannelStoreEvent message. Then extract the information you need from the message (the price at least) and display the offer. If the user accepts the offer, call DoUpgrade to complete the purchase, and check the return code from DoUpgrade to determine whether the user completed the purchase or cancelled it.

Here is some skeleton code that does this. It would need to be fleshed out with text appropriate to your app, and possibly modified if your upgrade offer is not on a separate screen like this.


' ---------------------------------------------------------------------
function ShowPurchaseScreen() as Void
' First screen: wait for GetUpgrade from Channel Store
store = CreateObject("roChannelStore")
if store = invalid then return
screen1 = CreateObject("roParagraphScreen")
upgrade = ScreenGetUpgrade(screen1, store)
if upgrade = invalid then return

' Second screen: buy offer
screen2 = CreateObject("roParagraphScreen")
if not ScreenPurchase(screen2, screen1, store, upgrade) then return

' Third screen: thanks for buying
screen3 = CreateObject("roParagraphScreen")
ScreenThanks(screen3, screen2)
end function

' ---------------------------------------------------------------------
function ScreenGetUpgrade(screen as Object, store as Object) as Dynamic
msgport = CreateObject("roMessagePort")
screen.SetMessagePort(msgport)
screen.AddParagraph("Please wait a moment...")
screen.Show()

store.SetMessagePort(msgport)
store.GetUpgrade()
timer = CreateObject("roTimeSpan")
timer.Mark()

while true
msg = wait(1000, msgport)
if type(msg) = "roChannelStoreEvent" then
if msg.IsRequestSucceeded() then
items = msg.GetResponse()
if items <> invalid and items.count() > 0 then return items[0]
exit while
elseif msg.IsRequestFailed() then
print "channel store req failed: ";msg.GetStatusMessage()
exit while
end if
elseif type(msg) = "roParagraphScreenEvent" then
if msg.IsScreenClosed() then return invalid
end if
if timer.TotalMilliseconds() > 8000 then
print "Channel Store timeout"
exit while
end if
end while
return invalid
end function

' ---------------------------------------------------------------------
function ScreenPurchase(screen as Object, old_screen as Object, store as Object, upgrade as Object) as Boolean
msgport = CreateObject("roMessagePort")
screen.SetMessagePort(msgport)
screen.AddParagraph("Do you want to upgrade?")
screen.AddButton(1, "Buy for " + upgrade.cost)
screen.Show()
old_screen.Close()

while true
msg = wait(0, msgport)
if type(msg) = "roParagraphScreenEvent" then
if msg.IsScreenClosed() then
return false
elseif msg.IsButtonPressed()
button = msg.GetIndex()
if button = 1 then ' Buy
item = store.DoUpgrade()
if item <> invalid and item <> "" then
print "buy succeeded, item ";item
return true
end if
print "buy failed"
end if
end if
end if
end while
end function

' ---------------------------------------------------------------------
function ScreenThanks(screen as Object, old_screen as Object) as Void
msgport = CreateObject("roMessagePort")
screen.SetMessagePort(msgport)
screen.AddParagraph("Thank you for upgrading.")
screen.AddParagraph("Press OK to return to the Roku home screen.")
screen.AddButton(1, "OK")
screen.Show()
old_screen.Close()

while true
msg = wait(0, msgport)
if type(msg) = "roParagraphScreenEvent" then
if msg.IsScreenClosed() then
return
elseif msg.IsButtonPressed()
return
end if
end if
end while
end function


--Mark
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.