B4J Question Status Update Notifications

aaronk

Well-Known Member
Licensed User
Hi,

I have created an iOS app using B4i, and it has in-app subscriptions in it. Using my B4J app I want to get notified when the in-app subscription changes.

In Apple Connect it has a spot for Subscription Status URL. This allows Apple to send a POST message to a server so the developer can verify the purchase when the subscription state changes.

https://developer.apple.com/library....html#//apple_ref/doc/uid/TP40008267-CH7-SW13

In my B4J app, I have added a filter but trying to work out how to read the POST message Apple sent. Reading Apples documentation it says it's a JSON message.

In my B4J app I have added the following Filter:
B4X:
Public Sub Filter(req As ServletRequest, resp As ServletResponse) As Boolean    'ignore
    Log(req.FullRequestURI)
    Dim postMap As Map = req.GetMultipartData(Globals.AppLocation,999999999999999)

    For i = 0 To postMap.Size - 1
        Log("Key: " & postMap.GetKeyAt(i))
        Log("Value: " & postMap.GetValueAt(i))
    Next

End Sub
When Apple submits the query to my server it seems to only log the URL (req.FullRequestURI) part in my code. (I do notice it logs the URL a few times sometimes)

I am guessing I am doing something wrong some where.

(not 100% sure if the map part is correct in my code above, or if that is the correct way in reading the POST body of the request?)
 

JanPRO

Well-Known Member
Licensed User
Hi,

first of all, why you are using a filter and not a server handler?

You need to read the request body and parse the json string to a Map:

B4X:
Sub Handle(req As ServletRequest, resp As ServletResponse)
    Dim TR As TextReader
    TR.Initialize(req.InputStream)
    Dim RequestBody As String = TR.ReadAll
  
    Dim JParser As JSONParser
    JParser.Initialize(RequestBody)
  
    Dim RequestMap As Map = JParser.NextObject
End Sub
Jan
 

aaronk

Well-Known Member
Licensed User
first of all, why you are using a filter and not a server handler?
Good question. I just changed it to a Handler.

Got the data (body) I needed:
B4X:
Sub Handle(req As ServletRequest, resp As ServletResponse)
    
    Log(req.FullRequestURI)

    Dim TR As TextReader
    TR.Initialize(req.InputStream)
    Dim RequestBody As String = TR.ReadAll
    
    Log(RequestBody)
 
End Sub
Thanks for your help.
 
Top