Classipress is a very useful wordpress theme from AppThemes, what add functionality to the sites to post and manage ads. The theme had gateways for lot of payment methods, but there isn’t contains the PayGol payment gateway. The PayGol is a sms based micro-payment solution, with lot of configurable options.
To add the appropriate functions, we have to make several changes on the code.
First step
We have to register the new gateway in the classipress/include/gateways/admin-gateway-values.php
You have to add the following code part into the $options_gateways array definition. You have to copy the paygol.png image into the images folder of the theme.
array( ‘type’ => ‘tab’, ‘tabname’ => ‘PayGol’,),
array( ‘name’ => ‘PayGol Options’,‘type’ => ‘title’,
‘id’ => ”),
array( ‘name’ => ‘<img src=”‘.get_bloginfo(‘template_directory’).’/images/paygol.png” />’,‘type’ => ‘logo’,
‘id’ => ”),
array( ‘name’ => ‘Enable PayGol’,
‘desc’ => ”,
‘tip’ => ‘Set this to yes if you want to offer paygol mobil transfer as a payment option on your site. Note: the "Charge for Listing Ads" option on the pricing page must be set to yes for this option to work.’,
‘id’ => $app_abbr.’_enable_paygol’,
‘css’ => ‘width:100px;’,
‘std’ => ”,
‘js’ => ”,
‘type’ => ‘select’,
‘options’ => array( ‘yes’ => __(‘Yes’, ‘appthemes’),
‘no’ => __(‘No’, ‘appthemes’))),array( ‘name’ => ‘PayGol Instructions’,
‘desc’ => ‘Enter your specific PayGol payment instructions here. HTML can be used.’,
‘tip’ => ‘This will be shown on the payment page after a new ad has been submitted. IMPORTANT: THE INFORMATION IN THIS TEXT BOX WILL BE SHOWN ON YOUR WEB SITE CONFIRMATION PAGE.’,
‘id’ => $app_abbr.’_paygol_instructions’,
‘css’ => ‘width:500px;height:150px;’,
‘vis’ => ”,
‘req’ => ”,
‘min’ => ”,
‘type’ => ‘textarea’,
‘std’ => ”),
array( ‘type’ => ‘tabend’),
Second Step
Now, on the admin area of the classipress theme, you can enable the PayGol payment gateway, and you will be able to add instructions about the payment.
Third Step
When the users post a new ad, they can select the payment method from the list, what the system provides them. In the classipress/includes/forms folder there are the step2.php, what control the payments. We have to change this script. Around the line 144, there is the part, what creates the select control, what contains the payment methods. You have to add the new method to this list.
<select name=”cp_payment_method”>
<?php if(get_option(‘cp_enable_paypal’) == ‘yes’) { ?><option value=”paypal”><?php echo _e(‘PayPal’, ‘appthemes’) ?></option><?php } ?>
<?php if(get_option(‘cp_enable_paygol’) == ‘yes’) { ?><option value=”paygol”><?php echo ‘PayGol’ ?></option><?php } ?>
<?php if(get_option(‘cp_enable_bank’) == ‘yes’) { ?><option value=”banktransfer”><?php echo _e(‘Bank Transfer’, ‘appthemes’) ?></option><?php } ?>
<?php if(get_option(‘cp_enable_gcheckout’) == ‘yes’) { ?><option value=”gcheckout”><?php echo _e(‘Google Checkout’, ‘appthemes’) ?></option><?php } ?>
<?php if(get_option(‘cp_enable_2checkout’) == ‘yes’) { ?><option value=”2checkout”><?php echo _e(’2Checkout’, ‘appthemes’) ?></option><?php } ?>
<?php if(get_option(‘cp_enable_authorize’) == ‘yes’) { ?><option value=”authorize”><?php echo _e(‘Authorize.net’, ‘appthemes’) ?></option><?php } ?>
<?php if(get_option(‘cp_enable_chronopay’) == ‘yes’) { ?><option value=”chronopay”><?php echo _e(‘Chronopay’, ‘appthemes’) ?></option><?php } ?>
<?php if(get_option(‘cp_enable_mbookers’) == ‘yes’) { ?><option value=”mbookers”><?php echo _e(‘MoneyBookers’, ‘appthemes’) ?></option><?php } ?>
</select>
After this change, the PayGol will be selectable when customers want to post a new ad.
Fourth Step
To select the payment method, won’t be enough, we need to make some scripts, what redirect the customer onto the payment site, and send the appropriate data to there, then receive the response about the success or failure of the payment.
This part of the solution use the settings of easy-paygol plugin, so don’t forget to install that, and set up a service what you made on the PayGol site.
We have to create a folder named paygol under the classipress/includes/gateways folder, and add a new file, named paygol.php to there. The script what handle the payment are the following;
<?php
/**
* PaGol payment gateway script
*
* @package ClassiPress
* @author UTD
* @version 3.0
*
* @param int $post_id
* @param text $type
*
*/// payment processing script that is used on the new ad confirmation page
// and also the ad dashboard so ad owners can pay for unpaid ads
function cp_dashboard_paygol_button($post_id, $type){
global $wpdb;
// figure out the number of days this ad was listed for
if (get_post_meta($post_id, ‘cp_sys_ad_duration’, true))$prun_period = get_post_meta($post_id, ‘cp_sys_ad_duration’, true);
else
$prun_period = get_option(‘cp_prun_period’);
$table_name_setting=get_option(table_name_setting);
$table_name_service=get_option(table_name_service);
$sql = “SELECT * FROM $table_name_setting “;$settings = $wpdb->get_results($sql);
foreach ($settings as $service)
{// retrieve service information we need
$pg_serviceid = $service->pg_serviceid;
$pg_currency = $service->pg_currency;
$pg_price = $service->pg_price;
$pg_button = $service->pg_button;}
// I used the same URL in all cases, just add different url parameter in the different cases.
$pg_cancel_url= home_url().’/’.”payment/?cancel_post_id=$post_id”;
$pg_notify_url = home_url().’/’.”payment/?success_post_id=$post_id”;
$pg_return_url = home_url().’/’.”payment/?success_post_id=$post_id”;
?>
<script src=http://www.paygol.com/micropayment/js/pg.js type=text/javascript></script>
<link rel=stylesheet href=http://www.paygol.com/micropayment/css/pg_pre.css type=text/css media=screen /><script type=’text/javascript’>
function pgredirect()
{document.getElementById(‘pg_button’).click();
}
</script>
<form name=’pg_frm’ method=’post’><input type=’hidden’ name=’pg_serviceid’ value=’<?=$pg_serviceid;?>’>
<input type=’hidden’ name=’pg_currency’ value=’<?=$pg_currency;?>’>
<input type=’hidden’ name=’pg_price’ value=’<?=$pg_price;?>’>
<input type=’hidden’ name=’pg_name’ value=’<?=$pg_name;?>’>
<input type=’hidden’ name=’pg_notify_url’ value=’<?=$pg_notify_url;?>’>
<input type=’hidden’ name=’pg_return_url’ value=’<?=$pg_return_url;?>’>
<input type=’hidden’ name=’pg_cancel_url’ value=’<?=$pg_cancel_url;?>’>
<center>
<input type=’image’ name=’pg_button’ id=’pg_button’ class=’paygol’ src=’<?=$pg_button;?>’ border=’0′ alt=’PayGol’ title=’PayGol’ onClick=’pg_reDirect(this.form)’><br>
<input type=”submit” onClick=’pg_reDirect(this.form)’ value=”<?php _e(‘Continue’,'appthemes’);?> ››” /></center>
<script type=”text/javascript”> setTimeout(“pgredirect()”,500); </script></form>
<?php
}
?>
This script acquire the payment data based on the post_id, prepare the form for the payment, then redirects the user to the PayGol website, where the can finish the payment. When the payment finished, the user will be redirected to the success or cancel URL, what we earlier defined.
Fifth Step
The script, what receives the payment info must process the requested data. We can publish the new ad, make it featured, or just update the ad expiration date based on the payment info.
wp_publish_post($post_id);
stick_post($post_id);
update_post_meta($post_id, ‘cp_sys_expire_date’, $new_expire_date);
I hope this small description will help you to add PayGol or any other payment gateway solution to your classipress powered site.





















