PayPal Script Buy Now Button Code

Zenguy

New Member
I'm having trouble getting my button to work.
Below is my code so far.
Can you give me some direction or do you have some code for a button?
I wasn't sure if I had to create code to figure out the fees either...so that's
in there too.


Code:
<?php
function paypalFees($sub_total, $round_fee) {
     
    // Set Fee Rate Variables : 
    $fee_percent = '2.9'; 
    $fee_cash = '0.30'; 
     
    // Calculate Fees
    $paypal_fee = ((($sub_total / 100) * $fee_percent) + $fee_cash);
     
    if ($round_fee == true) {
        $paypal_fee = ceil($paypal_fee);
    }
     
    // Calculate Grand Total
    $grand_total = ($sub_total + $paypal_fee);
     
    // Tidy Up Numbers
    $sub_total = number_format($sub_total, 2, '.', ',');
    $paypal_fee = number_format($paypal_fee, 2, '.', ',');
    $grand_total = number_format($grand_total, 2, '.', ',');
     
    // Return Array
    return array('grand_total'=>$grand_total, 'paypal_fee'=>$paypal_fee, 'sub_total'=>$sub_total);
}

	// Set the fees and gross minus fees
    $calc = paypalFees('20.00', false);
	$mc_gross = $receipt['sub_total'];
	$mc_fee = $receipt['paypal_fee'];
	$settle_amount = $mc_gross - $mc_fee;
	
?>

<form method="post" action="https://www.sandbox.paypal.com/cgi-bin/webscr" target="_top">
<input type="hidden" name="cmd" value="_xclick">

<!-- Business Info -->
<input type="hidden" name="business" value="woodthings-facilitator@ripnet.com">
<input type="hidden" name="notify_url" value="http://mysite.com/ipn/ipn_process.php">
<input type="hidden" name="return" value="http://mysite.com/ppb.php">
<input type="hidden" name="receiver_email" value="myemail@gmail.com" />
<input type="hidden" name="mc_currency" value="USD">
<input type="hidden" name="settle_currency" value="USD">

<!-- Customer Info -->
<input name="first_name" type="hidden" value="First Name" />
<input name="last_name" type="hidden" value="Last Name" />
<input name="payer_email" type="hidden" value="customer@gmail.com" />
<input name="payer_business_name" type="hidden" value="Payer Business Name" />
<input name="address_street" type="hidden" value="10 Home Street" />
<input name="address_zip" type="hidden" value="K7K 9A9" />
<input name="address_city" type="hidden" value="Ottawa" />
<input name="address_state" type="hidden" value="Ontario" />
<input name="address_country" type="hidden" value="Canada" />
<input name="address_country_code" type="hidden" value="CA" />
<input name="residence_country" type="hidden" value="CA" />

<!-- Art Item Info -->
<input type="hidden" name="on0" value="Item Name">Art Item Name<br />
<input type="text" name="os0" maxlength="200"><br />
<input type="hidden" name="on1" value="Item Size">Art Item Size<br />
<input type="text" name="os1" maxlength="200"><br />
<input type="hidden" name="on2" value="Item Info">Art Item Info<br />
<input type="text" name="os2" maxlength="200"><br />

<!-- Item Customer Is Purchasing -->
<input type="hidden" name="item_name" value="Call For Art - 1 Item">
<input type="hidden" name="item_number" value="CFA-001">
<input type="hidden" name="quantity" value="1">
<input type="hidden" name="mc_gross" value="<?php echo $mc_gross;?>">
<input type="hidden" name="amount" value="<?php echo $mc_gross;?>">
<input type="hidden" name="mc_fee" value="<?php echo $mc_fee;?>">
<input type="hidden" name="settle_amount" value="<?php echo $settle_amount;?>">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="shipping" value="0">
<input type="hidden" name="tax" value="0">

<input type="image" src="http://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
Thanks for your time
 

Zenguy

New Member
I managed to get most of the code to work, but the price of the item is not showing up on the initial paypal landing page. It's showing an empty box to put in the price.
In the button code I have both mc_gross and item_amount.
Also how will I show my custom fields on the landing page and receipt emails?
Custom fields:
Code:
<input type="hidden" name="on0" value="Item Name">Art Item Name<br />
<input type="text" name="os0" maxlength="200"><br />
<input type="hidden" name="on1" value="Item Size">Art Item Size<br />
<input type="text" name="os1" maxlength="200"><br />
<input type="hidden" name="on2" value="Item Info">Art Item Info<br />
<input type="text" name="os2" maxlength="200"><br />
Thank you.
 

Zenguy

New Member
Well... a few hours later I figured everything out.
Just an FYI for others wanting to post custom variables from a button then have them sent through the IPN process and back to your site please see below.
1st create the custom fields in you button:
Code:
<input type="hidden" name="on1" value="1st Item Name">1st Art Item Name<br />
<input type="text" name="os1" maxlength="200"><br />
<input type="hidden" name="on2" value="1st Item Size">1st Art Item Size<br />
<input type="text" name="os2" maxlength="200"><br />
<input type="hidden" name="on3" value="1st Item Info">1st Art Item Info<br />
<input type="text" name="os3" maxlength="200"><br />
<input type="hidden" name="on4" value="2nd Item Name">2nd Art Item Name<br />
<input type="text" name="os4" maxlength="200"><br />
<input type="hidden" name="on5" value="2nd Item Size">2nd Art Item Size<br />
<input type="text" name="os5" maxlength="200"><br />
<input type="hidden" name="on6" value="2nd Item Info">2nd Art Item Info<br />
<input type="text" name="os6" maxlength="200"><br />
<input type="hidden" name="on7" value="3rd Item Name">3rd Art Item Name<br />
<input type="text" name="os7" maxlength="200"><br />
<input type="hidden" name="on8" value="3rd Item Size">3rd Art Item Size<br />
<input type="text" name="os8" maxlength="200"><br />
<input type="hidden" name="on9" value="3rd Item Info">3rd Art Item Info<br />
<input type="text" name="os9" maxlength="200"><br />
Please note how I started with on1/os1 (not on0/os0)...I will explain later.
Now when PayPal sends these fields back to you they do not get posted back as on1/os1.
They get posted back as option_name1/option_selection1

Now to explain starting at on1/os1 over on0/os0.
If you start with on0 PayPal will post it back as option_name1...not option_name0.

Whew! :D

All better now.
 
Top