1. *** New version of B4J is available ***
    B4J v7.8
    Dismiss Notice

B4J Question Status Update Notifications

Discussion in 'B4J Questions' started by aaronk, Apr 22, 2019.

  1. aaronk

    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:
    Code:
    Public Sub Filter(req As ServletRequest, resp As ServletResponseAs 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?)
     
  2. JanPRO

    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:

    Code:
    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
     
  3. aaronk

    aaronk Well-Known Member Licensed User

    Good question. I just changed it to a Handler.

    Got the data (body) I needed:
    Code:
    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.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice