by
tim » Wed Nov 25, 2015 7:37 pm
Alright, Simon. Instead of sending you a ready-made modification, let's walk through the process and you can modify the file yourself. It'll be fun and easy and might be interesting to others curious about working with customizing Couch.
Fire up your trusty text editor and open couch/tags.php. Search for "paypal_button". You'll find exactly one instance on line 4627.
- Code: Select all
//////Will try and move the following to 'plugins', once the architecture is in place
function paypal_button( $params, $node ){
global $CTX, $FUNCS, $PAGE;
if( count($node->children) ) {die("ERROR: Tag \"".$node->name."\" is a self closing tag");}
extract( $FUNCS->get_named_vars(
array(
'image'=>'',
'processor'=>'',
'show_shipping'=>'0',
'return_url'=>'',
'cancel_url'=>'',
'custom'=>''
),
$params)
);
$image = trim( $image );
$processor = trim( $processor );
$show_shipping = ( $show_shipping==1 ) ? 1 : 0;
$return_url = trim( $return_url );
$cancel_url = trim( $cancel_url );
$item_name = $CTX->get('k_page_title');
$item_number = $CTX->get('k_page_id');
$amount = $CTX->get('pp_price');
$downloads = $CTX->get('pp_download'); //defunct?..will prevent paypal from asking the shipping address
$return_url = ( $return_url ) ? $return_url : K_SITE_URL . $PAGE->link;
$cancel_url = ( $cancel_url ) ? $cancel_url : $return_url;
$processor = ( $processor ) ? $processor : $return_url;
$sep = ( strpos($processor, '?')===false ) ? '?' : '&';
$notify_url = $processor . $sep . 'paypal_ipn=1';
// Paypal does not support zero cost transactions. Don't display buttom if amount not given.
if( $amount ){
if( K_PAYPAL_USE_SANDBOX ){
$paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
}
else{
$paypal_url = 'https://www.paypal.com/cgi-bin/webscr';
}
if( !$image ) $image=0;
if( $FUNCS->is_natural($image) ){
$arr_btns = array( 'x-click-but23.gif','x-click-but9.gif', 'x-click-but01.gif',
'x-click-but3.gif', 'x-click-butcc.gif', 'x-click-but5.gif',
'btn_buynow_SM.gif', 'btn_buynow_LG.gif', 'btn_buynowCC_LG.gif' );
$image_src = 'https://www.paypal.com/en_US/i/btn/'.$arr_btns[$image];
}
else{
$image_src = $image;
}
$html .= '<form action="'.$paypal_url.'" method="post">';
$html .= '<input type="hidden" name="cmd" value="_xclick"/>';
$html .= '<input type="hidden" name="business" value="'.K_PAYPAL_EMAIL.'"/>';
$html .= '<input type="hidden" name="item_name" value="'.$item_name.'"/>';
$html .= '<input type="hidden" name="item_number" value="'.$item_number.'"/>';
$html .= '<input type="hidden" name="amount" value="'.$amount.'"/>';
$html .= '<input type="hidden" name="undefined_quantity" value="1"/>';
//if( strlen(trim($downloads)) ){
if( !$show_shipping ){
//don't prompt customer for shipping address if product is downloadable
$html .= '<input type="hidden" name="no_shipping" value="1"/>';
}
$html .= '<input type="hidden" name="no_note" value="1"/>';
$html .= '<input type="hidden" name="currency_code" value="'.K_PAYPAL_CURRENCY.'"/>';
$html .= '<input type="hidden" name="rm" value="2"/>';
$html .= '<input type="hidden" name="custom" value="'.$custom.'">';
$html .= '<input type="hidden" name="return" value="'.$return_url.'"/>';
$html .= '<input type="hidden" name="cancel_return" value="'.$cancel_url.'"/>';
$html .= '<input type="hidden" value="'.$notify_url.'" name="notify_url"/>';
$html .= '<input type="image" border="0" alt="Make payments with PayPal - it\'s fast, free and secure!"';
$html .= ' name="submit" src="'.$image_src.'"/>';
$html .= '<img width="1" height="1" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" alt=""/>';
$html .= '</form>';
}
return $html;
}
We'll start by adding the 'seller' parameter to the array of parameters. Change this:
- Code: Select all
extract( $FUNCS->get_named_vars(
array(
'image'=>'',
'processor'=>'',
'show_shipping'=>'0',
'return_url'=>'',
'cancel_url'=>'',
'custom'=>''
),
$params)
);
to this:
- Code: Select all
extract( $FUNCS->get_named_vars(
array(
'image'=>'',
'processor'=>'',
'show_shipping'=>'0',
'return_url'=>'',
'cancel_url'=>'',
'seller'=>'',
'custom'=>''
),
$params)
);
Next scroll down to where you find the place where the business email is being set:
- Code: Select all
$html .= '<input type="hidden" name="business" value="'.K_PAYPAL_EMAIL.'"/>';
Change it to:
- Code: Select all
if( $seller !='' ){
$html .= '<input type="hidden" name="business" value="'.$seller.'"/>';
}
else{
$html .= '<input type="hidden" name="business" value="'.K_PAYPAL_EMAIL.'"/>';
}
and it's done! The whole thing looks like this:
- Code: Select all
//////Will try and move the following to 'plugins', once the architecture is in place
function paypal_button( $params, $node ){
global $CTX, $FUNCS, $PAGE;
if( count($node->children) ) {die("ERROR: Tag \"".$node->name."\" is a self closing tag");}
extract( $FUNCS->get_named_vars(
array(
'image'=>'',
'processor'=>'',
'show_shipping'=>'0',
'return_url'=>'',
'cancel_url'=>'',
'seller'=>'',
'custom'=>''
),
$params)
);
$image = trim( $image );
$processor = trim( $processor );
$show_shipping = ( $show_shipping==1 ) ? 1 : 0;
$return_url = trim( $return_url );
$cancel_url = trim( $cancel_url );
$item_name = $CTX->get('k_page_title');
$item_number = $CTX->get('k_page_id');
$amount = $CTX->get('pp_price');
$downloads = $CTX->get('pp_download'); //defunct?..will prevent paypal from asking the shipping address
$return_url = ( $return_url ) ? $return_url : K_SITE_URL . $PAGE->link;
$cancel_url = ( $cancel_url ) ? $cancel_url : $return_url;
$processor = ( $processor ) ? $processor : $return_url;
$sep = ( strpos($processor, '?')===false ) ? '?' : '&';
$notify_url = $processor . $sep . 'paypal_ipn=1';
// Paypal does not support zero cost transactions. Don't display buttom if amount not given.
if( $amount ){
if( K_PAYPAL_USE_SANDBOX ){
$paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
}
else{
$paypal_url = 'https://www.paypal.com/cgi-bin/webscr';
}
if( !$image ) $image=0;
if( $FUNCS->is_natural($image) ){
$arr_btns = array( 'x-click-but23.gif','x-click-but9.gif', 'x-click-but01.gif',
'x-click-but3.gif', 'x-click-butcc.gif', 'x-click-but5.gif',
'btn_buynow_SM.gif', 'btn_buynow_LG.gif', 'btn_buynowCC_LG.gif' );
$image_src = 'https://www.paypal.com/en_US/i/btn/'.$arr_btns[$image];
}
else{
$image_src = $image;
}
$html .= '<form action="'.$paypal_url.'" method="post">';
$html .= '<input type="hidden" name="cmd" value="_xclick"/>';
if( $seller !='' ){
$html .= '<input type="hidden" name="business" value="'.$seller.'"/>';
}
else{
$html .= '<input type="hidden" name="business" value="'.K_PAYPAL_EMAIL.'"/>';
}
$html .= '<input type="hidden" name="item_name" value="'.$item_name.'"/>';
$html .= '<input type="hidden" name="item_number" value="'.$item_number.'"/>';
$html .= '<input type="hidden" name="amount" value="'.$amount.'"/>';
$html .= '<input type="hidden" name="undefined_quantity" value="1"/>';
//if( strlen(trim($downloads)) ){
if( !$show_shipping ){
//don't prompt customer for shipping address if product is downloadable
$html .= '<input type="hidden" name="no_shipping" value="1"/>';
}
$html .= '<input type="hidden" name="no_note" value="1"/>';
$html .= '<input type="hidden" name="currency_code" value="'.K_PAYPAL_CURRENCY.'"/>';
$html .= '<input type="hidden" name="rm" value="2"/>';
$html .= '<input type="hidden" name="custom" value="'.$custom.'">';
$html .= '<input type="hidden" name="return" value="'.$return_url.'"/>';
$html .= '<input type="hidden" name="cancel_return" value="'.$cancel_url.'"/>';
$html .= '<input type="hidden" value="'.$notify_url.'" name="notify_url"/>';
$html .= '<input type="image" border="0" alt="Make payments with PayPal - it\'s fast, free and secure!"';
$html .= ' name="submit" src="'.$image_src.'"/>';
$html .= '<img width="1" height="1" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" alt=""/>';
$html .= '</form>';
}
return $html;
}
Let us know how it goes.
UPDATE:A potential problem was discovered with changing the seller email in this way. The process_paypal tag will fail to validate properly because it expects the IPN to return the email from the config file. See
viewtopic.php?p=22001#p22001 for a discussion and workaround.