iOS Question verify Receipt with php

tufanv

Expert
Licensed User
Can anyone help about this issue. I am fed up with non real purchases in my online game. I need some sort of verification or they will continue to use my in app purchases for free :/ . Only getting 21002 each time.
 

gerredtor

Active Member
Licensed User
We need the TransactionReceipt not the TransactionID but the TransactionReceipt is deprecated since IOS 7.0
 

gerredtor

Active Member
Licensed User
can Erel help us ? when he is online. this is a big problem.. it is so easy to root a iphone and fake a purchase
 

tufanv

Expert
Licensed User
Yes i everday hae around 20 fake purchase and i am about to remove the app because i am so angry with them. I hope he can help.
 

tufanv

Expert
Licensed User
I have a question. We will implement it in the next version. What will happen to older versions _ are ios apps are like android ? I mean , users have to updated to latest version to purchase ?
If it is not like that, people who did not do update will make it problem.

also when i tried your code and used
LogColor(b(),Colors.Magenta)
i get missing parameter
You can access transactionReceipt with this code:
B4X:
Dim no As NativeObject = Product
Dim b() As Byte = no.NSDataToArray(no.GetField("transactionReceipt"))
 

tufanv

Expert
Licensed User
No. Users can use an older version.
Ty
What about this :

also when i tried your code and used
LogColor(b(),Colors.Magenta)
i get missing parameter

I am not familiar with bytes obviously i am using it wrong ?
 

Filippo

Expert
Licensed User
I finally managed to validate. Thanks for all help!
Hi @tufanv ,

Can explain to me what you have done?
I have so far only implemented this under.
B4X:
Private Sub mnuInAppBilling_Click
    MyStore.RequestPayment(Product_1year)
End Sub

Private Sub MyStore_PurchaseCompleted (Success As Boolean, Product As Purchase)
    Dim PurchaseTime As Long
    Dim mp As Map
    mp.Initialize

    Log("Success = " & Success)

    If Success Then
        If Product.IsInitialized Then
            Log("Product: " & Product.ProductIdentifier & ", date=" & DateTime.Time(Product.TransactionDate) & _
       ", Transaction identifier=" & Product.TransactionIdentifier)

            Select Product.ProductIdentifier
                Case Product_1year
                    mp.Put(Product_1year, Product.TransactionDate)
                    PurchaseTime = DateTime.Add(Product.TransactionDate,1,0,0)
                Case Product_1month
                    mp.Put(Product_1month, Product.TransactionDate)
                    PurchaseTime = DateTime.Add(Product.TransactionDate,0,1,0)
            End Select

            'Lizenzfile aktualisieren oder löschen
            SavLizenzFileMap(mp, PurchaseTime)
        End If
       
    End If
End Sub

'Start Sub bei App-Start
Private Sub GetOwnedProductsOffline
    Dim PurchaseTime As Long
    Dim mp As Map
    mp.Initialize
   
    'Falls der Lizenzfile nicht vorhanden ist, dann Sub verlassen
    If Not(File.Exists(File.DirLibrary, "Cache\lizenz.txt")) Then Return
   
    mp = File.ReadMap(File.DirLibrary, "Cache\lizenz.txt")
   
    If mp.ContainsKey(Product_1year) Then
        'Jahres-Lizenz
        PurchaseTime = DateTime.Add(mp.Get(Product_1year),1,0,0)
        If DateTime.Now > PurchaseTime Then
            mp.Remove(Product_1year)
            ShowMessageLizenzExpired(Product_1year)
        End If
       
    else If mp.ContainsKey(Product_1month) Then
        'Monats-Lizenz
        PurchaseTime = DateTime.Add( mp.Get(Product_1month),0,1,0)
        If DateTime.Now > PurchaseTime Then
            mp.Remove(Product_1month)
            ShowMessageLizenzExpired(Product_1month)
        End If
    End If
   
    'Lizenzfile aktualisieren oder löschen
    SavLizenzFileMap(mp, PurchaseTime)
End Sub

Private Sub SavLizenzFileMap(mp As Map, PurchaseTime As Long)
    'Lizenzfile aktualisieren oder löschen
    If mp.Size > 0 Then
        'Log("Lizenzfile aktualisieren")
        File.WriteMap(File.DirLibrary, "Cache\lizenz.txt", mp)
       
        'Log("DateTime.Now=" & DateTime.Date(DateTime.Now))
        'Log("PurchaseTime=" & DateTime.Date(PurchaseTime))
       
        lizenzday = (PurchaseTime - DateTime.Now) / DateTime.TicksPerDay
       
        IsLicensevalid = True
       
    Else
        IsLicensevalid = False
        'Log("Lizenzfile löschen")
        File.Delete(File.DirLibrary, "Cache\lizenz.txt")
    End If
End Sub

Private Sub ShowMessageLizenzExpired(ProductId As String)
    'Meldung anzeigen das die Lizenz abgelaufen ist.
    CallSubDelayed2(Me, "ShowMessage", ProductId)
    Return
End Sub

Private Sub ShowMessage(ProductId As String)
    'Meldung anzeigen das die Lizenz abgelaufen ist.
    Select ProductId
        Case Product_1year
            Msgbox(mLanguage.getStr("strYearLicenseExpired"), mLanguage.getStr("strLicenseExpired"))
        Case Product_1month
            Msgbox(mLanguage.getStr("strMonthLicenseExpired"), mLanguage.getStr("strLicenseExpired"))
    End Select
End Sub
 

tufanv

Expert
Licensed User
Hi @tufanv ,

Can explain to me what you have done?
I have so far only implemented this under.
B4X:
Private Sub mnuInAppBilling_Click
    MyStore.RequestPayment(Product_1year)
End Sub

Private Sub MyStore_PurchaseCompleted (Success As Boolean, Product As Purchase)
    Dim PurchaseTime As Long
    Dim mp As Map
    mp.Initialize

    Log("Success = " & Success)

    If Success Then
        If Product.IsInitialized Then
            Log("Product: " & Product.ProductIdentifier & ", date=" & DateTime.Time(Product.TransactionDate) & _
       ", Transaction identifier=" & Product.TransactionIdentifier)

            Select Product.ProductIdentifier
                Case Product_1year
                    mp.Put(Product_1year, Product.TransactionDate)
                    PurchaseTime = DateTime.Add(Product.TransactionDate,1,0,0)
                Case Product_1month
                    mp.Put(Product_1month, Product.TransactionDate)
                    PurchaseTime = DateTime.Add(Product.TransactionDate,0,1,0)
            End Select

            'Lizenzfile aktualisieren oder löschen
            SavLizenzFileMap(mp, PurchaseTime)
        End If
      
    End If
End Sub

'Start Sub bei App-Start
Private Sub GetOwnedProductsOffline
    Dim PurchaseTime As Long
    Dim mp As Map
    mp.Initialize
  
    'Falls der Lizenzfile nicht vorhanden ist, dann Sub verlassen
    If Not(File.Exists(File.DirLibrary, "Cache\lizenz.txt")) Then Return
  
    mp = File.ReadMap(File.DirLibrary, "Cache\lizenz.txt")
  
    If mp.ContainsKey(Product_1year) Then
        'Jahres-Lizenz
        PurchaseTime = DateTime.Add(mp.Get(Product_1year),1,0,0)
        If DateTime.Now > PurchaseTime Then
            mp.Remove(Product_1year)
            ShowMessageLizenzExpired(Product_1year)
        End If
      
    else If mp.ContainsKey(Product_1month) Then
        'Monats-Lizenz
        PurchaseTime = DateTime.Add( mp.Get(Product_1month),0,1,0)
        If DateTime.Now > PurchaseTime Then
            mp.Remove(Product_1month)
            ShowMessageLizenzExpired(Product_1month)
        End If
    End If
  
    'Lizenzfile aktualisieren oder löschen
    SavLizenzFileMap(mp, PurchaseTime)
End Sub

Private Sub SavLizenzFileMap(mp As Map, PurchaseTime As Long)
    'Lizenzfile aktualisieren oder löschen
    If mp.Size > 0 Then
        'Log("Lizenzfile aktualisieren")
        File.WriteMap(File.DirLibrary, "Cache\lizenz.txt", mp)
      
        'Log("DateTime.Now=" & DateTime.Date(DateTime.Now))
        'Log("PurchaseTime=" & DateTime.Date(PurchaseTime))
      
        lizenzday = (PurchaseTime - DateTime.Now) / DateTime.TicksPerDay
      
        IsLicensevalid = True
      
    Else
        IsLicensevalid = False
        'Log("Lizenzfile löschen")
        File.Delete(File.DirLibrary, "Cache\lizenz.txt")
    End If
End Sub

Private Sub ShowMessageLizenzExpired(ProductId As String)
    'Meldung anzeigen das die Lizenz abgelaufen ist.
    CallSubDelayed2(Me, "ShowMessage", ProductId)
    Return
End Sub

Private Sub ShowMessage(ProductId As String)
    'Meldung anzeigen das die Lizenz abgelaufen ist.
    Select ProductId
        Case Product_1year
            Msgbox(mLanguage.getStr("strYearLicenseExpired"), mLanguage.getStr("strLicenseExpired"))
        Case Product_1month
            Msgbox(mLanguage.getStr("strMonthLicenseExpired"), mLanguage.getStr("strLicenseExpired"))
    End Select
End Sub
do you want to validate your receipt against fraud or do you want to get subscription info ? they are different things. After long tries , I had managed the auto subscription handling with ios , but i can't remember how i did it , can't find the code.
 

Filippo

Expert
Licensed User
Thank you tufanv,

I think I will also use the auto subscription, it is much easier.
The app can not be used anyway without a license.
 
Top