Simple PayPal Pay Now hack
this is a very simple PayPal Buy Now hack for jobberBase (plain straightforward use of hosted Buy Now buttons) if you only need to be able to direct your job posters to a paypal payment facility with the details of the job being posted (job id, title, etc) and approve jobs based on the payment made.
what you need to do:
* for each job type, create a hosted Buy Now buttons on PayPal (and change button type to Pay Now)
* take note of the PayPal button id for each of the Buy Now/Pay Now buttons you created
* when you have finished following the tutorial below, go to Admin->PayPal->PayPal Setting for Job Types and enter the corresponding amount and PayPal button ID for each of the job type
* you will approve the jobs paid for in the Admin to activate the job ad

please consider donating
other screenshots here:
Posting Job



Admin



create the paypal settings table
CREATE TABLE IF NOT EXISTS `paypal_settings` ( `id` int(11) NOT NULL AUTO_INCREMENT, `button_type` varchar(100) CHARACTER SET utf8 NOT NULL, `button_image` varchar(255) CHARACTER SET utf8 NOT NULL, `currency_code` varchar(3) CHARACTER SET utf8 NOT NULL, `return_url` varchar(255) CHARACTER SET utf8 NOT NULL, `is_active` tinyint(4) NOT NULL, `first_post_only` tinyint(4) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; INSERT INTO `paypal_settings` (`id`, `button_type`, `button_image`, `currency_code`, `return_url`, `is_active`, `first_post_only`) VALUES (1, '_s-xclick', 'https://www.paypal.com/en_US/i/btn/btn_paynowCC_LG.gif', 'USD', 'http://localhost/jb18/paypal/', 1, 0);
alter the types table to add amount and paypal button id
ALTER TABLE `types` ADD `amount` INT( 11 ) NULL , ADD `paypal_button_id` VARCHAR( 255 ) NULL
1) /config.php
after the line
require_once '_includes/smarty/libs/Smarty.class.php';
add below
// paypal settings require_once '_includes/class.PayPal.php';
after the line
define('CAPTCHA_PRIVATE_KEY', $settings['captcha_private_key']);
add below
// PayPal Settings $pp = new SimplePayPal(); $pp_settings = $pp->showsettings(); define('PAYPAL_IS_ACTIVE',$pp_settings['is_active']); define('PAYPAL_FIRST_POST_ONLY',$pp_settings['first_post_only']); define('PAYPAL_BUTTON_TYPE',$pp_settings['button_type']); define('PAYPAL_BUTTON_IMAGE',$pp_settings['button_image']); define('PAYPAL_CURRENCY_CODE',$pp_settings['currency_code']); define('PAYPAL_RETURN_URL',$pp_settings['return_url']);
2) /index.php
after the lines
case 'confirm': if(!ENABLE_NEW_JOBS) { redirect_to(BASE_URL); exit; } $flag =1; $job = new Job($id); $job_title = BASE_URL . URL_JOB .'/' . $job->mId . '/' . $job->mUrlTitle . '/'; $smarty->assign('auth', $job->GetAuth()); $smarty->assign('job_url', $job_title); $smarty->assign('first_time_post', $extra); $template = 'publish-confirmation.tpl'; break;
add this block
case 'payment': if(!ENABLE_NEW_JOBS) { redirect_to(BASE_URL); exit; } $flag =1; $job = new Job($id); $job_title = BASE_URL . URL_JOB .'/' . $job->mId . '/' . $job->mUrlTitle . '/'; $smarty->assign('auth', $job->GetAuth()); $smarty->assign('job_url', $job_title); $smarty->assign('first_time_post', $extra); if (PAYPAL_IS_ACTIVE == 1) { $smarty->assign('first_time_post', $job->CheckPosterEmail()); $smarty->assign('paypal_item_number', $id); $smarty->assign('paypal_item_name', $job->mTitle); $smarty->assign('paypal_job_type', get_type_name_by_id($job->mTypeId)); $smarty->assign('paypal_amount', get_type_amount_by_id($job->mTypeId)); $smarty->assign('paypal_button_id', get_type_button_id_by_id($job->mTypeId)); } $template = 'publish-paypal.tpl'; break;
3) /page_publish.php
after
$job->Publish();
change this line
redirect_to(BASE_URL . 'confirm/' . $job->mId . '/'.$first_time_post.'/');
to this block
if (PAYPAL_IS_ACTIVE == 1 && PAYPAL_FIRST_POST_ONLY == 0) { redirect_to(BASE_URL . 'payment/' . $job->mId . '/'.$first_time_post.'/'); } else { redirect_to(BASE_URL . 'confirm/' . $job->mId . '/'.$first_time_post.'/'); }
4) /_includes/functions.php
replace this whole function
function get_types() { ... }
with this block
function get_types() { global $db; $sql = 'SELECT id, name, var_name, amount, paypal_button_id FROM '.DB_PREFIX.'types '; $result = $db->query($sql); $types = array(); while($row = $result->fetch_assoc()) { $types[] = array('id' => $row['id'], 'name' => $row['name'], 'var_name' => $row['var_name'], 'amount' => $row['amount'], 'paypal_button_id' => $row['paypal_button_id']); } return $types; }
before the last
?>
add these blocks
function get_type_name_by_id($id) { global $db; $sql = 'SELECT name FROM '.DB_PREFIX.'types WHERE id = '.$id; $result = $db->query($sql); $row = $result->fetch_assoc(); if ($row) return $row['name']; return false; } // get type amount function get_type_amount_by_id($id) { global $db; $sql = 'SELECT amount FROM '.DB_PREFIX.'types WHERE id = '.$id; $result = $db->query($sql); $row = $result->fetch_assoc(); if ($row) return $row['amount']; return false; } // get type button id function get_type_button_id_by_id($id) { global $db; $sql = 'SELECT paypal_button_id FROM '.DB_PREFIX.'types WHERE id = '.$id; $result = $db->query($sql); $row = $result->fetch_assoc(); if ($row) return $row['paypal_button_id']; return false; }
5) /_includes/class.Job.php
replace the whole function
public function Publish() { ... }
with this function
public function Publish() { global $db; if (PAYPAL_IS_ACTIVE == 0) { if ($this->CheckPosterEmail()) { $sql = 'UPDATE '.DB_PREFIX.'jobs SET is_temp = 0, is_active = 1 WHERE id = ' . $this->mId; } else { $sql = 'UPDATE '.DB_PREFIX.'jobs SET is_temp = 0, is_active = 0 WHERE id = ' . $this->mId; } } else { if ($this->CheckPosterEmail() && PAYPAL_FIRST_POST_ONLY == 1) { $sql = 'UPDATE '.DB_PREFIX.'jobs SET is_temp = 0, is_active = 1 WHERE id = ' . $this->mId; } else { $sql = 'UPDATE '.DB_PREFIX.'jobs SET is_temp = 0, is_active = 0 WHERE id = ' . $this->mId; } } $db->query($sql); }
6) open /_includes/ and create a file called ‘class.PayPal.php’ and copy code below
<?php /** * jobber job board platform * * @author RedJumpsuit <myredjumpsuit@gmail.com> * @web http://www.redjumpsuit.net * * Very simple PayPal integration for jobberBase - strictly no IPN :) */ class SimplePayPal { function __construct() { } // update paypal settings public function updatesettings($data) { global $db; $sql = 'UPDATE '.DB_PREFIX.'paypal_settings SET button_type = "'. trim($data['button_type']) .'", button_image = "'. trim($data['button_image']) .'", currency_code = "'. trim($data['currency_code']) .'", return_url = "'. trim($data['return_url']) .'", is_active = '. $data['is_active'] .', first_post_only = '. $data['first_post_only'] .' WHERE id = 1'; if ($db->query($sql)) { return true; } else { return false; } } // update paypal amount public function updatetypeamount($id,$amount=0) { global $db; if (empty($amount)) { $amount = 0; } $sql = 'UPDATE '.DB_PREFIX.'types SET amount = '. $amount .' WHERE id = '. $id ; if ($db->query($sql)) { return true; } else { return false; } } // update paypal amount public function updatetypebutton($id,$button='') { global $db; if (empty($button)) { $button = ''; } $sql = 'UPDATE '.DB_PREFIX.'types SET paypal_button_id = "'. trim($button) .'" WHERE id = '. $id ; if ($db->query($sql)) { return true; } else { return false; } } // show paypal settings public function showsettings() { global $db; $pp = array(); $sql = 'SELECT * FROM '.DB_PREFIX.'paypal_settings'; $result = $db->query($sql); $row = $result->fetch_assoc(); $pp['button_type'] = $row['button_type']; $pp['button_image'] = $row['button_image']; $pp['currency_code'] = $row['currency_code']; $pp['return_url'] = $row['return_url']; $pp['is_active'] = $row['is_active']; $pp['first_post_only'] = $row['first_post_only']; if (isset($pp)) { return $pp; } } } ?>
7) /_includes/translations.ini
add this at the bottom of the file
[paypal] button_type = "Button Type" button_image = "Button Image" currency_code = "Currency Code" return_url = "Return URL" is_active = "PayPal Active" first_post_only = "First Post" settings = "PayPal Settings" update = "Update PayPal Settings" update_types = "Update Types" info = "Payment is required before job is posted." amount = "Amount" payment_needed = "Your job post has been submitted. In order for your post to be activated, complete the payment for the ad using the payment button below. Once payment is received you will be notified by email and your ad will be posted on the website."
/_templates/publish-write.tpl
after this line
<label for="type_id_{$types[tmp2].id}"><img src="{$BASE_URL}_templates/{$THEME}/img/icon-{$types[tmp2].var_name}.png" alt="{$types[tmp2].name}" />
add this before the closing label tag
{if $smarty.const.PAYPAL_IS_ACTIVE == 1}{$smarty.const.PAYPAL_CURRENCY_CODE}{$types[tmp2].amount}{/if}
this displays the amount corresponding to the job type (full time, part time, freelance, etc)
9) open /_templates/ and create a file called ‘publish-paypal.tpl’ and copy code below
{include file="header.tpl"} <div id="content"> <div id="job-listings"></div><!-- #job-listings --> <div class="steps"> <div id="step-1"> {$translations.publish.step1} </div> <div id="step-2"> {$translations.publish.step2} </div> <div id="step-3" class="step-active"> {$translations.publish.step3} </div> <div class="clear"></div> </div> <br /> {if $first_time_post == 1 && $smarty.const.PAYPAL_FIRST_POST_ONLY == 1} <div class="posted-ok"> <strong>{$translations.publish.congratulations}</strong><br /><a href="{$job_url}">{$translations.publish.view}</a>. </div> <h4>{$translations.publish.options_title}</h4> <p> {$translations.publish.options_info}: </p> <ul> <li><a href="{$BASE_URL}post/{$CURRENT_ID}/{$auth}/" title="{$translations.publish.edit}">» {$translations.publish.edit}</a></li> <li><a href="{$BASE_URL}deactivate/{$CURRENT_ID}/{$auth}/" title="{$translations.publish.deactivate}">» {$translations.publish.deactivate}</a></li> </ul> </div> {else} <div class="posted-pending"> <p>{$translations.paypal.payment_needed}</p> <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="{$smarty.const.PAYPAL_BUTTON_TYPE}"> <input type="hidden" name="currency_code" value="{$smarty.const.PAYPAL_CURRENCY_CODE}"> <input type="hidden" name="item_number" value="{$paypal_item_number}"> <input type="hidden" name="item_name" value="#{$paypal_item_number} - ({$paypal_job_type}) {$paypal_item_name}"> <input type="hidden" name="hosted_button_id" value="{$paypal_button_id}"> <input type="hidden" name="notify_url" value="{$smarty.const.PAYPAL_RETURN_URL}"> <div class="suggestion"> <input type="image" src="{$smarty.const.PAYPAL_BUTTON_IMAGE}" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"> <strong>{$translations.paypal.amount}: {$smarty.const.PAYPAL_CURRENCY_CODE} {$paypal_amount}</strong> | {$translations.paypal.info} <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"> </div> </form> </div> {/if} <p> <a href="{$BASE_URL}">« {$translations.notfound.back}</a> </p> </div><!-- /content --> {include file="footer.tpl"}
10) /admin/index.php
under the lines
case URL_JOBS: if(!isset($_SESSION['AdminId'])) { redirect_to(BASE_URL); exit; } require_once 'page_category.php'; $flag = 1; break;
add this
case 'paypal': if(!isset($_SESSION['AdminId'])) { redirect_to(BASE_URL); exit; } require_once 'page_paypal.php'; $flag = 1; break;
11) open /admin/ and create a file called ‘page_paypal.php’ and copy code below
<?php $pp = new SimplePayPal(); if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['update_what']) && trim($_POST['update_what']) == 'settings') { if (empty($_POST['button_type'])) { $smarty->assign('error', 'Button Type is required.'); } elseif (empty($_POST['button_image'])) { $smarty->assign('error', 'Button Image is required.'); } elseif (empty($_POST['currency_code'])) { $smarty->assign('error', 'Currency Code is required.'); } elseif (empty($_POST['return_url'])) { $smarty->assign('error', 'Return URL is required.'); } else { $data = array('button_type' => $_POST['button_type'], 'button_image' => $_POST['button_image'], 'currency_code' => $_POST['currency_code'], 'return_url' => $_POST['return_url'], 'is_active' => $_POST['is_active'], 'first_post_only' => $_POST['first_post_only']); $pp->updatesettings($data); unset($_POST['button_type']); unset($_POST['button_image']); unset($_POST['currency_code']); unset($_POST['return_url']); unset($_POST['is_active']); unset($_POST['first_post_only']); $smarty->assign('success', 'PayPal Settings has been updated!'); } } if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['update_what']) && trim($_POST['update_what']) == 'types') { foreach ($_POST['amount'] as $k1 => $v1) { $pp->updatetypeamount($k1,$v1); } foreach ($_POST['paypal_button_id'] as $k2 => $v2) { $pp->updatetypebutton($k2,$v2); } $smarty->assign('type_success', 'PayPal Setting for Job Types has been updated!'); } $smarty->assign('current_category', 'paypal'); $smarty->assign('paypal', $pp->showsettings()); $smarty->assign('types', get_types()); $html_title = 'PayPal Settings / ' . SITE_NAME; $template = 'paypal.tpl'; ?>
12) /admin/_templates/header.tpl
after this line
<li {if $current_category == 'settings'}class="selected"{/if}><a href="{$BASE_URL_ADMIN}settings/">Settings</a></li>
add this line
<li {if $current_category == 'paypal'}class="selected"{/if}><a href="{$BASE_URL_ADMIN}paypal/">PayPal</a></li>
13) open /admin/_templates and create a file called ‘paypal.tpl’ and copy code below
{include file="header.tpl"} <div id="content"> <h3 class="page-heading">{$translations.paypal.settings}</h3> <form id="publish_form" name="settings" action="{$smarty.server.REQUEST_URI}" method="post"> <fieldset> <table cellspacing="2" cellpadding="2" border="0"> {if $success} <tr> <td colspan="2"> <img src="{$BASE_URL_ADMIN}img/icon_accept.gif" alt="" /> {$success} </td> </tr> {elseif $error} <tr> <td colspan="2"> <img src="{$BASE_URL_ADMIN}img/exclamation.png" alt="" /> {$error} </td> </tr> {/if} {if $success == ''} <tr> <td>{$translations.paypal.button_type}:</td> <td><input type="text" name="button_type" size="20" maxlength="100" value="{if $paypal.button_type != ''}{$paypal.button_type}{else}{$smarty.const.PAYPAL_BUTTON_TYPE}{/if}"/></td> </tr> <tr> <td>{$translations.paypal.button_image }:</td> <td><input type="text" name="button_image" size="60" maxlength="255" value="{if $paypal.button_image != ''}{$paypal.button_image}{else}{$smarty.const.PAYPAL_BUTTON_IMAGE}{/if}"/></td> </tr> <tr> <td>{$translations.paypal.currency_code}:</td> <td><input type="text" name="currency_code" size="20" maxlength="3" value="{if $paypal.currency_code != ''}{$paypal.currency_code}{else}{$smarty.const.PAYPAL_CURRENCY_CODE}{/if}"/></td> </tr> <tr> <td>{$translations.paypal.return_url}:</td> <td><input type="text" name="return_url" size="60" maxlength="255" value="{if $paypal.return_url != ''}{$paypal.return_url}{else}{$smarty.const.PAYPAL_RETURN_URL}{/if}"/></td> </tr> <tr> <td>{$translations.paypal.is_active}:</td> <td> <select name="is_active"> <option value="1"{if $smarty.const.PAYPAL_IS_ACTIVE == 1} selected="selected"{/if}>Yes</option> <option value="0"{if $smarty.const.PAYPAL_IS_ACTIVE == 0} selected="selected"{/if}>No</option> </select> <span class="suggestion">Specify if PayPal is active (Yes) or not (No)</span> </td> </tr> <tr> <td colspan="2">Option below applies only if PayPal is set to Active.</td> <td> </tr> <tr> <td>{$translations.paypal.first_post_only}:</td> <td> <select name="first_post_only"> <option value="1"{if $smarty.const.PAYPAL_FIRST_POST_ONLY == 1} selected="selected"{/if}>Yes</option> <option value="0"{if $smarty.const.PAYPAL_FIRST_POST_ONLY == 0} selected="selected"{/if}>No</option> </select> <span class="suggestion">Specify if PayPal is active on first post only (Yes) or required whenever posting a job (No)</span> </td> </tr> <tr> <td colspan="2"> <input type="hidden" name="update_what" value="settings"> <input type="submit" name="submit" id="submit" value="{$translations.paypal.update}" /> </td> </tr> {/if} </table> </fieldset> </form> <h2>PayPal Setting for Job Types</h2> {if $type_success} <p><img src="{$BASE_URL_ADMIN}img/icon_accept.gif" alt="" /> {$type_success}</p> {/if} <form id="publish_form" name="types" action="{$smarty.server.REQUEST_URI}" method="post"> <table id="job-posts" class="job-posts" cellspacing="0"> <tr class="alt"> <td>ID</td> <td>Type Name</td> <td>Amount</td> <td>PayPal ID</td> </tr> {foreach from=$types item=types} <tr> <td class="center">{$types.id}</td> <td>{$types.name}</td> <td class="center"><input type="text" name="amount[{$types.id}]" value="{$types.amount}" /></td> <td class="center"><input type="text" name="paypal_button_id[{$types.id}]" value="{$types.paypal_button_id}" /></td> </tr> {/foreach} </table> <input type="hidden" name="update_what" value="types"> <input type="submit" name="submit" id="submit" value="{$translations.paypal.update_types}" /> </form> <p> </p> <p> </p> </div><!-- #job-details -->






Got report already that there is a missing block of code. to fix the error:
Fatal error: Call to undefined function get_type_name_by_id()
Add this block on functions.php, before function get_type_amount_by_id($id)
i will also be updating the code (but just in case you tried to follow this tutorial before this update and got the error)
hi, thanks for the hack. one question before I was using this, how can I use it only for hottys?!
Hey,
I get a blank screen now. Any idea why?
Cheers.
hi, please turn your error reporting on and let me know what error you are getting.
Hi,
Thanks for all your great work with jobberbase, and especially this tutorial, it has been a godsend!
I have added this hack to my jobberbase installation and it all works fine (except for the occasional white screen), however, if I edit a job it goes through to paypal again.
I would like people to pay for each ad posted, but not for each edit – can I change this so they only go through to paypal when they originally post an ad?
Also, through this method and by changing a few lines of code here and there for the paypal button is it possible to make it have a drop down option so users can choose between a regular posting and a spotlight job (with different prices)?
Thanks
Is there an update for 1.9? or does this work?
this hack is for jobberBase 1.8, if you want to use it for 1.9 you will have to convert the code to work for the new version.
the bundled add-ons by the way has a few fixes for this hack on jobberBase 1.8, so you might want to check that out if you want a better working paypal hack for the 1.8 version
has anyone gotten this to work with the latest jobber codebase?
Yeah… instructions for jobberBase 1.9 would be greatly appreciated!
I tried this but am not even getting the index screen anymore. I had jobberbase working fine, implemented the files changes above and now get ‘Web page cannot be displayed’. Any ideas?
I haven’t done the paypal bits yet (i.e. getting button ids etc), would this be why? I dont think so because I cant even access admin anymore to add the button ids.
Thanks.
Self fix – I did not create the table. I think this should be renumbered as item 1 rather than it being just before item 1).
someone from the jobberBase forum posted instructions to implement this for 1.9.x, check it out!
http://www.jobberbase.com/forum/topic2689-paypal-hack-for-jobberbase-v19.html