Skip to content

Instantly share code, notes, and snippets.

@ProKashif
Created July 21, 2020 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ProKashif/85dadae0e04bef64172eb3234128c802 to your computer and use it in GitHub Desktop.
Save ProKashif/85dadae0e04bef64172eb3234128c802 to your computer and use it in GitHub Desktop.
How to integrate Easypaisa with react-native
Add 3 packages :
import AesJs from 'aes-js';
import { Buffer } from 'buffer';
import queryString, { stringify } from 'query-string';
// Generating bytes encryption in AES, ECB mode with easypaisa HashKey
const aes = new AesJs.ModeOfOperation.ecb(AesJs.utils.utf8.toBytes(APP_STRING.HASH_KEY));
function pkcs5Pad(text: string, blockSize: number): string {
const pad = blockSize - (text.length % blockSize);
return text + String.fromCharCode(pad).repeat(pad);
}
// converting object to string with assending order
function convertObjectToString(obj: any): string {
let data = '';
Object.keys(obj)
.sort()
.forEach((key) => {
data += `${key}=${obj[key]}` + '&';
});
return data.slice(0, data.length - 1);
}
// Generating HashMapReq
const hasMapReq = Buffer.from(aes.encrypt(Buffer.from(pkcs5Pad(convertObjectToString(requestBody), 16)))).toString(
'base64',
);
appending hashMapReq with request body
requestBody['merchantHashedReq'] = hasMapReq;
Here is webView Setting
<WebView
source={{
uri: requestURL,
headers: requestHeader,
body: requestBodyParams,
method: 'POST',
}}
onNavigationStateChange={(e) => navigationURL(e)}
javaScriptEnabled
startInLoadingState
scalesPageToFit
onMessage={(e) => console.log('Click', e)}
/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment