I am integrating citrus payment into android app , everything is working well in sandbox till my transaction is successful but once my transaction is successful i get below logs :
MOTO SUCCESSFUL***{"txMsg":"Transaction successful","pgRespCode":"0","redirectUrl":"https://sandbox.citruspay.com/mpiServlet/715259413249776a736d6a62546c5a413247745871773d3d"}
Which says transaction is successful and i can see in my sandbox consumer account that transaction is successful but when it redirect to above url in log it shows below screen :
And When i try to press back button :
There is no way out to reach my last activity in application i tried to put return url in app as : private static final String RETURN_URL = "http://my.app";
which should return to my activity but didn't help, Any help or hint would be greatly appreciated.
I resolved the Issue Via sending the return page url which was hosted on my server itself like below :
<?php
$access_key = "xxxx"; //put your own access_key - found in admin panel
$secret_key = "xxxxx"; //put your own secret_key - found in admin panel
$return_url = "http://xxxxx/Citrus/return_page.php"; //put your own return_url.php here.
$txn_id = time() . rand(10000,99999);
$value = $_GET["amount"]; //Charge amount is in INR by default
$data_string = "merchantAccessKey=" . $access_key
. "&transactionId=" . $txn_id
. "&amount=" . $value;
$signature = hash_hmac('sha1', $data_string, $secret_key);
$amount = array('value' => $value, 'currency' => 'INR');
$bill = array('merchantTxnId' => $txn_id,
'amount' => $amount,
'requestSignature' => $signature,
'merchantAccessKey' => $access_key,
'returnUrl' => $return_url); echo json_encode($bill); ?>
And return url shows the message successful transaction and back to Activity ! .
<html>
<head>
<script type="text/javascript">
var globaldata;
function setdata(data) {
globaldata = data;
}
function postResponseiOS() {
return globaldata;
}
function postResponse(data) {
CitrusResponse.pgResponse(data); }
</script>
</head>
<body>
</body>
</html>
<?php
$secret_key = "xxxxx";
$data =array();
foreach ($_POST as $name => $value) {
$data[$name] = $value;
}
$verification_data = $data['TxId']
. $data['TxStatus']
. $data['amount']
. $data['pgTxnNo']
. $data['issuerRefNo']
. $data['authIdCode']
. $data['firstName']
. $data['lastName']
. $data['pgRespCode']
. $data['addressZip'];
$signature = hash_hmac('sha1', $verification_data, $secret_key);
if ($signature == $data['signature'])
{
$json_object = json_encode($data);
echo "<script>
postResponse('$json_object');
</script>";
echo"<script> setdata ('$json_object');
</script>";
}
else {
$response_data = array("Error" => "Transaction Failed",
"Reason" => "Signature Verification Failed");
$json_object = json_encode($response_data);
echo "
<script>
postResponse('$json_object');
</script>";
echo"
<script>
setdata ('$json_object');
</script>";
}
?>
Related
I have written an API for client side in node and I want that when a client hits the end-point only a string response is shown to client but as client hits the API an html file should be updated on the client side. Please let me know how to generate separate responses to client and admin from a single API in node.
app.get('/', function(req, res) {
res.sendfile('index.html');//sending file in response to client
});
// something like above is been done which sends response file to the client but i wants that it only updated and shown to the admin at the time of request.
const app = express();
const port = process.env.PORT || 3000;
const server = require('http').createServer(app);
//socket imported
const io = require('socket.io')(server);
//end-point 'ring'
app.post('/ring', (request, response)=>
{
console.log(request.body);
const data=request.body;
if(!data)
{
//if data is not sent then error status
return response.status(400).send('bad request');
}
// here i need to implement explicit responses
console.log((`data is----> ${data}`));
//here i'm emitting my json object to the html file
// this json object should be sent to the html to show
io.emit('message'{'requestbody':request.body,'status':'ringing'});
// sending success response to the client
response.status(200).send('ringing');
});
Index.html code
<body>
<script src=”/socket.io/socket.io.js”></script>
<script
//initializing socket
var socket = io();
//trying to recieve json object from socket
socket.on(‘message’, addMessages)>//calling the addMessage function
</script>
<script>
function addMessages(message)
{
//setting the text extracted from json object
$(“#messages”).append(`
//setting probeId
<h4> ${message.probeId} </h4>
//setting status
<p> ${message.status} </p>`)
}
</script>
//my 'index.html' file should be updated when user hits the ring api and user gets a string response.
I am pretty sure you don't need socket for what you need.
If my understanding of the question is good enough, you can just add a parameter to separate the type of return
app.post('/ring', (request, response)=>
{
console.log(request.body);
const data=request.body;
if(!data)
{
//if data is not sent then error status
return response.status(400).send('bad request');
}
if(data.returnType === 'html'){
response.sendFile(path.join(__dirname + '/index.html'));
} else {
response.status(200).send('ringing');
}
})
returnType is a POST parameter to separate the return types.
update :
if you want to update your index
app.post('/ring', (request, response)=>
{
console.log(request.body);
const data=request.body;
if(!data)
{
//if data is not sent then error status
return response.status(400).send('bad request');
}
if(data.returnType === 'html'){
response.sendFile(path.join(__dirname + '/index.html'));
} if(data.returnType === 'json'){
// Business logic here
let result = { a: 'aez' };
return response.json(result);
} else {
response.status(200).send('ringing');
}
})
And in your html
<body>
<script>
$("#envoyer").click(function(){
$.ajax({
url : 'send_mail.php',
type : 'POST',
data : 'dataType=json'
success: handle
});
});
function handle(result, status)
{
//setting the text extracted from json object
$(“#result”).append(`<div> ${result.a} </div>`)
}
</script>
</body>
I m developing and android application using phonegap . I m follwing this tutorial https://github.com/phonegap-build/FacebookConnect/tree/962eb0a1c07935ff813e28aa9eaa5581f2e10416 and i m succesfully connecting to facebook in Phonegap and i m displaying my Facebook username and Picture in my (Index.html) and sending my informations to the server.
In this page (index.html) , i have a button that let me go to another HTML Page(Profile.html). I m trying to display my facebook informations to this page (Profile.html) as well as the (Index.html)
Here is the code in my JS File that let me display my informations after a connect to facebook in my Indx.HTML Page and let me also send these informations to the server:
function handleStatusChange(session)
{
console.log('Got the user\'s session: ' + JSON.stringify(session));
alert('Got the user\'s session: ' + JSON.stringify(session));
if (session.authResponse)
{
//document.body.className = 'connected';
//Fetch user's id, name, and picture
FB.api('/me',
{
fields: 'name, picture,first_name,last_name,email'
},
function(response)
{
if (!response.error)
{
document.body.className = 'connected';
user = response;
console.log('Got the user\'s name and picture: ' + JSON.stringify(response));
console.log('FB name, ' + response.name);
console.log(('FB picture, ' + response.picture.data.url));
// alert('Fb Id,'+response.id);
//alert('Email'+response.email);
// alert('FB Last name'+response.first_name);
// alert('FB name, ' + response.last_name);
//Update display of user name and picture
if (document.getElementById('user-name'))
{
document.getElementById('user-name').innerHTML = user.name;
}
if (document.getElementById('user-picture'))
{
document.getElementById('user-picture').src = user.picture.data.url;
}
var callDataLogin = JSON.stringify({'serviceName':"global_functions", 'methodName':'login',"parameters":[response.id,response.last_name,response.first_name,response.email]});
$.post('Server URL', callDataLogin, function(resp){}).done(function(data)
{
console.log(data);
//alert(data);
//alert(" Send User Facebook info to server , Login");
});
}
else
{
document.body.className = 'not_connected';
console.log('Error getting user info: ' + JSON.stringify(response.error));
if (response.error.error_subcode && response.error.error_subcode == "458")
{
setTimeout(function()
{
alert("The app was removed. Please log in again.");
}, 0);
}
logout();
}
clearAction();
});
}
else {
document.body.className = 'not_connected';
clearAction();
}
}
And here is the code in my Index.html page that let me display my Facebook User Informations:
<div id="page-root" class="page">
<div class="show_when_connected">
<div id="welcome"><img id="user-picture" /><br /><span id="user-name"></span></div>
</div>
I also add this code to my Profile.html Page to display my facebook User Informations
<div id="page-root" class="page">
<div class="show_when_connected">
<div id="welcome"><img id="user-picture" /><br /><span id="user-name"></span></div>
</div>
But it s not displaying anything in my Profile.html as in my Index.html
Thanks for your help
////////////////////////////////////////UPDATE/////////////////////////////////////////////
in my js file here is the code that i put
<script>
//get the id
var getFbId=sessionStorage.getItem('Fbid');
//set the id html
document.getElementById('idget').innerHTML =getFbId;
var getFbName=sessionStorage.getItem('FBName');
//set the Name html
document.getElementById('Nameget').innerHTML =getFbName;
var getFbPicture=sessionStorage.getItem('FBPicture');
//set the Picture html
document.getElementById('Pictureget').innerHTML =getFbPicture;
</script>
and in my Profile.html here is the code that i used:
<div id="idget"></div>
<div id="Nameget"></div>
<img id="Pictureget">
You just set your fb credentials in localstorage/session storage after this you can retrieve in any page that you want.
function(response)
{
if (!response.error)
{
document.body.className = 'connected';
user = response;
console.log('Got the user\'s name and picture: ' + JSON.stringify(response));
console.log('FB name, ' + response.name);
console.log(('FB picture, ' + response.picture.data.url));
//set the id in session storage/localstorage
sessionStorage.setItem('Fbid',response.id);
//For localstorage
window.localStorage.setItem( 'Fbid', response.id);
}
}
For get this value in another html page by this way
//get the id from session
var getFbId=sessionStorage.getItem('Fbid');
//get the id from localstorage
var fromLocalStorage=window.localStorage.getItem( 'Fbid' );
//set the id html
document.getElementById('idget').innerHTML =getFbid;
I am having an issue with a Titanium App, the issue is only with Android, iOS is fine.
So I have a login form that queries the database, pretty straightforward. But for some reason it is not passing the params to the login script.
My JS function in app, have set the alert on the else statement to print out the $.email.value and password values which read fine. But with the current $response which is just a json it shows the values as being blank? The php form is also below. As I have said this is working fine on iOS
function login(e) {
//function to use HTTP to connect to a web server and transfer the data.
var sendit = Ti.Network.createHTTPClient({
onerror : function(e) {
Ti.API.debug(e.error);
alert('There was an error during the connection');
},
timeout : 100000,
});
//Here you have to change it for your local ip
sendit.open('GET', 'http://soyo.taylorhoganit.co.uk/post_auth.php');
var params = {
email : $.email.value,
password : $.password.value,
};
sendit.send(params);
//Function to be called upon a successful response
sendit.onload = function() {
var json = this.responseText;
var response = JSON.parse(json);
if (response.logged == true)
{
var landing = Alloy.createController("landing").getView();
$.index.close();
landing.open();
// Ti.App.Properties.setString('email', $.email.value);
// Ti.App.Properties.setString('password', $.password.value);
//alert("Username: " + response.username);
}
else
{
alert($response);
}
};
};
PHP Script
<?php
// Connect to the database(host, username, password)
$con = mysql_connect('replaced values');
if (!$con)
{
echo "Failed to make connection.";
exit;
}
$db = mysql_select_db('soyo');
if (!$db)
{
echo "Failed to select db.";
exit;
}
$email = $_POST['email'];
$password = $_POST['password'];
$sql = "SELECT * FROM users WHERE email = '" . $email . "' AND password = '" . $password . "'";
$query = mysql_query($sql);
// If we find a match, create an array of data, json_encode it and echo it out
if (mysql_num_rows($query) > 0)
{
$row = mysql_fetch_array($query);
$response = array(
'logged' => true,
'email' => $row['email']
);
echo json_encode($response);
}
else
{
// Else the username and/or password was invalid! Create an array, json_encode it and echo it out
$response = array(
'logged' => false,
'message' => $email + $password
);
echo json_encode($response);
}
?>
You did a mistake by using $response in the alert. It is a PHP variable not JS.
var response = JSON.parse(json);
// ...
alert($response); // Here should be just `response`
Edit: The another problem is that you are sending GET request while in PHP you accept POST ,so you can't get any params...
There is a mistake when you want to show alert.
You are using now is alert($response);
Remove $ from $response and use alert(response);, it will work properly.
I have an app i'm programming in Javascript/JQuery. I'm using PhoneGap and want to use localStorage to store the users credentials the first time they open the app and then autofill next time the user opens the app. I want to call the checkPreAuth() right when the page loads. But It's not calling my function. Can anybody help me?
Calling the function from login.html:
<script>
$(document).ready(function() {
checkPreAuth();
});
</script>
And the function in my digest_auth.js:
function checkPreAuth() {
var form = $("#loginForm");
var values = new Array();
var username = $('#username').val();
var password = $('#password').val();
if(window.localStorage["username"] == undefined && window.localStorage["password"] == undefined) {
localStorage.setItem("username", username);
localStorage.setItem("password", password);
alert('Saved username and password');
} else {
alert(username + ', ' + password);
}
}
Maybe this is the answer to your problem. I faced this problem and instead of using document ready of jquery, i used this:
JQuery document.ready vs Phonegap deviceready
I'm trying to find the best way to send my users a real-time status update of a process that's running on my server - this process is broken up into five parts. Right now I'm just 'pulling' the status using an Ajax call every few seconds to a PHP file that connects to MySQL and reads the status, but as you can imagine, this is extremely hard on my database and doesn't work so well with users that don't have a strong internet connection.
So I'm looking for a solution that will 'push' data to my client. I have APE push-engine running on my server now, but I'm guessing Socket.IO is better for this? What if they're on 3G and they miss a status update?
Thanks in advance :)
I guess my answer may match what you need.
1st: You Have to Get Node.js to run the socket.io
BELOW IS SAMPLE CODE FOR SERVER:
var app = require('http').createServer(handler)
, io = require('socket.io').listen(app)
, fs = require('fs')
app.listen(8800); //<---------Port Number
//If No Connection / Page Error
function handler (req, res) {
fs.readFile(__dirname + '/index.html',
function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading index.html');
}
res.writeHead(200);
res.end(data);
});
}
//If there is connection
io.sockets.on('connection', function (socket) {
//Set Varible
var UserID;
var Old_FieldContent = "";
socket.on('userid', function (data) {
if(data.id){
UserID = data.id;
StartGetting_FileName(UserID)
}
});
//Checking New Status
function StartGetting_FileName(UserID){
//Create Interval for continues checking from MYSQL database
var myInterval = setInterval(function() {
//clearInterval(myInterval);
//MySQL Connection
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
port : '3306',
user : 'root',
password : 'ABCD1234',
database : 'test',
});
//Setup SQL Query
var SQL_Query = "SELECT FileName FROM status WHERE UserID = '"+UserID+"'";
connection.connect();
connection.query(SQL_Query, function(err, rows, fields) {
//Do if old result is, different with new result.
if(Old_FieldContent !== rows[0].FileName){
if (err) throw err;
//Display at Server Console
console.log('------------------------------------------');
console.log('');
console.log('Fields: ', fields[0].name);
console.log('Result: ', rows[0].FileName);
console.log('');
console.log('------------------------------------------');
//Send Data To Client
socket.emit('news', { FieldName: fields[0].name });
socket.emit('news', { FieldContent: rows[0].FileName });
//Reset Old Data Variable
Old_FieldContent = rows[0].FileName;
}
});
connection.end();
}, 500 );
}
});
BELOW IS CLIENT HTML & JS:
<!doctype html>
<html>
<head>
<title>web sockets</title>
<meta charset="utf-8">
<!-- URL PATH TO LOAD socket.io script -->
<script src="http://15.17.100.165:8800/socket.io/socket.io.js"></script>
<script>
//Set Variable
var UserID = "U00001";
var socket = io.connect('http://15.17.100.165:8800');
var Field_Name = "No Data";
var Field_Content = "No Data";
// Add a disconnect listener
socket.on('connecting',function() {
msgArea.innerHTML ='Connecting to client...';
console.log('Connecting to client...');
//Once Connected Send UserID to server
//for checking data inside MYSQL
socket.emit('userid', { id: UserID });
});
// Get data that push from server
socket.on('news', function (data) {
console.log(data);
writeMessage(data);
});
// Add a disconnect listener
socket.on('disconnect',function() {
msgArea.innerHTML ='The client has disconnected!';
console.log('The client has disconnected!');
});
//Function to display message on webpage
function writeMessage(msg) {
var msgArea = document.getElementById("msgArea");
if (typeof msg == "object") {
// msgArea.innerHTML = msg.hello;
if(msg.FieldName !== undefined){
Field_Name = msg.FieldName;
}
if(msg.FieldContent !== undefined){
Field_Content = msg.FieldContent;
}
}else {
msgArea.innerHTML = msg;
}
msgArea.innerHTML = Field_Name +" = "+ Field_Content;
}
</script>
</head>
<body>
<div id="msgArea">
</div>
</body>
</html>
You should consider using push notifications, with the service provided for Android by Google as C2DM: https://developers.google.com/android/c2dm/
You will need to implement a PhoneGap plugin to handle the native notifications, and communicate them to your PhoneGap project that will then (and only then) query your server .
As K-ballo above points out, using a push notification plugin would be best.
Luckily, some good citizen on GitHub has done this already!
https://github.com/awysocki/C2DM-PhoneGap
Please note: the above C2DM plugin was built for PhoneGap v1.2, so if you are running a more up-to-date version you will have to tweak the native code a bit to get it working better.