Package com.stripe

Class StripeContext

java.lang.Object
com.stripe.StripeContext

public final class StripeContext extends Object
The StripeContext class provides an immutable container for interacting with the `Stripe-Context` header.

You can use it whenever you're initializing a `StripeClient` or sending `stripe_context` with a request. It's also found in the `EventNotification.context` property.

  • Constructor Details

    • StripeContext

      public StripeContext()
      Creates a new StripeContext with no segments.
    • StripeContext

      public StripeContext(List<String> segments)
      Creates a new StripeContext with the specified segments.
      Parameters:
      segments - the list of context segments
  • Method Details

    • push

      public StripeContext push(String segment)
      Returns a new StripeContext with the given segment added to the end.
      Parameters:
      segment - the segment to add
      Returns:
      a new StripeContext instance with the segment appended
    • pop

      public StripeContext pop()
      Returns a new StripeContext with the last segment removed.
      Returns:
      a new StripeContext instance with the last segment removed
    • toString

      public String toString()
      Converts the context to a string by joining segments with '/'.
      Overrides:
      toString in class Object
      Returns:
      string representation of the context segments joined by '/', `null` if there are no segments (useful for clearing context)
    • parse

      public static StripeContext parse(String contextStr)
      Parse a context string into a StripeContext instance.
      Parameters:
      contextStr - string to parse (segments separated by '/')
      Returns:
      StripeContext instance with segments from the string
    • getSegments

      public List<String> getSegments()
      Returns an unmodifiable list of the current segments.
      Returns:
      the list of segments
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object