friendspimp Posted June 26, 2009 Share Posted June 26, 2009 I am trying to integrate some code from my idevaffiliate software into my friendadder script site to track sales. I need the following inserted into my paypal button code to do the tracking: <input type="hidden" name="notify_url" value="http://www.friendspimp.com/idevaffiliate/paypal_ipn_buynow.php"> <input type="hidden" name="custom" value="<?PHP echo $_SERVER['REMOTE_ADDR']; ?>"> Also, I can leave the notify_url alone and just add the custom field to the paypal button, then use curl to post the ipn results to a second ipn script... that might be easier.... This is the script(3 pages control the process): First page ppbuynow.php (I think this may be the only page that needs adjustment to get the echo of the IP address inserted into the button correctly. Line 71 looks to be my nemesis... and maybe my syntax is off in the other hacks I made.) <?php class PayPalBuyNow { var $successUrl; var $notifyUrl; var $cancelUrl; var $autoReturn; var $price; var $currency; var $email; var $item; var $undefined_quantity; var $item_number; var $sandbox; var $no_note; var $no_shipping; var $charset; var $lc; #hack start var $custom; #hack end function PayPalBuyNow($item, $price, $success_url, $cancel_url, $email = false, $currency = false, $item_number = false, $undefined_quantity = false, $sandbox = null) { $app = getApp(); $this->item = $item; $this->item_number = $item_number; $this->undefined_quantity = $undefined_quantity; $this->price = $price; $this->successUrl = $success_url; $this->cancelUrl = $cancel_url; $this->email = ($email === false) ? $app->getIni('Payments', 'paypal_email') : $email; $this->currency = ($currency === false) ? $app->getIni('Payments', 'paypal_currency') : $currency; $this->sandbox = ($sandbox === null) ? $app->getIni('Payments', 'paypal_sandbox') : $sandbox; #hack start #$this->notifyUrl = null; $this->notifyUrl = 'http://www.friendspimp.com/idevaffiliate.com/paypal_ipn_buynow.php'; #hack end $this->no_note = false; $this->no_shipping = true; $this->charset = 'UTF-8'; $this->lc = 'US'; #hack start $this->custom = 'IP_ADDRESS'; #input type="hidden" name="custom" value="IP_ADDRESS" #hack end } function setLocation($location) { $this->lc = $location; } function setCharset($charset) { $this->lc = $charset; } function setNotifyUrl($url) { $this->notifyUrl = $url; } function setNoNote($value) { $this->no_note = $value; } function setNoShipping($value) { $this->$no_shipping = $value; } function getCode() { $return = urlencode($this->successUrl); $cancel = urlencode($this->cancelUrl); return "https://www.".($this->sandbox ? 'sandbox.' : '')."paypal.com/cgi-bin/webscr?cmd=_xclick&business=".urlencode($this->email)."&item_name=".urlencode($this->item).(($this->item_number === false) ? '': "&item_number=".urlencode($this->item_number))."&amount=".urlencode($this->price)."&undefined_quantity=".($this->undefined_quantity ? '1' : '0')."&bn=".urlencode("VASoftOnline BuyNow PHP generator")."&return=$return".(($this->notifyUrl !== null) ? "¬ify_url=".urlencode($this->notifyUrl) : '' )."&cancel_return=$cancel¤cy_code=".urlencode($this->currency)."&no_shipping=".($this->no_shipping ? '1' : '0')."&no_note=".($this->no_note ? '1' : '0')."&charset=".urlencode($this->charset); } } ?> Second page: buy-vip.php <?php $app = getApp(); if(isset($_REQUEST['cancel'])) echo "<center><span class='errormsg'>You have cancelled payment. Your VIP Membership is not updated.</span></center>"; else if(isset($_REQUEST['confirm'])) { echo "<center><span class='plaintext'><i>Thank you for using our services! Your VIP Membership status will be updated as soon as we receive payment notification from paypal.</i></span></center>"; } else if(isset($_REQUEST['submit'])) { $form_error = false; //Verify MySpace ID if(!verifyFormat($_REQUEST['id'], '/[0-9]{1,10}/im')) $form_error = 'You have entered invalid MySpace ID. MySpace ID is number with length up to 10 digits.'; //Get price if(!$form_error) { switch($_REQUEST['term']) { case 'day': $item = $app->getIni('Application', 'app_name')." VIP Membership for 1 day"; $price = $app->getIni('Payments', 'paypal_price_day'); break; case 'week': $item = $app->getIni('Application', 'app_name')." VIP Membership for 1 week"; $price = $app->getIni('Payments', 'paypal_price_week'); break; case 'month': $item = $app->getIni('Application', 'app_name')." VIP Membership for 1 month"; $price = $app->getIni('Payments', 'paypal_price_month'); break; case 'four months': $item = $app->getIni('Application', 'app_name')." VIP Membership for 4 months"; $price = $app->getIni('Payments', 'paypal_price_fourmonths'); break; default: $form_error = 'You have to select valid VIP Memebership term.'; } } //Show error if necessary if($form_error) echo "<center><span class='errormsg'>$form_error</span></center>"; else { $item .= " from MySpace ID {$_REQUEST['id']}"; //Regirect to payment page $paybut = new PayPalBuyNow($item, $price, $app->getAppUrl('buy vip', 'confirm&id='.urlencode($_REQUEST['id'])."&term=".$_REQUEST['term'], $app->getIni('Interface', 'show_port')), $app->getAppUrl('buy vip', 'cancel', $app->getIni('Interface', 'show_port')), false, false, false, true); $paybut->setNotifyUrl($app->getAppUrl('ipn', http_build_query(array('id' => $_REQUEST['id'], 'term' => $_REQUEST['term'])), $app->getIni('Interface', 'show_port'))); $app->serverSideRedirect($paybut->getCode()); } } //Crate payment type form $ppform = new form('100%', 'index.php'); $ppform->addHiddenField('action', 'Buy VIP'); $ppform->addHTML('<center><font class="form-header"></font></center><font class="form-label"><center>Enter Myspace ID to get VIP</center></font>'); $ppform->addField('id', 'ID Number:', 10); $ppform->addSelect('term', array(str_replace('%', $app->getIni('Payments', 'paypal_price_day')." ".$app->getIni('Payments', 'paypal_currency'), '1 day (%)') => 'day', str_replace('%', $app->getIni('Payments', 'paypal_price_week')." ".$app->getIni('Payments', 'paypal_currency'), '1 week (%)') => 'week', str_replace('%', $app->getIni('Payments', 'paypal_price_month')." ".$app->getIni('Payments', 'paypal_currency'), '1 month (%)') => 'month', str_replace('%', $app->getIni('Payments', 'paypal_price_fourmonths')." ".$app->getIni('Payments', 'paypal_currency'), '4 months (%)') => 'four months'), 'Term:'); $ppform->addSubmit('Pay'); //Get payment instruction $payment_instructions = str_replace('[__APPNAME__]', $app->getIni('Application', 'app_name'), file_get_contents('templates/payment-instruction.htm')); //Show text ?> <center><table width="87%" border="0" cellpadding="5" cellspacing="0"> <tr valign="top"> <td width="60%"> <?php echo $payment_instructions ?> </td> <td width="40%"> <?php echo $ppform->getCode(); echo file_get_contents('templates/adblock.htm'); ?> </td> </tr> </table></center> <?php ?> Third page: ipn.php <?php $app = getApp(); //Get price switch($_REQUEST['term']) { case 'day': $price = $app->getIni('Payments', 'paypal_price_day'); break; case 'week': $price = $app->getIni('Payments', 'paypal_price_week'); break; case 'month': $price = $app->getIni('Payments', 'paypal_price_month'); break; case 'four months': $price = $app->getIni('Payments', 'paypal_price_fourmonths'); break; default: $app->reportError('User '.$_REQUEST['id'].' has tried to fund his featured account for unknown term.'); } //Verify payment if(!VerifyPayPalPayment()) $app->reportError('User '.$_REQUEST['id'].' has tried to fund his featured account with invalid payment transaction (possible fraud).'); if(!VerifyPayPalTransactionId($_POST['txn_id'])) $app->reportError('User '.$_REQUEST['id'].' has tried to fund his featured account with previusly used transaction ID (possible fraud).'); $valid = ($_POST['payment_status'] == 'Completed'); if(!$valid) $app->reportError('User '.$_REQUEST['id'].' has tried to fund his featured account with not completed payment (possible fraud).'); $required_amount = $price * $_POST['quantity']; $valid = ($required_amount == $_POST['mc_gross']); if(!$valid) $app->reportError('User '.$_REQUEST['id'].' has tried to fund his featured account with not completed payment (possible fraud).'); $valid = ($_POST['mc_currency'] == $app->getIni('Payments', 'paypal_currency')); if(!$valid) $app->reportError('User '.$user->getLogin().' has tried to fund his featured account with invalid currency (possible fraud).'); $valid = (strcasecmp($app->getIni('Payments', 'paypal_email'), $_POST['receiver_email']) == 0); if(!$valid) $app->reportError('User '.$user->getLogin().' has tried to fund his featured account with fake payment notification (possible fraud).'); //Payment is successful - Initialize database $client = $app->getMySqlClient(); $client->connect(); $table_prefix = $app->getIni("MySql", "table_prefix"); $table_partisipant = $table_prefix."participant"; //Create user if necessary $id = $client->escape($_REQUEST['id']); $client->query("SELECT COUNT(*) FROM $table_partisipant WHERE id='$id'"); $result = $client->fetchRow(); if($result[0] == 0) $client->query("INSERT INTO $table_partisipant SET id='$id'"); //Set featured membership $client->query("UPDATE $table_partisipant SET featured_end=NOW() WHERE ((featured_end IS NULL) OR (featured_end<NOW())) AND (id='$id')"); //Select term $quantity = intval($_POST['quantity']); switch($_REQUEST['term']) { case 'day': $client->query("UPDATE $table_partisipant SET featured_end=DATE_ADD(featured_end,INTERVAL $quantity DAY) WHERE id='$id'"); break; case 'week': $client->query("UPDATE $table_partisipant SET featured_end=DATE_ADD(featured_end,INTERVAL $quantity*7 DAY) WHERE id='$id'"); break; case 'month': $client->query("UPDATE $table_partisipant SET featured_end=DATE_ADD(featured_end,INTERVAL $quantity MONTH) WHERE id='$id'"); break; case 'four months': $client->query("UPDATE $table_partisipant SET featured_end=DATE_ADD(featured_end,INTERVAL $quantity*4 MONTH) WHERE id='$id'"); break; default: $app->reportError('User '.$_REQUEST['id'].' has tried to fund his featured account for unknown term.'); } //Close database connection if($error = $client->close()) $app->reportError($error); ?> I have made some changes indicated in the comments... I just don't seem to be getting this coding correct. I am a newbie in php so any help would be greatly appreciated and I will use this as a tutorial for making changes like this in the future. Also, I have some custom functions that I would like to add to this script in the future and will be looking for a 'go to' php/html/javascript guy to get this work done at a reasonable price in the future... Quote Link to comment https://forums.phpfreaks.com/topic/163813-idevaffiliate-integration-with-paypal-button-script/ Share on other sites More sharing options...
friendspimp Posted June 27, 2009 Author Share Posted June 27, 2009 whoops I do see the error in the first file posted with the incorrect directory... /idevaffiliate.com/ should be /idevaffiliat/ I still can't seem to get this code to work, I also changed: $this->custom = 'IP_ADDRESS'; To: $this->custom = $_SERVER['REMOTE_ADDR']; As this seems to make more sense as I just need to echo the IP of the user making purchase. The problem I think lies in this section: return "https://www.".($this->sandbox ? 'sandbox.' : '')."paypal.com/cgi-bin/webscr?cmd=_xclick&business=".urlencode($this->email)."&item_name=".urlencode($this->item).(($this->item_number === false) ? '': "&item_number=".urlencode($this->item_number))."&amount=".urlencode($this->price)."&undefined_quantity=".($this->undefined_quantity ? '1' : '0')."&bn=".urlencode("VASoftOnline BuyNow PHP generator")."&return=$return".(($this->notifyUrl !== null) ? "¬ify_url=".urlencode($this->notifyUrl) : '' )."&cancel_return=$cancel¤cy_code=".urlencode($this->currency)."&no_shipping=".($this->no_shipping ? '1' : '0')."&no_note=".($this->no_note ? '1' : '0')."&charset=".urlencode($this->charset)."custom=".urlencode($this->custom); I added the 'custom=' to the string, but I don't think that it is entirely correct nor incorrect either... lol. Anyway, I would really love some help getting this to work! Quote Link to comment https://forums.phpfreaks.com/topic/163813-idevaffiliate-integration-with-paypal-button-script/#findComment-864499 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.