cKurultayKalkan
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2016
03:31 AM
Roku 4 in app purchase ıd problem
Hello All,
I have problems about roku 4 in app system. in roku 2 everything is fine but when we try in roku4 app response don't contains purchaseId. i tried many times in different ways but i can't solve problem. It really start to get boring 🙂 Could you check out the script and help to find where is the problem ?
Thank you very much to all team and developers.
I can't get purchaseID or purchaseDetails. and g.store.GetPurchases() return uninitialized .
I have problems about roku 4 in app system. in roku 2 everything is fine but when we try in roku4 app response don't contains purchaseId. i tried many times in different ways but i can't solve problem. It really start to get boring 🙂 Could you check out the script and help to find where is the problem ?
Thank you very much to all team and developers.
Function InAppScreen()
g = GetGlobals(0)
g.store = CreateObject("roChannelStore")
g.port = CreateObject("roMessagePort")
g.store_items = CreateObject("roArray", 10, true)
g.store.SetMessagePort(g.port)
g.store.GetUpgrade()
print "Start to get channel catalog"
get_channel_catalog()
email = RegRead("email","User")
if(email = invalid)
print "email from reg is invalid"
print "Start to get user Data"
info = g.store.GetPartialUserData("email, firstname")
print "we got user data"
if(info <> invalid)
email = info.email
else
email = "wecantcatchanyemail@dayrep.com"
endif
endif
order = [{
purchaseID : email
code: g.store_items[0].code
qty: 1
}]
LogToServer("prepare order with code : " + g.store_items[0].code)
if(order[0].code = invalid Or order[0].code = "")
LogToServer("NoProductFromRokuChannel")
order_status_dialog(false,"No Product From Roku Channel")
return false
endif
LogToServer("tryToDoOrder")
LogToServer("set order...")
val = g.store.SetOrder(order)
LogToServer("do order...")
res = g.store.DoOrder()
LogToServer("we got res and finish order")
if res = true then
LogToServer("res is true")
while true
msg = wait(10000, g.port)
if type(msg) = "roChannelStoreEvent" then
if msg.isRequestSucceeded() then
deneme = g.store.GetPurchases()
LogToServer("getpurchases type:" + type(deneme))
LogToServer("we start to get response")
purchaseDetails = msg.GetResponse()
LogToServer("we got response and purchase details")
print purchaseDetails
if purchaseDetails <>invalid AND type(purchaseDetails)="roArray" then
LogToServer("purchaseDetails is valid array")
if purchaseDetails.count() > 0 then
purchase = purchaseDetails[0]
LogToServer("purchaseDetails has an element")
if purchase.purchaseID <> invalid then
LogToServer("that element has an purchaseID : " + purchase.purchaseID)
purchaseID = strReplace(purchase.purchaseID,"-","")
LogToServer(purchaseID)
if purchaseID <> invalid then
LogToServer("purchaseID is ready to post")
LogToServer("sending toocast request")
result = TooCast(email,purchaseID)
LogToServer("got response from toocast services : " + result)
if result = "success" then
LogToServer("Successful TooCast Response")
order_status_dialog(true,"Completed!")
return true
else
order_status_dialog(false,result)
return false
end if
else
LogToServer("PurchaseId is invalid after - replacement")
end if
else
objectString = "Obj : "
for each obj in purchase
objectString = objectString + toStr(obj) + " = " + toStr(purchase.lookup(obj))
end for
LogToServer("PurchaseID property is not valid and its type is" + type(purchase.purchaseID))
LogToServer(objectString)
if purchase.qty <> invalid and purchase.qty > 0 then
order_status_dialog(true,"Successfull! Please Wait")
end if
end if
else
LogToServer("purchaseDetails is has no element")
order_status_dialog(false,"Roku response has not an element")
return false
end if
else
LogToServer("purchaseDetails is invalid and its type is " + type(purchaseDetails))
order_status_dialog(false,"We cant get purchaseDetails from Roku Channel Store!")
return false
end if
end if
end if
end while
else
LogToServer("Payment Error about user.")
order_status_dialog(false,"No payment. Please try again")
return false
end if
End Function
Function order_status_dialog(success as boolean, msg as String) as void
dialog = CreateObject("roMessageDialog")
port = CreateObject("roMessagePort")
dialog.SetMessagePort(port)
if success = true then
dialog.SetTitle("Order Completed Successfully")
str = "Your Purchase Completed Successfully"
else
dialog.SetTitle("Order Failed")
str = "Your Purchase Failed, " + msg
end if
dialog.SetText(str)
dialog.AddButton(1, "OK")
dialog.EnableOverlay(true)
dialog.EnableBackButton(true)
dialog.Show()
while true
dlgMsg = wait(0, dialog.GetMessagePort())
if type(dlgMsg) = "roMessageDialogEvent" then
if dlgMsg.isButtonPressed() then
if dlgMsg.GetIndex() = 1 then
if success = true then
exit while
else
exit while
end if
end if
else if dlgMsg.isScreenClosed() then
exit while
end if
end if
end while
End Function
Function get_channel_catalog() as void
g = GetGlobals(0)
g.store.GetCatalog()
while true
msg = wait(1000, g.port)
if type(msg) = "roChannelStoreEvent" then
if msg.isRequestSucceeded() then
print "getting content list"
get_content_list(msg.GetResponse())
end if
exit while
else if msg.isRequestFailed() then
print "***** Failure: " + msg.GetStatusMessage() + " Status Code: " + stri(msg.GetStatus()) + " *****"
exit while
end if
end while
End Function
Function get_content_list(items) as void
g = GetGlobals(0)
i = 0
arr = []
for each item in items
print "********************* Item " + Stri(i) + " *********************"
print item
print item.code
i = i+1
owned = false
list_item = {
Title: item.name
ID: stri(i)
code: item.code
cost: item.cost
}
print "store item : " + stri(i) + "item code" + item.code
g.store_items.Push(list_item)
end for
End Function
Function TooCast(email as String, trans as String)
print "toocast cms services post starting"
LogToServer("ToocastStart")
g = GetGlobals(0)
Identifier="ArtHouse"
TransactionId=trans
PublisherId = g.loc.publisher_id
CountryCode = g.realCountry
CountryCode = "US"
Email = email
port = CreateObject("roMessagePort")
request = CreateObject("roUrlTransfer")
request.SetMessagePort(port)
requestUrl = "http://plat-test.filmboxlive.com/payment/roku/verify"
params = "TransactionId="+TransactionId+"&PublisherId="+PublisherId+"&Email="+Email+"&CountryCode="+CountryCode+"&Identifier=ArtHouse&device=roku"
request.SetUrl(requestUrl)
request.AddHeader("Content-Type", "application/x-www-form-urlencoded")
print "request is ready"
if (request.AsyncPostFromString(params))
msg = wait(0, port)
if (type(msg) = "roUrlEvent")
code = msg.GetResponseCode()
print "we got http response"
if (code = 200)
LogToServer("its 200 ok")
json = ParseJSON(msg.GetString())
if(json <> invalid and json.Success <> invalid and json.Success = true)
LogToServer("toocast return success")
return "success"
else if (json.Success = false)
LogToServer("toocast return error : "+ json.Exception.Message)
return json.Exception.Message
else
LogToServer("bad response..")
request.AsyncCancel()
end if
else
SendLogs(["bad response not 200:", codes])
codes = ToStr(code)
LogToServer(codes)
print "not 200"
print code
errorsArr = msg.GetFailureReason()
print errorsArr
errorsArr = msg.GetResponseHeadersArray()
for each header in errorsArr
LogToServer(header)
end for
return codes
endif
else if (event = invalid)
request.AsyncCancel()
endif
endif
End Function
Sub LogToServer(message as String)
port = CreateObject("roMessagePort")
request = CreateObject("roUrlTransfer")
request.SetMessagePort(port)
print "Log to Server"; message
message = HttpEncode(message)
requestUrl = "http://xxx/api/v0.1/admin/writeToFile/"+message
request.SetUrl(requestUrl)
if (request.AsyncGetToString())
msg = wait(0, port)
if (type(msg) = "roUrlEvent")
code = msg.GetResponseCode()
if (code = 200)
print "logged"
endif
else if (event = invalid)
request.AsyncCancel()
endif
endif
End Sub
I can't get purchaseID or purchaseDetails. and g.store.GetPurchases() return uninitialized .
1 REPLY 1
EnTerr
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2016
12:44 PM
Re: Roku 4 in app purchase ıd problem
Good grief man, that's some verbose code. Don't have the mental strength to read it all. Doesn't seem bad... just long. Last night i finished my in-app purchase code and it does it all in 30-40 lines - check previous purchase, dialog, do the due, store the due, report the deed. In my defense, i had legitimate reason to cram it though.
In your defense, i see lots of logging to server... sucks that can't use debug console with billing, doesn't it? Let me peddle again my proposal to fix that viewtopic.php?f=34&t=95553 🙂
I don't think Roku4 has issue with billing, seems to work for me. Have a look at viewtopic.php?f=34&t=95592 for some ideas - for example i notice if doOrder() is canceled by user, you may still get seemingly completed order event - sans `purchaseId` though.
In your defense, i see lots of logging to server... sucks that can't use debug console with billing, doesn't it? Let me peddle again my proposal to fix that viewtopic.php?f=34&t=95553 🙂
I don't think Roku4 has issue with billing, seems to work for me. Have a look at viewtopic.php?f=34&t=95592 for some ideas - for example i notice if doOrder() is canceled by user, you may still get seemingly completed order event - sans `purchaseId` though.