Close
Loading...
- Getting Started
- APIs
- Digital Banking
- Accounts
- Overview
- API Reference
- Customers
- Overview
- API Reference
- Create Individual Customer
- Customer Employment Information Update
- Customer General Information
- Customer List
- Unsuscribe Customer
- Update Customer Identity Documents
- Update Customer
- Get Customer Action Logs
- Get Customer Risk Indicators
- Get List of Customers
- Get Supporting Documents
- Get a Customer Document
- Onboarding
- Overview
- API Reference
- Device Registration
- Token Update
- Onboarding Session
- Session Summary
- Get Terms and Conditions
- Accept Terms and Conditions
- Membership Payment
- Get Biometric Applicant ID
- Residence Address
- Personal Information
- OTP Request Via SMS or E-mail
- OTP Verification
- Occupation
- Other Type of Occupation
- Income Source
- Expected Account Activity
- Regulatory Questions
- Get Customer's Support Documents
- Upload Support Document
- User Creation
- Approve Account
- Profile
- Program Profiles
- Programs
- Operations
- Accounts
- Card Solutions
- Cards
- Overview
- API Reference
- Card And Account Bundled
- Card Information
- Card Active Status
- Card Replacement
- Block Card
- Unblock Card
- Card PIN Assignment
- Card PIN update
- Card Movements Query
- Transaction Detail
- Transaction Summary
- Cash In
- Cash Out
- Request Cash in
- Cardholder Creation
- Account Balance By CardId
- Virtual to physical card
- Card QR code
- QR Code for Payments
- Cards List by Document Id
- Cash out reverse
- Cash in reverse
- Send money
- Customize Cardholder Limits
- Customize Operation Limits
- Update Transaction
- Cards
- Payment Infrastructure
- Digital Banking
- SDKs
- Tokenization
- Overview
- Document Reference
- Tokenization
Overview
Technical documentation
Integration
Integration
JAVA Code
package alias_directory_api;
//Doc: https://developer.novopayment.com/api/alias-directory-api/alias-info-api
import cards_api.CardAndAccountBundled;
import com.nimbusds.jose.*;
import com.nimbusds.jose.crypto.RSADecrypter;
import com.nimbusds.jose.crypto.RSAEncrypter;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;
import org.bouncycastle.util.io.pem.PemObject;
import org.bouncycastle.util.io.pem.PemReader;
import org.json.JSONObject;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.logging.Logger;
public class AliasInfoAPI {
private static Logger LOGGER = Logger.getLogger(CardAndAccountBundled.class.getName());
final static private String CONST_TRUE = "TRUE";
public static void main(String[] args) throws Exception {
//Oauth2 token
String token = "<BEARER_TOKEN>";
//To indicate that the request is encrypted
String encrypted = "TRUE";
final HttpClient httpClient = HttpClients.custom().build();
final String baseUrl = "https://sandbox-api.novopayment.com/aliasdirectory/v1";
String bodyRequest = "{\n" +
" \"alias\": \"51934586958\"\n" +
"}";
JWEHeader header = null;
Payload payload = null;
if(encrypted.equalsIgnoreCase(CONST_TRUE))
{
header = new JWEHeader(JWEAlgorithm.RSA_OAEP_256, EncryptionMethod.A256CBC_HS512);
payload = new Payload(bodyRequest);
JWEObject jwe = new JWEObject(header, payload);
RSAPublicKey publicRsaKey = readPublicKey(new File("jwe_public_key.pem"));
jwe.encrypt(new RSAEncrypter(publicRsaKey));
bodyRequest = "{\n" +
" \"data\":\""+jwe.serialize()+"\"\n" +
" }";
System.out.println(bodyRequest);
}
StringEntity entity = new StringEntity(bodyRequest);
HttpUriRequest request = RequestBuilder.post()
.setUri(baseUrl+"/aliasinfo")
.setHeader(HttpHeaders.CONTENT_TYPE, "application/json")
.setHeader(HttpHeaders.AUTHORIZATION, "Bearer "+token)
.setHeader("X-Encrypted", encrypted)
.setEntity(entity)
.build();
HttpResponse response = null;
response = httpClient.execute(request);
BufferedReader reader = null;
reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line = "";
String bodyResponse = "";
while (true) {
if (!((line = reader.readLine()) != null)) break;
bodyResponse+=line;
}
if(encrypted.equalsIgnoreCase(CONST_TRUE)) {
LOGGER.info(bodyResponse);
// create a decrypter with the specified private RSA key
RSAPrivateKey privateRsaKey = readPrivateKey("jwe_private_key");
RSADecrypter decrypter = new RSADecrypter(privateRsaKey);
JSONObject json = new JSONObject(bodyResponse);
JWEObject jwe = JWEObject.parse(json.getString("data"));
// do the decryption
jwe.decrypt(decrypter);
json.put("data", jwe.getPayload().toString());
bodyResponse = json.toString();
}
LOGGER.info(bodyResponse);
}
public static RSAPublicKey readPublicKey(File file) throws Exception {
KeyFactory factory = KeyFactory.getInstance("RSA");
try (FileReader keyReader = new FileReader(file);
PemReader pemReader = new PemReader(keyReader)) {
PemObject pemObject = pemReader.readPemObject();
byte[] content = pemObject.getContent();
X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(content);
return (RSAPublicKey) factory.generatePublic(pubKeySpec);
}
}
public static RSAPrivateKey readPrivateKey(final String keyfile){
try {
Process p;
p = Runtime.getRuntime().exec("openssl pkcs8 -nocrypt -topk8 -inform PEM " +
"-in " + keyfile + ".pem -outform DER -out " + keyfile + ".der");
p.waitFor();
System.out.println("Command executed" + (p.exitValue() == 0 ? " successfully" : " with error" ));
} catch ( IOException | InterruptedException e) {
e.printStackTrace();
System.exit(1);
}
PrivateKey myPrivKey = null;
try {
byte[] keyArray = Files.readAllBytes(Paths.get(keyfile + ".der"));
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyArray);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
myPrivKey = keyFactory.generatePrivate(keySpec);
} catch (IOException | NoSuchAlgorithmException | InvalidKeySpecException e){
e.printStackTrace();
System.exit(1);
}
RSAPrivateKey rsa = (RSAPrivateKey) myPrivKey;
return rsa;
}
}
JAVA Dependencies
plugins {
// Apply the java plugin to add support for Java
id 'java'
// Apply the application plugin to add support for building a CLI application
id 'application'
}
repositories {
// Use jcenter for resolving dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
dependencies {
// This dependency is used by the application.
implementation 'com.google.guava:guava:28.0-jre'
// https://mvnrepository.com/artifact/com.nimbusds/nimbus-jose-jwt
implementation group: 'com.nimbusds', name: 'nimbus-jose-jwt', version: '9.10'
// https://mvnrepository.com/artifact/org.bouncycastle/bcpkix-jdk15on
implementation group: 'org.bouncycastle', name: 'bcpkix-jdk15on', version: '1.69'
// https://mvnrepository.com/artifact/org.json/json
implementation group: 'org.json', name: 'json', version: '20210307'
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.11'
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.14.1'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.14.1'
}
application {
// Define the main class for the application
mainClassName = 'my_project.App'
}
On this page