Package vn.payos.core

Class Client

java.lang.Object
vn.payos.core.Client
Direct Known Subclasses:
PayOS, PayOSAsync

public abstract class Client extends Object
Base client class that provides common functionality for both synchronous and asynchronous payOS implementations.
  • Field Details

    • options

      protected final ClientOptions options
      options
    • VERSION

      public static final String VERSION
      VERSION
    • httpClient

      protected final okhttp3.OkHttpClient httpClient
      httpClient
    • mapper

      protected final com.fasterxml.jackson.databind.ObjectMapper mapper
      mapper
    • crypto

      protected final CryptoProvider crypto
      crypto
  • Constructor Details

    • Client

      public Client(@NonNull @NonNull String clientId, @NonNull @NonNull String apiKey, @NonNull @NonNull String checksumKey)
      Client
      Parameters:
      clientId - client id
      apiKey - api key
      checksumKey - checksum key
    • Client

      public Client(@NonNull @NonNull String clientId, @NonNull @NonNull String apiKey, @NonNull @NonNull String checksumKey, String partnerCode)
      Client
      Parameters:
      clientId - client id
      apiKey - api key
      checksumKey - checksum key
      partnerCode - partner code
    • Client

      public Client(@NonNull @NonNull ClientOptions options)
      Client
      Parameters:
      options - options
  • Method Details

    • getCrypto

      public CryptoProvider getCrypto()
      Get crypto
      Returns:
      crypto
    • buildHeaders

      protected Map<String,String> buildHeaders(Map<String,String> addl)
      Build headers
      Parameters:
      addl - addition headers
      Returns:
      headers
    • getUserAgent

      protected String getUserAgent()
      Get user-agent
      Returns:
      user-agent
    • buildUrl

      protected String buildUrl(String path, Map<String,Object> queries)
      Build URL
      Parameters:
      path - path
      queries - queries
      Returns:
      URL
    • shouldRetry

      protected boolean shouldRetry(int status)
      Should retry
      Parameters:
      status - status
      Returns:
      should retry
    • buildBody

      protected <TReq> String buildBody(TReq body)
      Build body
      Type Parameters:
      TReq - Request body type
      Parameters:
      body - body
      Returns:
      body
    • parseJson

      protected <T> T parseJson(String json, com.fasterxml.jackson.core.type.TypeReference<T> ref)
      Parse JSON
      Type Parameters:
      T - Parsed type
      Parameters:
      json - JSON
      ref - type reference
      Returns:
      Parsed type
    • applySignatureHeaders

      protected void applySignatureHeaders(Map<String,String> headers, FinalRequestOptions.SignatureOptions sig, Object body)
      Apply signature headers
      Parameters:
      headers - headers
      sig - signature
      body - body
    • validateResponseSignature

      protected void validateResponseSignature(APIResponse<?> apiResp, FinalRequestOptions.SignatureOptions sig, Object data, okhttp3.Response response)
      Validate response signature
      Parameters:
      apiResp - API Response
      sig - signature
      data - data
      response - response
    • sleep

      protected void sleep(long ms)
      Sleep
      Parameters:
      ms - sleep time
    • computeBackoffMs

      protected long computeBackoffMs(int attempt)
      Calculate retry time
      Parameters:
      attempt - attempt
      Returns:
      retry time
    • computeRetryDelayMs

      protected long computeRetryDelayMs(okhttp3.Response response, int attempt, int maxRetries, int retriesRemaining)
      Calculate retry delay based on response headers or fallback to exponential backoff
      Parameters:
      response - HTTP response with headers
      attempt - current retry attempt number
      maxRetries - maximum number of retries
      retriesRemaining - retries remaining
      Returns:
      retry delay in milliseconds
    • buildRequest

      protected okhttp3.Request buildRequest(FinalRequestOptions.HTTPMethod method, String url, String body, Map<String,String> headers)
      Build request
      Parameters:
      method - method
      url - URL
      body - body
      headers - headers
      Returns:
      request
    • processRequestBodyWithSignature

      protected <TReq> String processRequestBodyWithSignature(FinalRequestOptions<TReq> reqOpts)
      Process request body with signature
      Type Parameters:
      TReq - Request body type
      Parameters:
      reqOpts - request options
      Returns:
      request
    • processResponse

      protected <TResp> TResp processResponse(String text, int status, okhttp3.Response res, FinalRequestOptions<?> reqOpts, Class<TResp> dataClass)
      Process response
      Type Parameters:
      TResp - Response type
      Parameters:
      text - text
      status - status
      res - res
      reqOpts - response options
      dataClass - dataClass
      Returns:
      response
    • createAPIException

      protected APIException createAPIException(String text, int status)
      Create APIException
      Parameters:
      text - text
      status - status
      Returns:
      APIException
    • processFileDownloadResponse

      protected FileDownloadResponse processFileDownloadResponse(okhttp3.Response res) throws IOException
      Process file download response
      Parameters:
      res - res
      Returns:
      file
      Throws:
      IOException - exception