JonnyH
June 20th, 2008, 05:11
I've never got the hang of this.. I'm a such Noob when it comes to paypal. I'm using Joe's paypal IPN which is great, but I don't know what to do it with it :knockedou
It shows the checkout, then uses ajax to confirm this and post these details to cP Creator for insertion and then calls paypal. The thing is, what details do I put in an array for a paypal? Why, when the function is called does just take a long time and do nothing?
Here's the checkout:
//Checkout
function checkout($time) {
//Split sessions up
foreach($_SESSION as $key => $content) {
${$key} = $content;
}
if(!isset($_SESSION['IRGENUINE']) /*|| isset($_SESSION['pdone'])*/) {
echo "Error: This isn't a genuine checkout call";
}
else {
mysql_query("INSERT INTO `{$this->sql['pre']}paiddetails`
(user ,fname, lname, address, address2, city, region, zip, country, num)
VALUES('{$user}','{$fname}','{$lname}','{$address}','{$addre ss2}','{$city}','{$region}','{$zip}','{$country}','{$num}')", $this->sql['con']);
$_SESSION['pdone'] = 1;
//Use the Paypal Script
$this->paypal($details);
}
}
Here's the Paypal function:
//Sends user to paypal - CREATED BY KRAKJOE @ http://freewebspace.net/forums/showthread.php?t=2199767
function paypal($details) {
define( "PAYPAL_WEBSCR", "www.paypal.com" ); # Server to use, should normally be www.paypal.com
define( "PAYPAL_ADDRESS", "paypal@kwix-host.com" ); # paypal address expected
define( "PAYPAL_CURRENCY", "USD"); # Currency of transaction
define( "PAYPAL_REQUIRED_STATUS", "completed" ); # All payments should be completed before we take automated action
define( "PAYPAL_ATTEND", $this->config("adminemail") ); # Address to send notifications generated by this code to
if( get_magic_quotes_gpc() ) $details = array_map( 'stripslashes', $_REQUEST );
if( count( $details ) )
{
if( ( $sock = fsockopen( PAYPAL_WEBSCR, 80, $errno, $errstr, 5 ) ) ) # Open a socket to paypal
{
$post[ ] = "cmd=_notify-validate"; # Append what we're doing here
foreach( $details as $k => $v ) $post[ ] = sprintf( "%s=%s", $k, urlencode( $v ) ); # Build postback
$post = implode( '&', $post ); # Finalize postback
$request[ ] = "POST /cgi-bin/webscr HTTP/1.0"; # POST request
$request[ ] = sprintf( "Content-length: %d", strlen( $post ) ); # Length of final postback
$request[ ] = "Content-type: application/x-www-form-urlencoded"; # Duh
$request[ ] = "" ; # HTTP Compliant post request
$request[ ] = $post ; # Final post string
fwrite( $sock, sprintf( "%s\r\n", implode("\r\n", $request ) ) ); # Write postback to paypal
while( !feof( $sock ) ) $response .= fgets( $sock ); # Get response from paypal server
fclose( $sock ); # Close socket
}
foreach( $details as $k => $v ) $email[ ] = sprintf( "%s:\t%s", $k, urldecode( $v ) ); # Build an email for later
$email[ ] = sprintf( "RAW RESPONSE:\n%s\n", $response ); # Append raw response to email
$email = implode("\n", $email ); # Finalize email
if( ereg( "VERIFIED", $response ) ) # Ensure the customer was verified
{
if( strtolower( $_REQUEST['payment_status'] ) == PAYPAL_REQUIRED_STATUS ) # Check for completed payment, echeck etc dont' complete instantly
{
if( $_REQUEST['receiver_email'] == PAYPAL_ADDRESS ) # Check for correct email address
{
if( $_REQUEST['mc_currency'] == PAYPAL_CURRENCY ) # Check for correct currency
{
// your site specific code here
}
else mail( PAYPAL_ATTEND, "Non standard currency used", $email );
}
else mail( PAYPAL_ATTEND, "Payment to wrong address", $email );
}
else mail( PAYPAL_ATTEND, "Non completed payment", $email );
}
else mail( PAYPAL_ATTEND, "Suspicious payment recieved", $email );
mail( PAYPAL_ATTEND, "TEST", $email );
}
}
I sooo need help with this. Im struggling.
It shows the checkout, then uses ajax to confirm this and post these details to cP Creator for insertion and then calls paypal. The thing is, what details do I put in an array for a paypal? Why, when the function is called does just take a long time and do nothing?
Here's the checkout:
//Checkout
function checkout($time) {
//Split sessions up
foreach($_SESSION as $key => $content) {
${$key} = $content;
}
if(!isset($_SESSION['IRGENUINE']) /*|| isset($_SESSION['pdone'])*/) {
echo "Error: This isn't a genuine checkout call";
}
else {
mysql_query("INSERT INTO `{$this->sql['pre']}paiddetails`
(user ,fname, lname, address, address2, city, region, zip, country, num)
VALUES('{$user}','{$fname}','{$lname}','{$address}','{$addre ss2}','{$city}','{$region}','{$zip}','{$country}','{$num}')", $this->sql['con']);
$_SESSION['pdone'] = 1;
//Use the Paypal Script
$this->paypal($details);
}
}
Here's the Paypal function:
//Sends user to paypal - CREATED BY KRAKJOE @ http://freewebspace.net/forums/showthread.php?t=2199767
function paypal($details) {
define( "PAYPAL_WEBSCR", "www.paypal.com" ); # Server to use, should normally be www.paypal.com
define( "PAYPAL_ADDRESS", "paypal@kwix-host.com" ); # paypal address expected
define( "PAYPAL_CURRENCY", "USD"); # Currency of transaction
define( "PAYPAL_REQUIRED_STATUS", "completed" ); # All payments should be completed before we take automated action
define( "PAYPAL_ATTEND", $this->config("adminemail") ); # Address to send notifications generated by this code to
if( get_magic_quotes_gpc() ) $details = array_map( 'stripslashes', $_REQUEST );
if( count( $details ) )
{
if( ( $sock = fsockopen( PAYPAL_WEBSCR, 80, $errno, $errstr, 5 ) ) ) # Open a socket to paypal
{
$post[ ] = "cmd=_notify-validate"; # Append what we're doing here
foreach( $details as $k => $v ) $post[ ] = sprintf( "%s=%s", $k, urlencode( $v ) ); # Build postback
$post = implode( '&', $post ); # Finalize postback
$request[ ] = "POST /cgi-bin/webscr HTTP/1.0"; # POST request
$request[ ] = sprintf( "Content-length: %d", strlen( $post ) ); # Length of final postback
$request[ ] = "Content-type: application/x-www-form-urlencoded"; # Duh
$request[ ] = "" ; # HTTP Compliant post request
$request[ ] = $post ; # Final post string
fwrite( $sock, sprintf( "%s\r\n", implode("\r\n", $request ) ) ); # Write postback to paypal
while( !feof( $sock ) ) $response .= fgets( $sock ); # Get response from paypal server
fclose( $sock ); # Close socket
}
foreach( $details as $k => $v ) $email[ ] = sprintf( "%s:\t%s", $k, urldecode( $v ) ); # Build an email for later
$email[ ] = sprintf( "RAW RESPONSE:\n%s\n", $response ); # Append raw response to email
$email = implode("\n", $email ); # Finalize email
if( ereg( "VERIFIED", $response ) ) # Ensure the customer was verified
{
if( strtolower( $_REQUEST['payment_status'] ) == PAYPAL_REQUIRED_STATUS ) # Check for completed payment, echeck etc dont' complete instantly
{
if( $_REQUEST['receiver_email'] == PAYPAL_ADDRESS ) # Check for correct email address
{
if( $_REQUEST['mc_currency'] == PAYPAL_CURRENCY ) # Check for correct currency
{
// your site specific code here
}
else mail( PAYPAL_ATTEND, "Non standard currency used", $email );
}
else mail( PAYPAL_ATTEND, "Payment to wrong address", $email );
}
else mail( PAYPAL_ATTEND, "Non completed payment", $email );
}
else mail( PAYPAL_ATTEND, "Suspicious payment recieved", $email );
mail( PAYPAL_ATTEND, "TEST", $email );
}
}
I sooo need help with this. Im struggling.