I am working with a php payment api https://simplepay4u.com/developer.php
I have followed every step successfully but can't seem to get return values to generate a receipt after payment. I am stock not understanding the what the unotify page should be doing.
Here is my form which is posting properly:
$action = $_POST["action"];
$pid = $_POST["pid"];
$buyer = $_POST["buyer"];
$total = $_POST["total"];
$comments = $_POST["comments"];
$referer = $_POST["referer"];
$customid = $_POST["customid"];
$transaction_id = $_POST["customid"];
$val = #json_encode($_POST);
// For Loging $val can be used
if ($referer == "https://simplepay4u.com"
|| $referer == "https://www.simplepay4u.com"
|| "http://sandbox.simplepay4u.com/process.php") //1st level checking
{
if (!empty($transaction_id)) //2nd level checking
{
/*** Server side verification. Your server is communicating with Simplepay Server Internally**/
//$simplepay_url="https://simplepay4u.com/processverify.php"; // Live URL
$simplepay_url = "http://sandbox.simplepay4u.com/processverify.php";
$curldata["cmd"] = "_notify-validate";
foreach ($_REQUEST as $key => $value) {
if ($key != 'view' && $key != 'layout') {
$value = urlencode($value);
$curldata[$key] = $value;
}
}
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $simplepay_url);
curl_setopt($handle, CURLOPT_POST, 1);
curl_setopt($handle, CURLOPT_POSTFIELDS, $curldata);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($handle, CURLOPT_TIMEOUT, 90);
$result = curl_exec($handle);
curl_close($handle);
var_dump(json_decode($result));
enter code here
if ('VERIFIED' == $result) {
// IMPLEMENTATION CODE & aPPLICATION lOGIC WILL GO HER TO UPDATE THE ACCOUNT
}
}
}
I have set my ureturn page to carry the above script and tried var_dump(json_decode($result)), print_r($result) and echo $result; Just to see something but I get the result.
Can someone please tell me what to do to get my return values after posting my already working form?
Related
I don't have much experience here, so pls bear with me. I am good with cURL and sending data to API's - right now I want to set up a testing environment as the API isn't ready, but I know what he responses will be.
I will be sending some data to the API via cURL - no issue there. The main variable is called $src and it is a simple POST value. I want to set up a script on another server and echo back some messaging based on $src value.
On the remote script, that will mimic the API I'm getting returned messages like "Resource id #4" or "Resource id #5" I realize that is a generic message. Here is what I am trying to do
cURL scripting
foreach($fields as $key=>$value) {
$fields_string .= $key.'='.$value.'&';
}
$fields_string = rtrim($fields_string,'& ');
$urlFX = 'http://myserver.com/NTLM/testresponse.php';
$ch = curl_init($urlFX);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
echo($ch);
Test script to mimic API Response:
<?php
$src = $_GET['src'];
if($src == "nt-fx-data-test") {
echo('foo');
} else {
echo('bar');
}
?>
How can I set up a script that will mimic the API's responses based on the $src var value?
Try to hit
http://goelette.net/NTLM/testresponse.php
With params:
src=nt-fx-data-test
src=xp
dst=nt-fx-data-test
Code:
<?php
foreach($_REQUEST as $param => $value) {
if ($param == 'src' and $value == 'nt-fx-data-test') {
echo 'foo';
} else if ($param == 'src' and $value != 'nt-fx-data-test') {
echo 'bar';
} else {
echo "unknown $param";
}
}
I am using paypal payment gateway (currently using sandbox), its working but some time on success auto return showing blank screen?? response url is pretty good, but some times after auto return its showing blank screen.
My code:
after success auto return redirect properly:
http://domainname/client/paypal/success?amt=9.24&cc=USD&item_name=Weight%20Loss%20Diet%20Program&st=Completed&tx=9CX31984H5808205U
after success auto return redirect properly but showing website blank screen:
http://domainname/client/paypal/success?amt=9.24&cc=USD&item_name=Weight%20Loss%20Diet%20Program&st=Completed&tx=9CX31984H5808205U
everything is looking good with code & return url, then why after return sometimes website showing blank screen??
My Code Snippet to execute paypal response:
switch($action){
case "success":
if(isset($_GET['tx']))
{
$tx_token = $_GET['tx'];
$req = 'cmd=_notify-synch';
$auth_token = PDT_IDENTITY_TOKEN;
$req .= "&tx=$tx_token&at=$auth_token";
$ch = curl_init();
if($sandbox==0){
curl_setopt($ch, CURLOPT_URL, "https://www.paypal.com/cgi-bin/webscr"); //Live
}else{
curl_setopt($ch, CURLOPT_URL, "https://www.sandbox.paypal.com/cgi-bin/webscr"); //Sandbox
}
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
//set cacert.pem verisign certificate path in curl using 'CURLOPT_CAINFO' field here,
//if your server does not bundled with default verisign certificates.
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
if($sandbox==0){
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Host: www.paypal.com")); //Live
}else{
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Host: www.sandbox.paypal.com")); //Sandbox
}
$res = curl_exec($ch);
curl_close($ch);
$lines = explode("\n", trim($res));
$keyarray = array();
if (strcmp ($lines[0], "SUCCESS") == 0)
{
for ($i = 1; $i < count($lines); $i++)
{
$temp = explode("=", $lines[$i],2);
$keyarray[urldecode($temp[0])] = urldecode($temp[1]);
}
$invoice_id = $keyarray['invoice'];
$transaction_id = $keyarray['txn_id'];
$payment_status = $keyarray['payment_status'];
if($payment_status=='Completed')
{
........
}
}
}
....
break;
....
}
During PayPal operations, the variables you are using are part of PDT (Paypal data transfer), which is PayPal a/c feature which needs to be enabled. Please check your PayPal a/c PDT settings once.
I am trying to make a redirect php script, I want that script to check if the link exist and then redirect the user to the link, if it doesn't exist then it will get the next link and so on, but for some reason is not working, maybe you could give me some help on this.
<?php
$URL = 'http://www.site1.com';
$URL = 'http://www.site2.com';
$URL = 'http://www.site3.com';
$handlerr = curl_init($URL);
curl_setopt($handlerr, CURLOPT_RETURNTRANSFER, TRUE);
$resp = curl_exec($handlerr);
$ht = curl_getinfo($handlerr, CURLINFO_HTTP_CODE);
if ($ht == '404')
{ echo "Sorry the website is down atm, please come back later!";}
else { header('Location: '. $URL);}
?>
You are overwriting your $URL variable..
$URL = 'http://www.site1.com';
$URL = 'http://www.site2.com';
$URL = 'http://www.site3.com';
Put these urls in an array and go through it with a for each loop.
You have a few issues in your code. For 1, your $URL will overwrite itself, resulting in only 1 url in there. It needs to be an array:
array( 'http://www.site1.com', 'http://www.site2.com', 'http://www.site3.com' );
You can get many responses, not just a 404, so you should tell cURL to follow redirects. If the URL was a redirect itself, could get a 301 that redirects to a 200. So we want to follow that.
Try This:
<?php
function curlGet($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$output = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ( $httpcode == 200 ) {
return true;
}
return false;
}
$urlArray = array( 'http://www.site1.com', 'http://www.site2.com', 'http://www.site3.com' );
foreach ( $urlArray as $url ) {
if ( $result = curlGet($url) ) {
header('Location: ' . $url);
exit;
}
}
// if we made it here, we looped through every url
// and none of them worked
echo "No valid URLs found...";
http://php.net/manual/en/function.file-exists.php#74469
<?php
function url_exists($url) {
if (!$fp = curl_init($url)) return false;
return true;
}
?>
This will give you the url exists check.
to check multiple urls though, you need an array:
<?
$url_array = [];
$url_array[] = 'http://www.site1.com';
$url_array[] = 'http://www.site2.com';
$url_array[] = 'http://www.site3.com';
foreach ($url_array as $url) {
if url_exists($url){
// do what you need;
break;
}
}
?>
PS - this is completely untested, but should theoretically do what you need.
I have an IPN file that works perfectly in sandbox. It returns valid or not and executes the code correctly. However if I try real live payments it tells me the url is malformed
This is the error with live payments:
bool(false) string(15) " malformed"
this is the curl code I have:
if($testmode === true)
{
$paypalaction = "https://www.sandbox.paypal.com/cgi-bin/webscr";
}
elseif($paypal == "paypal")
{
$paypalaction = "https://www.paypal.com/cgi-bin/webscr";
}
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value)
{
// If magic quotes is enabled strip slashes
if (get_magic_quotes_gpc())
{
$_POST[$key] = stripslashes($value);
$value = stripslashes($value);
}
$value = urlencode($value);
// Add the value to the request parameter
$req .= "&$key=$value";
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$paypalaction);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
$res = curl_exec($ch);
var_dump($res);
var_dump(curl_error($ch));
curl_close($ch);
It sounds like you may be posting sandbox transactions to the live URL or the other way around. Make sure that when you try a live transaction, you are doing so with a real, live PayPal account. Double-check your code to ensure that your test for which PayPal URL is working correctly.
The problem wasn't with paypal or sandbox but just me being stupid. i had the following if statement:
if($testmode === true)
{
$paypalaction = "https://www.sandbox.paypal.com/cgi-bin/webscr";
}
elseif($paypal == "paypal")
{
$paypalaction = "https://www.paypal.com/cgi-bin/webscr";
}
But the $paypal variable wasn't used anymore so it never entered the elseif statement. I should have been only an if else:
if($testmode === true)
{
$paypalaction = "https://www.sandbox.paypal.com/cgi-bin/webscr";
}
else
{
$paypalaction = "https://www.paypal.com/cgi-bin/webscr";
}
How can I authenticate my users via our their Google Apps account.
I also need access to their email.
I've read Oauth is needed but I have no idea if that is correct.
I'm using PHP.
I use this code in a library I wrote to pull contact information from gmail. http://www.oriontechnologysolutions.com/programming/libgoog_php.
This particular function will validate an account and pass back an Auth Token used to access Google Services.
function login() {
$response = Array();
if(isset($this->domain))
$email = $this->username . '#' . $this->domain;
else
$email = $this->username;
$requestString = "service=".$this->service."&Email=".urlencode($email)."&Passwd=".urlencode($this->passwd)."&source=".self::source;
$c = curl_init();
curl_setopt($c, CURLOPT_URL, self::loginUrl);
curl_setopt($c, CURLOPT_POST, 1);
curl_setopt($c, CURLOPT_POSTFIELDS, $requestString);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($c);
$httpCode = curl_getinfo($c, CURLINFO_HTTP_CODE);
foreach(explode("\n", $res) as $line) {
if(strpos($line, "=") != false) {
gooDebug("Exploding $line\n", 4);
list($name, $value) = explode("=", $line);
$response[$name] = $value;
}
}
if($httpCode !=200)
return($response);
$this->authTok = $response['Auth'];
return($this->authTok);
}