- Home
- Developers
Development Platform
The Smartest way to Digitalize your Payments
Collection Verification Code
try { HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create("<Verification URL>? MERCHANTCODE=" + MERCHANTCODE + &PRN=" + PRN + "&AMOUNT=" + AMOUNT); webrequest.Method = "POST"; webrequest.ContentType = "application/json"; webrequest.ContentLength = 0; Stream stream = webrequest.GetRequestStream(); stream.Close(); string result; using (WebResponse response = webrequest.GetResponse()) { using (StreamReader reader = new StreamReader(response.GetResponseStream())) { result = reader.ReadToEnd(); dynamic stuff = JsonConvert.DeserializeObject(result); string STATUS = stuff.STATUS; string RESPONSECODE = stuff.RESPONSECODE; if (STATUS == "SUCCESS") { //Transaction is successful } } } } catch (Exception ex) { //Exception thrown from the api }
try { OkHttpClient client = new OkHttpClient().newBuilder().build(); MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); RequestBody body = RequestBody.create(mediaType, "MERCHANTCODE = <merchantCode> & PRN = <merchantPRN>& AMOUNT = <amount>"); Request request = new Request.Builder() .url("<Verification URL>") .method("POST", body) .addHeader("Content-Type", "application/x-www-form-urlencoded") .build(); Response response = client.newCall(request).execute(); } catch (Exception ex) { //Exception thrown from the api }
Collection Encryption Code
public static string Encrypt(string plainText, string key){ try{ RijndaelManaged aes = new RijndaelManaged(); aes.KeySize = 256; aes.BlockSize = 128; aes.Padding = PaddingMode.PKCS7; aes.Mode = CipherMode.CBC; aes.Key = SHA256.Create().ComputeHash(encoding.GetBytes(key)); aes.IV = MD5.Create().ComputeHash(encoding.GetBytes(key)); ICryptoTransform AESEncrypt = aes.CreateEncryptor(aes.Key, aes.IV); byte[] buffer = encoding.GetBytes(plainText); return Convert.ToBase64String( AESEncrypt.TransformFinalBlock(buffer, 0, buffer.Length)); } catch (Exception e){ //Handle Exception } } public static string Decrypt(string plainText, string key){ try{ RijndaelManaged aes = new RijndaelManaged(); aes.KeySize = 256; aes.BlockSize = 128; aes.Padding = PaddingMode.PKCS7; aes.Mode = CipherMode.CBC; aes.Key = SHA256.Create().ComputeHash(encoding.GetBytes(key)); aes.IV = MD5.Create().ComputeHash(encoding.GetBytes(key)); ICryptoTransform AESDecrypt = aes.CreateDecryptor(aes.Key, aes.IV); byte[] buffer = Convert.FromBase64String(plainText); return encoding.GetString( AESDecrypt.TransformFinalBlock(buffer, 0, buffer.Length)); } catch (Exception e){ //Handle Exception } }
private static final String TRANSFORMATION = "AES/CBC/PKCS5Padding"; private SecretKeySpec secretKey; private IvParameterSpec ivParameterSpec; public String encrypt(final String toBeEncryptString) throws Exception { if (toBeEncryptString == null) { //Handle Exception } try { final Cipher cipher = Cipher.getInstance(TRANSFORMATION); cipher.init(ENCRYPT_MODE, secretKey, ivParameterSpec); return encodeBase64String(cipher.doFinal( toBeEncryptString.getBytes(UTF_8))); } catch (final Exception ex) { //Handle Exception } } public String decrypt(final String toBeDecryptString) throws Exception { if (toBeDecryptString == null) { //Handle Exception } try { final Cipher cipher = Cipher.getInstance(TRANSFORMATION); cipher.init(DECRYPT_MODE, secretKey, ivParameterSpec); return new String(cipher.doFinal(decodeBase64(toBeDecryptString))); } catch (final Exception ex) { //Handle Exception } } public void setKey(final String key) throws Exception { if (key == null) { //Handle Exception } try { secretKey = new SecretKeySpec(sha256(key.getBytes(UTF_8)), "AES"); ivParameterSpec = new IvParameterSpec(md5(key.getBytes(UTF_8))); } catch (final Exception ex) { //Handle Exception } }
public $key, $iv; public $method = 'AES-256-CBC'; public function encrypt($toBeEncryptString){ return openssl_encrypt($toBeEncryptString, $this->method, hex2Bin($this->key), 0, hex2Bin($this->iv)); } public function decrypt($toBeDecryptString){ return openssl_decrypt($toBeDecryptString, $this->method, hex2Bin($this->key), 0, hex2Bin($this->iv)); } public function setKey($key){ $this->key = hash("sha256", $key); $this->iv = md5($key); }