Hi everyone,
i have been recently asked by some members how you can create a custom generated PayPal Buy Now button. These buttons are extremely useful and are the basis of customized payments. Ok, let's see how you do this. We will suppose here that you want to create a button where amount and item description are user defined. The same technique can be used to customize any other parameter that a PayPal button allows for, as Currency, shipping etc. A working example can be seen in my own payments page, in http://www.dbtechnosystems.com/payment_general.php
For this tutorial, we will asume that the page (which needs to be in php) is called "payment.php"
Ok, lets see the steps one by one:
1. Creating the main button code:
Go in your PayPal account, and create a button with the charatteristics you like. As we said, we will customize Item description and amount, so don't care about these two things, you can place there as amount "10" and as description: "example description". You will get a code like
Now, change these two lines as follows:
Ok, add this code in the begining:
and the following one at the end:
At this point the entire button code will be:
Add a html box, more or less the same size as the button that you want to create, in your page, and paste the code in it. Place the html box where you want it to appear.
Step 2. Create the form that will customize the button: this is a very simple form, with two fields: "amount", and "item_name". Please use exactly these names, as they are the same that PayPal uses. Add a submit button. Set the form action in "payment.php" so the page will submit to itself, the method to "POST", the encoding type to "multipart / form data".
Double click the amount field and the initial value to be
<? echo $amount; ?>
Double click the item_name field and set the initial value to be <? echo $item_name; ?>
Ok, the form part is finished.
Step 3. Go to Page html, and paste the following code in the Start of page Tag:
Now, set your page extension to be php when published, save, and publish.
That's all, have fun!!
Warning: this trick asumes that you use a NON ENCRYPTED PayPal buy now button. Ad Davidindalicia has correctly stated in a post furher down, the code results clear to whoever views the source code. So, anyone can see the return page link. Conclusion: do NOT use this trick to generate a PayPal Button for downloadable products, unless you have a script that will verify the payment before allowing the download link(s) to appear in the return page.
This trick is intended for customized payments, where the return page is simply a thank you page (you send the product yourself, either per email, if it is an electronic product, or phisically ship it, if it is a real product), or for those cases where the product is a downloadable one, but the download link is protected by a payment verification code as described above.
i have been recently asked by some members how you can create a custom generated PayPal Buy Now button. These buttons are extremely useful and are the basis of customized payments. Ok, let's see how you do this. We will suppose here that you want to create a button where amount and item description are user defined. The same technique can be used to customize any other parameter that a PayPal button allows for, as Currency, shipping etc. A working example can be seen in my own payments page, in http://www.dbtechnosystems.com/payment_general.php
For this tutorial, we will asume that the page (which needs to be in php) is called "payment.php"
Ok, lets see the steps one by one:
1. Creating the main button code:
Go in your PayPal account, and create a button with the charatteristics you like. As we said, we will customize Item description and amount, so don't care about these two things, you can place there as amount "10" and as description: "example description". You will get a code like
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="you@yoursite.com">
<input type="hidden" name="item_name" value="example description">
<input type="hidden" name="item_number" value="">
<input type="hidden" name="amount" value="10">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="return" value="http://www.yoursite.com/returnpage.php">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="bn" value="PP-BuyNowBF">
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but02.gif" border="0" name="submit" alt="Make your payments with PayPal. It is free, secure, effective.">
<img alt="" border="0" src="https://www.paypal.com/it_IT/i/scr/pixel.gif" width="1" height="1">
</form>
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="you@yoursite.com">
<input type="hidden" name="item_name" value="example description">
<input type="hidden" name="item_number" value="">
<input type="hidden" name="amount" value="10">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="return" value="http://www.yoursite.com/returnpage.php">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="bn" value="PP-BuyNowBF">
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but02.gif" border="0" name="submit" alt="Make your payments with PayPal. It is free, secure, effective.">
<img alt="" border="0" src="https://www.paypal.com/it_IT/i/scr/pixel.gif" width="1" height="1">
</form>
<input type="hidden" name="item_name" value="<? echo $item_name; ?>">
<input type="hidden" name="amount" value="<? echo $amount; ?>">
<input type="hidden" name="amount" value="<? echo $amount; ?>">
<?
if ($amount != 0){
?>
if ($amount != 0){
?>
<?
}
?>
}
?>
<?
if ($amount != 0){
?>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="you@yoursite.com">
<input type="hidden" name="item_name" value="="<? echo $item_name; ?>">
<input type="hidden" name="item_number" value="">
<input type="hidden" name="amount" value="="<? echo $amount; ?>">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="return" value="http://www.yoursite.com/returnpage.php">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="bn" value="PP-BuyNowBF">
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but02.gif" border="0" name="submit" alt="Make your payments with PayPal. It is free, secure, effective.">
<img alt="" border="0" src="https://www.paypal.com/it_IT/i/scr/pixel.gif" width="1" height="1">
</form>
<?
}
?>
if ($amount != 0){
?>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="you@yoursite.com">
<input type="hidden" name="item_name" value="="<? echo $item_name; ?>">
<input type="hidden" name="item_number" value="">
<input type="hidden" name="amount" value="="<? echo $amount; ?>">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="return" value="http://www.yoursite.com/returnpage.php">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="bn" value="PP-BuyNowBF">
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but02.gif" border="0" name="submit" alt="Make your payments with PayPal. It is free, secure, effective.">
<img alt="" border="0" src="https://www.paypal.com/it_IT/i/scr/pixel.gif" width="1" height="1">
</form>
<?
}
?>
Step 2. Create the form that will customize the button: this is a very simple form, with two fields: "amount", and "item_name". Please use exactly these names, as they are the same that PayPal uses. Add a submit button. Set the form action in "payment.php" so the page will submit to itself, the method to "POST", the encoding type to "multipart / form data".
Double click the amount field and the initial value to be
<? echo $amount; ?>
Double click the item_name field and set the initial value to be <? echo $item_name; ?>
Ok, the form part is finished.
Step 3. Go to Page html, and paste the following code in the Start of page Tag:
<?
$item_name = $_POST['item_name'];
$amount = $_POST['amount'];
?>
$item_name = $_POST['item_name'];
$amount = $_POST['amount'];
?>
That's all, have fun!!
Warning: this trick asumes that you use a NON ENCRYPTED PayPal buy now button. Ad Davidindalicia has correctly stated in a post furher down, the code results clear to whoever views the source code. So, anyone can see the return page link. Conclusion: do NOT use this trick to generate a PayPal Button for downloadable products, unless you have a script that will verify the payment before allowing the download link(s) to appear in the return page.
This trick is intended for customized payments, where the return page is simply a thank you page (you send the product yourself, either per email, if it is an electronic product, or phisically ship it, if it is a real product), or for those cases where the product is a downloadable one, but the download link is protected by a payment verification code as described above.
Comment