Sub billing_PurchasesUpdated (Result As BillingResult, Purchases As List)
    'This event will be raised when the status of one or more of the purchases has changed.
    'It will usually happen as a result of calling LaunchBillingFlow however it can be called in other cases as well.
 
    If Result.IsSuccess Then
     
        For Each pr As Purchase In Purchases
         
            If pr.Sku = ADS_SDK_ID Then
                HandleAdsPurchase(pr)
            Else
                Log("Unexpected product...")
            End If
         
        Next
     
    End If
 
End Sub
Private Sub HandleAdsPurchase (pr As Purchase)
 
    If pr.PurchaseState <> pr.STATE_PURCHASED Then Return
    'Verify the purchase signature.
    'This cannot be done with the test id.
 
    If pr.Sku.StartsWith("android.test") = False And billing.VerifyPurchase(pr, BILLING_KEY) = False Then
        Log("Invalid purchase")
        Return
    End If
 
    If pr.IsAcknowledged = False Then
        'we either acknowledge the product or consume it.
        Wait For (billing.AcknowledgePurchase(pr.PurchaseToken, "")) Billing_AcknowledgeCompleted (Result As BillingResult)
        Log("Acknowledged: " & Result.IsSuccess)
 
    End If
 
    Log("AdsRemoved")
    CheckDonation
 
End Sub
Private Sub btnDonazione_Click
 
    'make sure that the store service is connected
    Wait For (billing.ConnectIfNeeded) Billing_Connected (Result As BillingResult)
    If Result.IsSuccess Then
        'get the sku details
        Dim sf As Object = billing.QuerySkuDetails("inapp", Array(ADS_SDK_ID))
        Wait For (sf) Billing_SkuQueryCompleted (Result As BillingResult, SkuDetails As List)
        If Result.IsSuccess And SkuDetails.Size = 1 Then
            Result = billing.LaunchBillingFlow(SkuDetails.Get(0))
            If Result.IsSuccess Then
                CheckDonation
                Return
            End If
        End If
    End If
    ToastMessageShow("Error starting billing process", True)
 
End Sub
Private Sub CheckDonation
 
    Wait For (billing.ConnectIfNeeded) Billing_Connected (Result As BillingResult)
    If Result.IsSuccess Then
        Wait For (billing.QueryPurchases("inapp")) Billing_PurchasesQueryCompleted (Result As BillingResult, Purchases As List)
        Log("Query completed: " & Result.IsSuccess)
        If Result.IsSuccess Then
            For Each pr As Purchase In Purchases
                If pr.Sku = ADS_SDK_ID Then HandleAdsPurchase(pr)
             
                If pr.PurchaseState= pr.STATE_PURCHASED Then
                    giaAcquistato =True
                Else
                    giaAcquistato =False
                End If
             
            Next
        End If
    End If
 
    If giaAcquistato =True Then
        btnDonazione.Visible =False
    Else
        btnDonazione.Visible =True
    End If
 
End Sub