Xojo Plugin Requires Chilkat v11.0.0+
Xojo Plugin
PayPal: Decide when to renew an access token
See more PayPal Examples
Use the UTC request time and expires_in from the token example. Renew five minutes early. This is a cache decision; a revoked token can still receive HTTP 401 before its calculated expiry.
Chilkat Xojo Plugin Downloads
// Read the metadata saved by Get a sandbox access token.
Dim timing As New Chilkat.JsonObject
Dim issued As New Chilkat.CkDateTime
Dim loadedTiming As Boolean
loadedTiming = timing.LoadFile("paypal-token-timing.json")
If (loadedTiming <> True) Then
System.DebugLog("No timing metadata. Request a token.")
Return
End If
Dim validTimestamp As Boolean
validTimestamp = issued.SetFromTimestamp(timing.StringOf("issued_at"))
If (validTimestamp <> True) Then
System.DebugLog("Invalid issue time. Request a token.")
Return
End If
Dim now As New Chilkat.CkDateTime
Dim success As Boolean
success = now.SetFromCurrentSystemTime()
Dim age As Int32
age = now.DiffSeconds(issued)
Dim lifetime As Int32
lifetime = timing.IntOf("expires_in")
If ((age < 0) Or (lifetime <= 300) Or (age >= (lifetime - 300))) Then
System.DebugLog("Request a new client-credentials token.")
Return
End If
System.DebugLog("Reuse the matching token from the credential store.")