Jump to content

[SOLVED] paypal subscription help :S


jamesxg1

Recommended Posts

paypal.class.php

 

<?php

class Paypal {

private $VARS;
private $button;
private $logFile;
private $isTest=false;

function getLink()
{
	$url = $this->getPaypal();
	$link = 'https://'.$url.'/cgi-bin/webscr?';
	foreach($this->VARS as $item => $sub){
		$link .= $sub[0].'='.$sub[1].'&';
	}
	return $link;
}


function showForm()
{
	$url = $this->getPaypal();
	$FORM  = '<form action="https://'.$url.'/cgi-bin/webscr" method="post" target="_blank" style="display:inline;">'."\n";

	foreach($this->VARS as $item => $sub){
		$FORM .= '<input type="hidden" name="'.$sub[0].'" value="'.$sub[1].'">'."\n";
	}

	$FORM .= $this->button;    
	$FORM .= '</form>';
	echo $FORM;
}


function addVar($varName,$value)
{
	$this->VARS[${varName}][0] = $varName;
	$this->VARS[${varName}][1] = $value;
}


function addButton($type,$image = NULL)
{
	switch($type)
	{

		case 1:
			$this->button = '<input type="image" height="21" style="width:86;border:0px;"';
			$this->button .= 'src="https://www.sandbox.paypal.com/en_US/i/btn/btn_paynow_SM.gif" border="0" name="submit" ';
			$this->button .= 'alt="PayPal - The safer, easier way to pay online!">';
			break;

		case 2:
			$this->button = '<input type="image" height="26" style="width:120;border:0px;"';
			$this->button .= 'src="https://www.paypal.com/en_US/i/btn/btn_cart_LG.gif" border="0" name="submit"';
			$this->button .= 'alt="PayPal - The safer, easier way to pay online!">';
			break;

		case 3:
			$this->button = '<input type="image" height="47" style="width:122;border:0px;"';
			$this->button .= 'src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit"';
			$this->button .= 'alt="PayPal - The safer, easier way to pay online!">';
			break;

		case 4:	
			$this->button = '<input type="image" height="47" style="width:179;border:0px;"';
			$this->button .= 'src="https://www.paypal.com/en_US/i/btn/btn_giftCC_LG.gif" border="0" name="submit"';
			$this->button .= 'alt="PayPal - The safer, easier way to pay online!">';
			break;

		case 5:	
			$this->button = '<input type="image" height="47" style="width:122;border:0px;"';
			$this->button .= 'src="https://www.paypal.com/en_US/i/btn/btn_subscribeCC_LG.gif" border="0" name="submit"';
			$this->button .= 'alt="PayPal - The safer, easier way to pay online!">';
			break;

		default:
			$this->button = '<input type="image" src="'.$image.'" border="0" name="submit"';
			$this->button .= 'alt="PayPal - The safer, easier way to pay online!">';
	}
	$this->button .= "\n";
}


function setLogFile($logFile)
{
	$this->logFile = $logFile;
}


private function doLog($_POST)
{
	ob_start();
	echo '<pre>'; print_r($_POST); echo '</pre>';
	$logInfo = ob_get_contents();
	ob_end_clean();

	$file = fopen($this->logFile,'a');
	fwrite($file,$logInfo);
	fclose($file);
}


function checkPayment($_POST)
{

	$req = 'cmd=_notify-validate';


	foreach ($_POST as $key => $value) {
		$value = urlencode(stripslashes($value));
		$req .= "&$key=$value";
	}

	$url = $this->getPaypal();


	$header .= "POST /cgi-bin/webscr HTTP/1.1\r\n";
	$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
	$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
	$fp = fsockopen ($url, 80, $errno, $errstr, 30);


	if (!$fp) {

		return false;
	} else {
		fputs ($fp, $header . $req);
		while (!feof($fp)) {
			$res = fgets ($fp, 1024);
			if (strcmp ($res, "VERIFIED") == 0) {

				return true;
			} else {
//				if (strcmp ($res, "INVALID") == 0) {

				if($this->logFile != NULL){
					$this->doLog($_POST);
				}
				return false;
			}
		}
		fclose ($fp);
	}
	return false;
}


function useSandBox($value)
{
	$this->isTest=$value;
}


private function getPaypal()
{
	if($this->isTest == true){
		return 'www.sandbox.paypal.com';
	} else {
		return 'www.paypal.com';
	}
}
}
?>

 

subscribe.php

 

<?php

require_once('paypal.class.php');

$this_script = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
$doSubscribe = new Paypal;
$doSubscribe->useSandBox(true);
$doSubscribe->addVar('cmd','_xclick-subscriptions');
$doSubscribe->addVar('business','softwarespin@hotmail.co.uk');	
$doSubscribe->addVar('currency_code','GBP');
$doSubscribe->addVar('item_name','Membership Subscription');
$doSubscribe->addVar('item_number','MSFF1');
$doSubscribe->addVar('a3','20');
$doSubscribe->addVar('p3','1'); 	
$doSubscribe->addVar('t3','Y'); 	
$doSubscribe->addVar('src','1');
$doSubscribe->addVar('sr1','1');
$doSubscribe->addVar('no_note','1');
$doSubscribe->addVar('rm','2');			
$doSubscribe->addVar('notify_url',$this_script.'?action=success');
$doSubscribe->addVar('cancel_return',$this_script.'?action=cancel');
$doSubscribe->addVar('notify_url', $this_script.'?action=ipn');
$doSubscribe->addButton(5);	
$doSubscribe->addButton(6,'https://www.paypal.com/en_US/i/btn/btn_subscribeCC_LG.gif');
$doSubscribe->showForm();


echo '<br><a href="'.$doSubscribe->getLink().'">Click Here</a>';

switch($_GET['action']) {

        case 'success':
echo "<html><head><title>Success</title></head><body><h3>Thank you for your order.</h3>";
      echo "</body></html>";

      break;
      
   case 'cancel':
      echo "<html><head><title>Canceled</title></head><body><h3>The order was canceled.</h3>";
      echo "</body></html>";
break;
      
   case 'ipn':  
$subject = 'Instant Payment Notification - Recieved Payment';
         $to = 'softwarespin@hotmail.co.uk';
         $body =  "An instant payment notification was successfully recieved thankyou for joining.\n";

         mail($to, $subject, $body); 
break;

}
  
?>

 

The system works completely fine until i get to the site, then login and then this is displayed ..."The link you have used to enter the PayPal system is invalid. Please review the link and try again.".... but the screen before this (login page) has all the correct info on it so im really confused here :S.

Link to comment
Share on other sites

Well what does the link look like?  What is it supposed to be?

 

You can probably just view source it or echo $link in the getLink method.

 

https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_xclick-subscriptions&business=softwarespin@hotmail.co.uk&currency_code=GBP&item_name=Membership%20Subscription&item_number=MSFF1&a3=20&p3=1&t3=Y&src=1&sr1=1&no_note=1&rm=2&notify_url=http://cj.co.uk/paypal/subscribe.php?action=ipn&cancel_return=http://cj.co.uk/paypal/subscribe.php?action=cancel&

 

thats the link, and i litrully dont have a clue what it is supposed look like i just went with paypal's way :S

Link to comment
Share on other sites

ok, so im guessing noone has any ideas here :( :( ???

 

Or maybe, just maybe, you've annoyed everyone by being so impatient. The help and answers you might receive on these forums aren't something you're entitled to. People are giving up their own time in order to help, for free. I'm not going to sit here and claim they do it entirely out of their good nature - of course people gain something out of helping. However, you can't expect instantaneous replies to your questions. If it's that urgent, you should pay someone.

Link to comment
Share on other sites

It could also be that, the information provided to us does not help us diagnose your problem. Given that this is technically a 3rd party script (I take it you got it from paypal) maybe you need to goto the sandbox help forums and ask them there why it is not working.

 

I never used paypals sandbox or the script they provide, so it could be simply that the information you are passing is invalid as the error suggests.

 

A rule of thumb, if you do not get an answer to your question within a day, chances are you have worded it wrong, you are posting in the wrong section, or you need to do some more research on your own to figure it out. As we cannot test what you have (nor would I want to) and without being able to actively test that script I cannot help resolve it. Sure I could make guesses, but they are just that. A guess, which could lead you in the wrong direction.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.