jamesxg1 Posted April 23, 2009 Share Posted April 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/155430-solved-paypal-subscription-help-s/ Share on other sites More sharing options...
Maq Posted April 23, 2009 Share Posted April 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/155430-solved-paypal-subscription-help-s/#findComment-817907 Share on other sites More sharing options...
jamesxg1 Posted April 23, 2009 Author Share Posted April 23, 2009 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¤cy_code=GBP&item_name=Membership%20Subscription&item_number=MSFF1&a3=20&p3=1&t3=Y&src=1&sr1=1&no_note=1&rm=2¬ify_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 Quote Link to comment https://forums.phpfreaks.com/topic/155430-solved-paypal-subscription-help-s/#findComment-817909 Share on other sites More sharing options...
jamesxg1 Posted April 23, 2009 Author Share Posted April 23, 2009 does anyone know what im doing wrong here ? ??? Quote Link to comment https://forums.phpfreaks.com/topic/155430-solved-paypal-subscription-help-s/#findComment-817934 Share on other sites More sharing options...
mrMarcus Posted April 24, 2009 Share Posted April 24, 2009 the paypal form is using the POST method .. but your 'action' is relying on GET. just a quick observation. Quote Link to comment https://forums.phpfreaks.com/topic/155430-solved-paypal-subscription-help-s/#findComment-817941 Share on other sites More sharing options...
jamesxg1 Posted April 24, 2009 Author Share Posted April 24, 2009 the paypal form is using the POST method .. but your 'action' is relying on GET. just a quick observation. oh :S, ermmm how do i change this ? Quote Link to comment https://forums.phpfreaks.com/topic/155430-solved-paypal-subscription-help-s/#findComment-817943 Share on other sites More sharing options...
jamesxg1 Posted April 24, 2009 Author Share Posted April 24, 2009 i always thought that if a script is getting or posting something it only uses $_POST or $_GET :S Quote Link to comment https://forums.phpfreaks.com/topic/155430-solved-paypal-subscription-help-s/#findComment-817946 Share on other sites More sharing options...
jamesxg1 Posted April 24, 2009 Author Share Posted April 24, 2009 does anyone have any idea please ??? Quote Link to comment https://forums.phpfreaks.com/topic/155430-solved-paypal-subscription-help-s/#findComment-818251 Share on other sites More sharing options...
jamesxg1 Posted April 24, 2009 Author Share Posted April 24, 2009 someone ?, anyone ? Quote Link to comment https://forums.phpfreaks.com/topic/155430-solved-paypal-subscription-help-s/#findComment-818275 Share on other sites More sharing options...
jamesxg1 Posted April 24, 2009 Author Share Posted April 24, 2009 ok, so im guessing noone has any ideas here :( ??? Quote Link to comment https://forums.phpfreaks.com/topic/155430-solved-paypal-subscription-help-s/#findComment-818308 Share on other sites More sharing options...
GingerRobot Posted April 24, 2009 Share Posted April 24, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/155430-solved-paypal-subscription-help-s/#findComment-818337 Share on other sites More sharing options...
premiso Posted April 24, 2009 Share Posted April 24, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/155430-solved-paypal-subscription-help-s/#findComment-818348 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.