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