com.mypos.myposcheckout.ipc

 

Class Helper

java.lang.Object com.mypos.myposcheckout.ipc.Helper


public abstract class Helper
extends java.lang.Object
IPC Library helper functions.

 

Constructor Summary

Constructors
Constructor and Description
Helper() 

 

Method Summary

All MethodsStatic MethodsConcrete Methods
Modifier and Type Method and Description
static java.lang.String buildQueryFromParameterMap(java.util.Map<java.lang.String,java.lang.String[]> queryParamsMap)
Create a query string from the API request parameter map.
static java.lang.String concatRequestParams(java.util.Collection<java.lang.String> params)
Concatenates all request parameters, so they can be used for creating an API request signature, or verifying one.
static java.lang.String concatRequestParams(java.util.Map<java.lang.String,java.lang.String[]> params)
Concatenates all request parameters, so they can be used for creating an API request signature, or verifying one.
static java.lang.String concatStringArray(java.lang.String[] pieces, java.lang.String glue)
Concatenates the elements of the string array to a single string.
static java.security.PrivateKey createPrivateKeyFromString(java.lang.String privateKeyString)
Create a PrivateKey object from the provided PEM encoded data.
static java.security.PublicKey createPublicKeyFromString(java.lang.String publicKeyString)
Create a PublicKey object from the provided PEM encoded data.
static java.lang.String encryptStringWithPublicKey(java.lang.String data, java.security.PublicKey key)
Encrypts a string with a provided public key.
static boolean isNumeric(java.lang.String str)
Checks if a string is numeric (consisted only of digits).
static boolean isValidEmail(java.lang.String str)
Checks if a string is a valid email address.
static boolean isValidOrderId(java.lang.String str)
Check if a string is in a valid order id format.
static boolean isValidOutputFormat(CommunicationFormat format)
Checks if a CommunicationFormat value can be used as an output format (to send data to the API).
static boolean isValidTrnRef(java.lang.String str)
Check if a string is in a valid transaction reference format.
static java.lang.String readFile(java.lang.String file) 
static java.lang.String readFile(java.lang.String file, java.nio.charset.Charset cs) 
static java.lang.String readFile(java.lang.String file, java.lang.String csName) 
static java.lang.String readInputStream(java.io.InputStream inputStream, java.nio.charset.Charset cs) 
static java.lang.String readInputStream(java.io.InputStream inputStream, java.lang.String csName) 

 

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

 

Constructor Detail

Helper

public Helper()

 

Method Detail

createPrivateKeyFromString

public static java.security.PrivateKey createPrivateKeyFromString(java.lang.String privateKeyString)
                                                           throws java.security.spec.InvalidKeySpecException,
                                                                  java.security.NoSuchAlgorithmException,
                                                                  java.io.UnsupportedEncodingException
Create a PrivateKey object from the provided PEM encoded data. The first and last lines are not actual data so they are removed.
Parameters:
privateKeyString - the Base64 encoded private key
Returns:
a PrivateKey object
Throws:
java.security.spec.InvalidKeySpecException - if the private key can not be generated
java.security.NoSuchAlgorithmException - If the KeyFactory does not support the needed algorithm.
java.io.UnsupportedEncodingException - If the private key string could not be decoded.

createPublicKeyFromString

public static java.security.PublicKey createPublicKeyFromString(java.lang.String publicKeyString)
                                                         throws java.security.spec.InvalidKeySpecException,
                                                                java.security.NoSuchAlgorithmException,
                                                                java.io.UnsupportedEncodingException
Create a PublicKey object from the provided PEM encoded data. The first and last lines are not actual data so they are removed.
Parameters:
publicKeyString - the Base64 encoded public key
Returns:
a PublicKey object
Throws:
java.security.spec.InvalidKeySpecException - if the public key can not be generated
java.security.NoSuchAlgorithmException - If the KeyFactory does not support the needed algorithm.
java.io.UnsupportedEncodingException - If the private key string could not be decoded.

encryptStringWithPublicKey

public static java.lang.String encryptStringWithPublicKey(java.lang.String data,
                                                          java.security.PublicKey key)
                                                   throws javax.crypto.BadPaddingException,
                                                          javax.crypto.IllegalBlockSizeException,
                                                          java.security.InvalidKeyException,
                                                          java.security.NoSuchAlgorithmException,
                                                          javax.crypto.NoSuchPaddingException,
                                                          java.io.UnsupportedEncodingException
Encrypts a string with a provided public key.
Parameters:
data - the string to be encrypted
key - the PublicKey object, used for encryption
Returns:
a base64 encoded representation of the encrypted data
Throws:
javax.crypto.BadPaddingException - if the data is not padded properly
javax.crypto.IllegalBlockSizeException - When the length of data provided to a block cipher is incorrect.
java.security.InvalidKeyException - if the public key is invalid
java.security.NoSuchAlgorithmException - If the KeyFactory does not support the needed algorithm..
javax.crypto.NoSuchPaddingException - when the padding mechanism is not available
java.io.UnsupportedEncodingException - If the private key string could not be decoded.

readFile

public static java.lang.String readFile(java.lang.String file)
                                 throws java.io.IOException
Throws:
java.io.IOException

readFile

public static java.lang.String readFile(java.lang.String file,
                                        java.lang.String csName)
                                 throws java.io.IOException
Throws:
java.io.IOException

readFile

public static java.lang.String readFile(java.lang.String file,
                                        java.nio.charset.Charset cs)
                                 throws java.io.IOException
Throws:
java.io.IOException

readInputStream

public static java.lang.String readInputStream(java.io.InputStream inputStream,
                                               java.lang.String csName)
                                        throws java.io.IOException
Throws:
java.io.IOException

readInputStream

public static java.lang.String readInputStream(java.io.InputStream inputStream,
                                               java.nio.charset.Charset cs)
                                        throws java.io.IOException
Throws:
java.io.IOException

buildQueryFromParameterMap

public static java.lang.String buildQueryFromParameterMap(java.util.Map<java.lang.String,java.lang.String[]> queryParamsMap)
                                                   throws java.io.UnsupportedEncodingException
Create a query string from the API request parameter map.
Parameters:
queryParamsMap - the query parameter map
Returns:
a query string
Throws:
java.io.UnsupportedEncodingException - If the query string could not be decoded.

concatRequestParams

public static java.lang.String concatRequestParams(java.util.Collection<java.lang.String> params)
Concatenates all request parameters, so they can be used for creating an API request signature, or verifying one. "-" is used as a separator.
Parameters:
params - a collection of strings to be concatenated
Returns:
a string in the form of "abc-xyz-123"

concatRequestParams

public static java.lang.String concatRequestParams(java.util.Map<java.lang.String,java.lang.String[]> params)
Concatenates all request parameters, so they can be used for creating an API request signature, or verifying one. "-" is used as a separator.
Parameters:
params - a collection of strings to be concatenated
Returns:
a string in the form of "abc-xyz-123"

concatStringArray

public static java.lang.String concatStringArray(java.lang.String[] pieces,
                                                 java.lang.String glue)
Concatenates the elements of the string array to a single string. The glue parameter is used as a separator.
Parameters:
pieces - an array of strings to be concatenated
glue - the string used as separator
Returns:
a string in the form of "abc-xyz-123" if "-" is used as glue

isNumeric

public static boolean isNumeric(java.lang.String str)
Checks if a string is numeric (consisted only of digits).
Parameters:
str - a a string that may be consisted of digits only
Returns:
true if the string contains only digits, false otherwise

isValidEmail

public static boolean isValidEmail(java.lang.String str)
Checks if a string is a valid email address. Does not validate against the syntax in RFC 822. Instead a simpler approach (regular expression) is used. https://www.w3.org/TR/html5/forms.html#valid-e-mail-address
Parameters:
str - a string that may contain an email address
Returns:
true if the string is a valid email address, false otherwise

isValidOutputFormat

public static boolean isValidOutputFormat(CommunicationFormat format)
Checks if a CommunicationFormat value can be used as an output format (to send data to the API). Some formats can only be used as input (receiving data from the API).
Parameters:
format - the used communication format
Returns:
true if the format can be used as an output one

isValidTrnRef

public static boolean isValidTrnRef(java.lang.String str)
Check if a string is in a valid transaction reference format.
Parameters:
str - a string containing a transaction reference
Returns:
true if the string is a valid reference

isValidOrderId

public static boolean isValidOrderId(java.lang.String str)
Check if a string is in a valid order id format.
Parameters:
str - a string containing an order id
Returns:
true if the string is a valid id