![JAR search and dependency download from the Maven repository](/logo.png)
com.payu.sdk.api.http.PayUAuthenticator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of api-client Show documentation
Show all versions of api-client Show documentation
A fresh implementation of the PayU API Client for Android
The newest version!
package com.payu.sdk.api.http;
import com.squareup.okhttp.Credentials;
import com.squareup.okhttp.Request;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import okio.ByteString;
import static com.payu.sdk.api.constants.Headers.AUTHORIZATION_HEADER_NAME;
import static com.payu.sdk.api.constants.Headers.IF_MATCH_HEADER_NAME;
public abstract class PayUAuthenticator {
private static final String ALGORITHM = "SHA-256";
private static final String ENCODING = "UTF-8";
private final String apiKey;
private final String apiLogin;
private final String fingerprint;
public PayUAuthenticator(String apiLogin, String apiKey, String fingerprint) {
this.apiLogin = apiLogin;
this.apiKey = apiKey;
this.fingerprint = fingerprint;
}
protected Request authRequest(Request.Builder requestBuilder) {
AuthorizationHeader(requestBuilder);
IfMatchHeader(requestBuilder);
return requestBuilder.build();
}
private void AuthorizationHeader(Request.Builder requestBuilder) {
requestBuilder.addHeader(AUTHORIZATION_HEADER_NAME, Credentials.basic(apiLogin, apiKey));
}
private void IfMatchHeader(Request.Builder requestBuilder) {
requestBuilder.addHeader(IF_MATCH_HEADER_NAME, sha256Hex(fingerprint));
}
private String sha256Hex(String s) {
try {
MessageDigest messageDigest = MessageDigest.getInstance(ALGORITHM);
byte[] sha256bytes = messageDigest.digest(s.getBytes(ENCODING));
return ByteString.of(sha256bytes).hex();
} catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
throw new AssertionError(e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy