I'm using angular/node.js stack for payumoney integration.
On the angular side, an order is placed using $http.post to a route endpoint at the server side (node.js) as follows:
$http.post('/placeOrder',order).success(function(data, status, headers, config){
//handle responses on client side
console.log("Successfully POSTED to payment gateway");
window.location = "https://test.payu.in/_payment";
}).error(function(data, status, headers, config) {
console.log("Error in posting");
});
The actual heavy lifting is done on the node.js (server side):
router.post('/placeOrder', function(req, res, next){
hash_data = MERCHANT_KEY+'|'+txnid+'|'+amount+'|'+productinfo+'|'+firstname+'|'+email+'|'+udf1+'|'+udf2+'|'+udf3+'|'+udf4+'|'+udf5+'||||||'+SALT;
var data = querystring.stringify({
'key': MERCHANT_KEY,
'txnid': txnid,
'amount': amount,
'productinfo': productinfo,
'firstname': firstname,
'email': email,
'phone': phone,
'surl': SUCCESS_URL,
'furl': FAILURE_URL,
'curl': FAILURE_URL,
'hash': hash,
'service_provider': SERVICE_PROVIDER
//'salt': SALT
});
//POST options
var POST_OPTIONS = {
hostname: PAYU_BASE_URL,
port: 443,
path: '/_payment',
method: 'POST',
//json: true,
agent: false,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
//'Content-Length': Buffer.byteLength(data)
'Content-Length': data.length
}
};
var resp_status = "";
var req = https.request(POST_OPTIONS, function(response) {
console.log('STATUS: ' + response.statusCode);
console.log('HEADERS: ' + JSON.stringify(response.headers));
response.setEncoding('utf8');
response.on('data', function (chunk) {
console.log("body: " + chunk);
resp_status = 200;
res.json(chunk);
});
response.on('error', function (err) {
console.log("Got error: " + err.message);
resp_status = 500;
return res.send(err);
});
});
req.end(data);
However, this doesn't seem to work as the POST doesnt seem to work using this approach. While debugging on the browser through the network tab, I always see:
Request URL:https://test.payu.in/_payment
Request Method:GET
Status Code:200 OK
Also, the test payment page (https://test.payu.in/_payment) shows:
"Error Reason
One or more mandatory parameters are missing in the transaction request."
Any help would be appreciated!!
How did I implement this..
Use Jquery and create a Form
Use sha512 to create hashcode. (bower install js-sha512)
var hashString = this.merchantKey+'|'+ options.uid +'|'+ options.totalPrice + '|'+'options.uid + '|' +
options.recipient_name + '|'+ options.email +'|||||||||||'+ this.merchantSalt ;
var hash = sha512(hashString);
var key1 = $('<input></input>').attr('type', 'hidden').attr('name', "key").val("merchantKey");
var key2 = $('<input></input>').attr('type', 'hidden').attr('name', "txnid").val(options.uid);
var key3 = $('<input></input>').attr('type', 'hidden').attr('name', "amount").val(options.totalPrice);
var key4 = $('<input></input>').attr('type', 'hidden').attr('name', "productinfo").val(options.uid);
var key5 = $('<input></input>').attr('type', 'hidden').attr('name', "firstname").val(options.recipient_name);
var key6 = $('<input></input>').attr('type', 'hidden').attr('name', "email").val(options.email);
var key7 = $('<input></input>').attr('type', 'hidden').attr('name', "phone").val(options.phone);
var key8 = $('<input></input>').attr('type', 'hidden').attr('name', "surl").val("http://192.168.43.121/payment/success");
var key9 = $('<input></input>').attr('type', 'hidden').attr('name', "furl").val("http://192.168.43.121/payment/error");
var key10 = $('<input></input>').attr('type', 'hidden').attr('name', "hash").val(hash);
var key11 = $('<input></input>').attr('type', 'hidden').attr('name', "service_provider").val("payu_paisa");
var form = $('<form/></form>');
form.attr("id", "payuform");
form.attr("action", this.payumoneyLink );
form.attr("method", "POST");
form.attr("style", "display:none;");
form.append(key1, key2, key3, key4, key5, key6, key7, key8, key9,key10, key11);
$("body").append(form);
// submit form
form.submit();
This is my first answer on StacksOverflow. Hope it helps!
As per the browser network tab which you have mentioned,
Request URL:https://test.payu.in/_payment Request Method:GET Status Code:200 OK
This means PayU is getting called with GET request instead of POST request somehow. PayU accepts data as a POST request only.
Also, the test payment page (https://test.payu.in/_payment) shows: "Error Reason One or more mandatory parameters are missing in the transaction request."
This is due to GET request. I have faced similar situation in my JSF based application wherein I was sending all parameters correctly but as a GET request. Later on when I switched to POST, the error got resolved automatically.
For information about sending POST request from angular, check below link.
https://www.devglan.com/angular/payumoney-integration-angular
NOTE: If input type is hidden, angularjs has some issue connecting model and view. So please take a note of that. txnid and hash I am getting from AJAX get call so I had to bind it in seperate variable from scope.
Angular code is staright forward, just populate the variables.
One more thing to remember as of today, if your account is not active then you need to use test salt/key provided by their customer support:
MID : 4934580
Key : rjQUPktU
Salt : e5iIg1jwi8
Authorization : y8tNAC1Ar0Sd8xAHGjZ817UGto5jt37zLJSX/NHK3ok=
Test Card : 5123456789012346
Expiry : 05/20
CVV : 123
Related
is there any way to make an HTTP request inside a Zeppelin paragraph? e.g.
function get_app_name(){
//var xmlHttp = new XMLHttpRequest();
//xmlHttp.open( "GET", "https://example.com/application/key", true, 'username', 'password');
//xmlHttp.send( null );
URL url = new URL("https://example.com/application/key");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
}
I cannot import any of the resources (e.g. URL) because the interpreter doesn't allow it (mongodb interpreter). Is there any way to make a simple GET request in Zeppelin? I'm trying to fetch data for my tables that is not in the specified db as the other elements.
From HTTP request inside MongoDB
%mongodb
function wget(url){
var tmp = "/tmp";
var id = new ObjectId();
var outFile= tmp+"/wget"+id;
var p = run("wget", "--user=user", "--password=password", "-o log", "--output-document="+outFile,url);
if (p==0){
var result = cat(outFile);
removeFile(outFile);
return result;
} else {
return "";
}
}
url = "https://exampleurl.com/resource"
result = wget(url)
print(result)
I can use ajax to check infomation in database with jquery but I dont know do same with angularjs . I use
$http({
type : "post",
dataType : "JSON",
url : "register.php",
data : data,
success : function(result)
{
....
}
php code
$errors = array(
'error' => 0
);
$username = $_POST['username']
$password = $_POST['password']
$email =$_POST['email']
$fullname = $_POST['fullname']
$sql = "SELECT * "
. "FROM USERS "
. "WHERE username='".$username."' "
. "OR email='".$email."'";
if (mysqli_num_rows($result) > 0)
{
$row = mysqli_fetch_assoc($result);
if ($row['username'] == $username){
$errors['username'] = 'Tên đăng nhập đã tồn tại';
}
if ($row['email'] == $email){
$errors['email'] = 'Email đã tồn tại';
}
}
if (count($errors) > 1){
$errors['error'] = 1;
die (json_encode($errors));
}else{
//insert database
}
$result = mysqli_query($conn, $sql);
but I dont know do next step . I want check in database if have user name show message error else show succes .Pls help me
Using success is deprecated but you're on the right path. Here's how you would do it now:
$http({
type : "post",
url : "register.php",
data : data
}).then(function(response){
// If data is returned, do stuff with it here
console.log('Yay, my data was POSTed', response.data);
}, function(response){
console.log('Aww, it failed.');
});
It would be easier to help you further, if you add a bit more information on what you're actually trying to achieve. For instance what is returned by this "register.php" endpoint, and what you intent to do after this.
check the DOC for $http.
The $http service is a function which takes a single argument — a configuration object — that is used to generate an HTTP request and returns a promise.
The response comes under promise (.then).
$http({
type : "POST",
url : "register.php",
data : data,
}).then(function successCallback(response) {
// this callback will be called asynchronously
// when the response is available/success
console.log(response.data)
}, function errorCallback(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
console.log(response.data)
});
> Am trying to provide login credentials with email and password using postgres database table.
postgres database tables. When i get records it should send 200 status
to my page.Am getting error on query. Kindly help me out how to use
select with where condition. Am missing some syntax.
getUser : function(req, res) {
var pg = require('pg');
var conString = process.env.DATABASE_URL || "postgres://test:test#localhost:5432/wallet";
var client = new pg.Client(conString);
client.connect();
console.log(req.query.email_id);
console.log(req.query.user_password);
var query = client.query("select * from pp_user_profile where email_id ="+req.query.email_id+ "and" + "user_password=" +req.query.password);
query.on("end", function (result) {
client.end();
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('Success');
res.end();
});
},
Try the below syntax:
"select * from pp_user_profile where email_id = '"+req.query.email_id+"' and user_password= '"+req.query.password+"'";
I am using Linkedin Oauth 2.0 . Here i have fetch the token in the code below next step is that i want to fetch info of a user whose email id i'll be passing. But its giving error unable to load resource error:500.
Below is the code:
chrome.identity.launchWebAuthFlow({
"url": " https://www.linkedin.com/uas/oauth2/authorization?&response_type=code&client_id=" + clientid +
"&redirect_uri=" + encodeURIComponent(redirectUri) +
"&state=121212121"
,'interactive': true,
},
function(redirect_url) {
var pairs = redirect_url.split('/');
var values = {};
var code1 = redirect_url.split('?');
var code2 = code1[1].split('&');
var code3 = code2[0].split('=');
var actualCode = code3[1];// actual code obtained in request
var deferred = $q.defer();
var req = {
method: 'POST',
url: 'https://www.linkedin.com/uas/oauth2/accessToken?&grant_type=authorization_code&code=' + actualCode +
'&redirect_uri='+ redirectUri + '&client_id=' + clientid + '&client_secret=' + clientSecretKey,
headers:{
'Access-Control-Expose-Headers': 'X-My-Custom-Header, X-Another-Custom-Header'
}
}
$http(req).then(function(data){
deferred.resolve(data);
console.log("deferred.resolve(data)"+ data.data.access_token ); // gives the token generated
var req2 = {
method: 'GET',
url: 'https://api.linkedin.com/v1/people/email=xxxx#gmail.com:(first-name,last-name)?format=json',
headers :{
'oauth_token': data.data.access_token,
'x-li-format': 'json'
}
}
$http(req2).then(function(data1){
deferred.resolve(data1);
console.log("sndsnd");
console.log("deferred.resolve(data)"+ data1.data );
});
});
}
);
You dont have to specify email and fields for the basic profile data. Use
url : https://api.linkedin.com/v1/people/~?format=json
and the correct accesstoken with "r_basicprofile" permission to get the basic details like firstName, lastName, id, headline and siteStandardProfileRequest.
For retreiving additional profile fields, use
url : https://api.linkedin.com/v1/people/~:(id,num-connections,picture-url)?format=json
For available profile fields using "r_basicprofile" permission, check https://developer.linkedin.com/docs/fields/basic-profile
For full profile details of the user, your app needs to get access from Linkedin to use "Apply with Linkedin"
https://developer.linkedin.com/docs/fields/full-profile
https://developer.linkedin.com/docs/apply-with-linkedin
Apply with Linkedin application Form :
https://help.linkedin.com/app/ask/path/api-dvr
I am trying to do HTTPRequest Post via Google App Engine.
This is what I have so far
URL url = new URL("http://myurl.com/myfile.php");
HTTPRequest request = new HTTPRequest(url, HTTPMethod.POST);
request.setPayload(########);
HTTPResponse response = URLFetchServiceFactory.getURLFetchService().fetch(request);
Here I need to put some paired values (ie. "email","hi#example.com" etc)
Since setPayload accept byte[] I have no idea how to convert my paired values
into byte.
I have searched other posts but I am very stuck.
EDIT:
I have changed to this but it is still not working
byte[] data = ("EMAIL=bo0#gmail.com&TITLE=evolution&COMMENT=comments&PRICE=5000;").getBytes();
try {
URL url = new URL("http://www.bo.x10.mx/nPost.php");
HTTPRequest request = new HTTPRequest(url, HTTPMethod.POST);
request.setPayload(data);
HTTPResponse response = URLFetchServiceFactory.getURLFetchService().fetch(request);
This is what I have on php website.
<?php
include "path/conf.php"; //logging into database works
$tb_name = 'Post';
$EMAIL=$_POST['EMAIL'];
$TITLE =$_POST['TITLE'];
$COMMENT =$_POST['COMMENT'];
$PRICE =$_POST['PRICE'];
if(!isset($EMAIL) || !isset($TITLE ) || !isset($PRICE )|| !isset($COMMENT)){
header('HTTP/1.0 412 Precondition Failed', true, 412);
die('Bad data');
}
$sql="INSERT INTO $tb_name(EMAIL, TITLE, COMMENT, PRICE) VALUES ('$EMAIL', '$TITLE ', '$COMMENT ', '$PRICE ')";
$result=mysql_query($sql);
if($result==TRUE){
echo "successfully inserted into table!";}
else{
echo "error in inserting into table!";
header('HTTP/1.0 500 Internal Server Error', true, 500);}
ob_end_flush();
exit();
?>
EDIT2: This is a working code
try{
byte[] data = ("EMAIL=bo0#gmail.com&TITLE=evolution&COMMENT=comments&PRICE=5000").getBytes("UTF-8");
URL url = new URL("http://www.box.com/nost.php");
HTTPRequest request = new HTTPRequest(url, HTTPMethod.POST);
request.setPayload(data);
HTTPResponse response = URLFetchServiceFactory.getURLFetchService().fetch(request);
}
My database string field is of type UTF-8
You create a String with the request body, and then you get the byte array. For example we have:
URL url = new URL("http://myurl.com/myfile.php");
HTTPRequest request = new HTTPRequest(url, HTTPMethod.POST);
String body = "email=" + email + "&mpla=" + mpla;
request.setPayload(body.getBytes("UTF-8"));
HTTPResponse response = URLFetchServiceFactory.getURLFetchService().fetch(request);
Hope this helps!