Package vn.payos.core
Class Client
java.lang.Object
vn.payos.core.Client
- Direct Known Subclasses:
PayOS,PayOSAsync
Base client class that provides common functionality for both synchronous and asynchronous payOS
implementations.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final CryptoProvidercryptoprotected final okhttp3.OkHttpClienthttpClientprotected final com.fasterxml.jackson.databind.ObjectMappermapperprotected final ClientOptionsoptionsstatic final StringVERSION -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidapplySignatureHeaders(Map<String, String> headers, FinalRequestOptions.SignatureOptions sig, Object body) Apply signature headersprotected <TReq> StringbuildBody(TReq body) Build bodybuildHeaders(Map<String, String> addl) Build headersprotected okhttp3.RequestbuildRequest(FinalRequestOptions.HTTPMethod method, String url, String body, Map<String, String> headers) Build requestprotected StringBuild URLprotected longcomputeBackoffMs(int attempt) Calculate retry timeprotected longcomputeRetryDelayMs(okhttp3.Response response, int attempt, int maxRetries, int retriesRemaining) Calculate retry delay based on response headers or fallback to exponential backoffprotected APIExceptioncreateAPIException(String text, int status) Create APIExceptionGet cryptoprotected StringGet user-agentprotected <T> TParse JSONprotected FileDownloadResponseprocessFileDownloadResponse(okhttp3.Response res) Process file download responseprotected <TReq> StringprocessRequestBodyWithSignature(FinalRequestOptions<TReq> reqOpts) Process request body with signatureprotected <TResp> TRespprocessResponse(String text, int status, okhttp3.Response res, FinalRequestOptions<?> reqOpts, Class<TResp> dataClass) Process responseprotected booleanshouldRetry(int status) Should retryprotected voidsleep(long ms) Sleepprotected voidvalidateResponseSignature(APIResponse<?> apiResp, FinalRequestOptions.SignatureOptions sig, Object data, okhttp3.Response response) Validate response signature
-
Field Details
-
options
options -
VERSION
VERSION -
httpClient
protected final okhttp3.OkHttpClient httpClienthttpClient -
mapper
protected final com.fasterxml.jackson.databind.ObjectMapper mappermapper -
crypto
crypto
-
-
Constructor Details
-
Client
public Client(@NonNull @NonNull String clientId, @NonNull @NonNull String apiKey, @NonNull @NonNull String checksumKey) Client- Parameters:
clientId- client idapiKey- api keychecksumKey- checksum key
-
Client
public Client(@NonNull @NonNull String clientId, @NonNull @NonNull String apiKey, @NonNull @NonNull String checksumKey, String partnerCode) Client- Parameters:
clientId- client idapiKey- api keychecksumKey- checksum keypartnerCode- partner code
-
Client
Client- Parameters:
options- options
-
-
Method Details
-
getCrypto
Get crypto- Returns:
- crypto
-
buildHeaders
Build headers- Parameters:
addl- addition headers- Returns:
- headers
-
getUserAgent
Get user-agent- Returns:
- user-agent
-
buildUrl
Build URL- Parameters:
path- pathqueries- queries- Returns:
- URL
-
shouldRetry
protected boolean shouldRetry(int status) Should retry- Parameters:
status- status- Returns:
- should retry
-
buildBody
Build body- Type Parameters:
TReq- Request body type- Parameters:
body- body- Returns:
- body
-
parseJson
Parse JSON- Type Parameters:
T- Parsed type- Parameters:
json- JSONref- type reference- Returns:
- Parsed type
-
applySignatureHeaders
protected void applySignatureHeaders(Map<String, String> headers, FinalRequestOptions.SignatureOptions sig, Object body) Apply signature headers- Parameters:
headers- headerssig- signaturebody- body
-
validateResponseSignature
protected void validateResponseSignature(APIResponse<?> apiResp, FinalRequestOptions.SignatureOptions sig, Object data, okhttp3.Response response) Validate response signature- Parameters:
apiResp- API Responsesig- signaturedata- dataresponse- 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 headersattempt- current retry attempt numbermaxRetries- maximum number of retriesretriesRemaining- 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- methodurl- URLbody- bodyheaders- headers- Returns:
- request
-
processRequestBodyWithSignature
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- textstatus- statusres- resreqOpts- response optionsdataClass- dataClass- Returns:
- response
-
createAPIException
Create APIException- Parameters:
text- textstatus- status- Returns:
- APIException
-
processFileDownloadResponse
Process file download response- Parameters:
res- res- Returns:
- file
- Throws:
IOException- exception
-