PDA

View Full Version : Custom generated PayPal Button



navaldesign
04-10-2007, 06:54 AM
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



<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 (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 (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>


Now, change these two lines as follows:




<input type="hidden" name="item_name" value="<? echo $item_name; ?>">
<input type="hidden" name="amount" value="<? echo $amount; ?>">


Ok, add this code in the begining:


<?
if ($amount != 0){
?>

and the following one at the end:


<?
}
?>

At this point the entire button code will be:



<?
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>
<?
}
?>



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:



<?
$item_name = $_POST['item_name'];
$amount = $_POST['amount'];
?>


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.

aconstas1
04-10-2007, 06:57 AM
Thanks Naval. Just another one of those treasures that you wont find anywhere else.

aconstas1
04-10-2007, 07:06 AM
Does this work if I add the appropriate hidden fields and code to an encrypted button that I generate with PayPal?

aconstas1
04-10-2007, 08:26 AM
sorry another question, can you make item_name required with ABVFP or will the name extension mess up the PayPal side of it?

davidundalicia
04-10-2007, 02:37 PM
NavalDesign,

Would it not be a good idea to advise anyone that uses this tip, that they will also need a method of confirming payment BEFORE directing the client to the actual download page?

If members use this tip as it is, then the return page is visible after the paypal button has been generated and BEFORE the payment has been made......

aconstas1
04-10-2007, 06:11 PM
The buttons i generate do not grab the correct item_name
my field is correctly named and has the correct initial value
my button html also has the correct code in the value
What else could cause this?

my payment php page is HERE (http://www.aapossolutions.com/PayPal/payment.php)

aconstas1
04-10-2007, 06:27 PM
I dont know what I did, but apparently where the fields appear in html versus the button has something to do with functionality. Also i had copied and pasted the amount code and just changed the item_number name which made my amount field be entered for the item_name during button generation. I had to delete the line in the HTML code in the button and retype the line for the item_name value without copying and pasting. I dont know why this would have effected the functionality of my form and button generation, but it did.

davidundalicia
04-10-2007, 06:37 PM
Alex, when I tested your button it generated the button with the correct text in the item-name.

But the return page could not be found...maybe you should check the spelling of your return link.

aconstas1
04-10-2007, 07:14 PM
Alex, when I tested your button it generated the button with the correct text in the item-name.

But the return page could not be found...maybe you should check the spelling of your return link.
hehe yes i got it working, and it didn't find the return yet because I'm still building it. :p
Thanks for watching out for me though.

navaldesign
04-10-2007, 08:55 PM
Does this work if I add the appropriate hidden fields and code to an encrypted button that I generate with PayPal?

No, you need to use a NON encrypted button.

Can you make the "item_name" required ?

Yes, but a differents version would be needed, with a second page, which would check the amount and item name, and if the amount is not null, will chek the item name to see if it is null, and if yes, it will give an error message. If both are null, it will redirect to the same initial page.

The button is correctly generated in your page.

navaldesign
04-10-2007, 09:00 PM
NavalDesign,

Would it not be a good idea to advise anyone that uses this tip, that they will also need a method of confirming payment BEFORE directing the client to the actual download page?

If members use this tip as it is, then the return page is visible after the paypal button has been generated and BEFORE the payment has been made......

David, you are correct. But this is NOT intended for a downloadable product payment. Usually downloadable products have a fixed description and price. It is intended for a customized service payment, where the return page is simply a thank you page.

However, you are correct, and i shall place the correct warning in my initial post.

Thanks.

You know my opinion on paid for downloads: no links, no risk. The thank you page (in my opinion) MUST have a payment verification script.

davidundalicia
04-10-2007, 09:51 PM
As a method of paying for a service without a downloadable product, then once again your expertise and contribution is highly commendable and I shall use this myself..............Thanks George.

Karen Mac
04-10-2007, 11:02 PM
When copy and pasting from other sources on the web like webpages or forums, its a good idea to to first copy into notepad, then recopy the notepad code to your actual application. Very often you pick up some erroneous code or figures that may or not be visible to you, but generally notepad will eliminate that.

Alternately, could you not just make your own button and just change the URL to your .gif instead of the secured one at paypal?


<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.">

or will it give a pop up error?

Karen

aconstas1
04-10-2007, 11:09 PM
I'm using this to allow my customers to pay me their monthly bills via web site instead of me having to go collect or them mail it in. Excellent addition to the web site.

navaldesign
04-10-2007, 11:19 PM
When copy and pasting from other sources on the web like webpages or forums, its a good idea to to first copy into notepad, then recopy the notepad code to your actual application. Very often you pick up some erroneous code or figures that may or not be visible to you, but generally notepad will eliminate that.

Alternately, could you not just make your own button and just change the URL to your .gif instead of the secured one at paypal?



or will it give a pop up error?

Karen

Hi KAren,

yes, you can change the image source. No problem

Windameer Farm
04-20-2007, 04:00 PM
Hello,

Can I get some help with this and a form I'm trying to connect it to please. the for url is www.windameer.com/feltitemsforsale.php (http://www.windameer.com/feltitemsforsale.php) .

Thanks Jolen

navaldesign
04-20-2007, 05:15 PM
Hello,

Can I get some help with this and a form I'm trying to connect it to please. the for url is www.windameer.com/feltitemsforsale.php (http://www.windameer.com/feltitemsforsale.php) .

Thanks Jolen

Here is the procedure that you should have followed:

The form submits. So your button should NOT have "Generate" but should have a label like "Calculate cost". Then, you should have a script, in the cost calculation page, that will receive the form details, email you the order details, calculate the cost, and, if the amount is >0, create the button code (which will also make the button visible). As it is now, it only submits to the "action.php" page, and then it doesn't do anything.

Windameer Farm
04-20-2007, 06:38 PM
Here is the procedure that you should have followed:

The form submits. So your button should NOT have "Generate" but should have a label like "Calculate cost". Then, you should have a script, in the cost calculation page, that will receive the form details, email you the order details, calculate the cost, and, if the amount is >0, create the button code (which will also make the button visible). As it is now, it only submits to the "action.php" page, and then it doesn't do anything.

Thank you Navaldesign. I think this one is a bit over my head :). I'm goignt o put it on hold for now and finish the rest of the web pages. maybe by then i'll deside on what to do with this.

Thank you for your help and i'm useing alot of your tips well rebuilding :)
Jolen

navaldesign
04-20-2007, 06:50 PM
It is really very simple.
You create a page that you will name "action" and publish as php. In the Start of Page (of the html code of the page) you will paste the same script that you will find in the Forms Tutorial Part 1. This will email the order details to you. Then, you will have a html box, with the code that will create the PayPal button.

If you want, create this page, as you want it visually, and send me the .bvp file, i will place the code and send it back to you ready for publishing.

Windameer Farm
04-20-2007, 07:00 PM
Ok I'll do that and send it to you thanks.

Windameer Farm
04-20-2007, 09:29 PM
It is really very simple.
You create a page that you will name "action" and publish as php. In the Start of Page (of the html code of the page) you will paste the same script that you will find in the Forms Tutorial Part 1. This will email the order details to you. Then, you will have a html box, with the code that will create the PayPal button.

If you want, create this page, as you want it visually, and send me the .bvp file, i will place the code and send it back to you ready for publishing.

Thank you I made it and sent it to you threw you web site. sorry i sent the wrong one the frist time.

cct9105
05-26-2007, 06:18 AM
Hi Navaldesign,

I did a form with check box choices which amount a customer can donate and I want to integrate the with paypal so they can pay using visa/mastercard if they click "make donation". To give you an idea what I am doing pls. go to
http://www.millarefoundation.com/dform.html

Thanks and I appreciate your help.

janeth

navaldesign
05-26-2007, 07:01 AM
There are some mistakes in your form:
1. The page must be php and not html.
2. The form has no action at all. The action should be the page itself: "dform.php"
3. Encoding type: it is set to text / plain, must be multipart / form data
4. You need Radio buttons, not checkboxes because only one ammount should be chosen.
5. These radio buttons should have the same Group name (at the moment they are unnamed)
6. You do NOT have the "If "statement so hat the button will only appear after a selection has been made.
7. You did not define any item name, item value etc when creating the button. Also no return page. Did you create it in PayPal, or did you use BV's PayPal tool?
8. You did not replace the item name and value (which do not exist) with the php code as per tutorial.
Please read again and follow the instructions.

cct9105
05-26-2007, 12:53 PM
Thank you for you reply. I redo and I'll be back. I had my paypal account already but I used the paypal in the BV that's why I don't know how can to link it.

cct9105
06-05-2007, 07:13 PM
Hi Navaldesign,

I'm back seeking help again, I used the radiobutton, now how can I pass the value selected to the paypal form. to complete the transaction. I know nothing about HTML.
Thanks.

navaldesign
06-05-2007, 09:08 PM
The radio button group name should be "amount" so the amount is passed to the script. If you do so, the value selected will be automatically be passed to the script. Just follow the initial instructions in post #1 in this same thread, replacing the text box with the radio buttons group.

cct9105
06-24-2007, 05:29 AM
Hi Navaldesign,

I'm back, still trying to finish my paypal form but I couldn't get it, if you have a few minutes kindly check www.millarefoundation.com/payment.php (http://www.millarefoundation/payment.php) and point me where did I go wrong.

Thanks and appreciate your effort.

navaldesign
06-24-2007, 07:48 AM
Your Radio buttons should have, as value, the amount corresponding to each one. They are null right now

cct9105
07-01-2007, 10:22 AM
Hi Navaldesign,

I'm back again, sorry for taking so long quite busy on everything, if you have spare time kindly check what I did and give you fine suggestion.
Thanks and I really appreciate your help I learn a lot from you.

I just have another question on HMTL though, how can I insert a line in between text.

http://www.millarefoundation/payment.php

navaldesign
07-01-2007, 11:43 AM
Yes, your script works, though i would have added some code so that the visitor doesn't have to make two selections one for description and one for amount. However, these are personal choices. Good work.

Not sure what you mean "insert a line in text". You mean a Fine Feed ? if that is the case, suppose you need to display the following text:

This is line one

This is line three because there is an empty line.

The code is:

<font style="font-size:13px" color="#000000" face="Verdana">This is line one<br>
<br>
This is line three because there is an empty line.</font>

As you see the two <br> 's cause the CR from line one to line two and yet to line three.

cct9105
07-01-2007, 02:57 PM
Hi Navaldesign,

Thanks, I though of that if a visitor chooses the a certain the description will be selected automatically but I don't know how to do it, second, how can I keep the button to a selected one.

I do appreciate your help seems your are the guru. :))

janeth

navaldesign
07-03-2007, 08:52 AM
Hi Navaldesign,

Thanks, I though of that if a visitor chooses the a certain the description will be selected automatically but I don't know how to do it, second, how can I keep the button to a selected one.

I do appreciate your help seems your are the guru. :))

janeth

Depending on your form, the script has to be adapted. Have a look at this example: http://www.dbtechnosystems.com/Tips/radio_payment.php

If you like it, contact me and i will send you the file.

cct9105
07-03-2007, 02:50 PM
Thank you very much, Navaldesign, you are such a nice person, very helpful. I love to have a copy of what you did.

navaldesign
07-03-2007, 04:44 PM
Contact me through my form (http://www.dbtechnosystems.com/contact.php) so i can email the file to you.

cct9105
07-08-2007, 05:14 AM
Hi Navaldesign,

I did fillout your form, iyour reply form is very nice,how did you make in table format. Thanks and I'll be happy if you can share it.

navaldesign
07-08-2007, 07:19 AM
This is a bit complicated. It requires sending html email and hardcoding the mail content. I do that on a professional basis.

cct9105
07-10-2007, 08:54 PM
Thanks a lot with code you sent though but have a fe problem, I cant go through my paypal account it always say incorect formatted amount item. I tried everything that I know but still do the same, maybe I missing sonething on the HTML I'm not sure. Kindly take a look again on your spare time pls.

www.millarefoundation.com/payment.php (http://www.millarefoundation.com/payment.php)

for my prevous question: Yes, I agree with that it is a complicated one and I noticed also the one that you created on the payment.php is a hardcoded amount. I hope will learn more as I am venturing myself in website development.

I really appreciate your willingness to help.

navaldesign
07-10-2007, 08:57 PM
Hi

check your paypal button code. Also, you could change he settings in the form so that the radio buttons start from 1 instead of 0 . This way it will NOT default to the first choice as it does now. In that case make the first radio NOT selected

cct9105
07-15-2007, 05:22 AM
Hi Navaldesign,

I finally finished my form, just a few error on the quotation part o the html, you are an angel in finishing this portion of the website.

Thank you very much.

Mdpeters
08-08-2007, 07:36 PM
My turn to ask for help with this button. Can you look at www.vacations-afloat.com/payments.html (http://www.vacations-afloat.com/payments.html) and tell me where i am going wrong. I can't figure out how to make the initial value work without displaying their values.

Thanks for your anticipated help

Michael

michael@vacations-afloat.com

navaldesign
08-08-2007, 09:00 PM
You have published the page as html. Please read the instructions, you need to publish it as php

Mdpeters
08-12-2007, 09:40 AM
Thanks for that, the mistake was in the menu buttons which were pointing at an .html page and not the .php one.

Next question, we sell vactaions and therefore each transaction is a different value, hence the need for your custom button. We also sell in 3 currencies, US Dollars, British Pounds and Euros, can I add the ability to select currency to the cutom buton? If so how do i do tis?

Many thanks
Michael

navaldesign
08-12-2007, 08:39 PM
You can add in the form ALL the parameters of the PayPal button: amount, item descriptin, item nr., amount, currency, etc. The code has to be changed acordingly, and the form fields must reflect the code elements. So, change the button code to :


<?
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 $_POST['item_name']; ?>">
<input type="hidden" name="item_number" value="">
<input type="hidden" name="amount" value="="<? echo $_POST['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="<? echo $_POST['currency'];?> ">
<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>
<?
}
?>

and include, in the form, a drop down with the thre values : USD, GBP, EUR for the three currencies you need.

Mdpeters
08-14-2007, 05:00 PM
I am obviously being very stupid about this i now get an error:
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in /home/xdqsufol/public_html/payments.php on line 280
Might be easier if i paid you to do this for us

navaldesign
08-14-2007, 05:38 PM
Hi,

this is entirely up to you. If you wish you can contact (http://www.dbtechnosystems.com/contact.php) me privately.

Frosty
09-10-2007, 04:24 PM
David, you are correct. But this is NOT intended for a downloadable product payment. Usually downloadable products have a fixed description and price. It is intended for a customized service payment, where the return page is simply a thank you page.

However, you are correct, and i shall place the correct warning in my initial post.

Thanks.

You know my opinion on paid for downloads: no links, no risk. The thank you page (in my opinion) MUST have a payment verification script.

Fair enough, but im wondering what the code-lines would be then for a single item download so there's no messing around with amount, just "yes I want to download that file"

navaldesign
09-10-2007, 05:47 PM
I am not sure what you mean here. if you only want one item, at a fixed price, just create the correct PayPal button and add it in your sales page. The comment David had done, is that since you are using NON encrypted button code, this trick should NOT be used for downloadable products.

There are a few ways to have protection for your download link. The best, in my opinion, is to have a script that will check the payment, with PayPal, and if the payment is ok, it will display the download link ( attention: NOT the file name, just the link). Otherwise it will display an appropriate error messaGE.

I do have a script that allowes excactly this task: it is called IDC (Instant Download Cart) but it is a pro script and as such it is not free. If you are interested, you can contact me through my form (http://www.dbtechnosystems.com/contact.php).

yourgmsolutions
03-20-2008, 08:29 AM
I've been playing around with paypal buttons resently. and I founded very simple solution.
1. log in to your paypal account
2. select merchant tab
3. you'll see a dozen of options for buttons/carts/customizations
4. make selections and paypal will automatically generate html code for you
5. copy and then paste it on your web page

navaldesign
03-20-2008, 08:36 AM
Hi,

this is not to disappoint you, but this is not the subject of this thread. Creating the button code in the PayPal site is something well known to most users. It can also be done directly in BV. The question here is HOW the user will be able to modify the button properties (subcription and amount) directly on your webpage, when different services / prices are required.

yourgmsolutions
03-20-2008, 10:14 AM
sorry, my bad. I guess I missunderstood the point.
sorry again

msandeepk
10-17-2011, 12:25 PM
How safe is it to use Not encrypted buttons.
Because here we are directly providing Merchant e-mail. If any one modifies the merchant email(business).
Then amount will be transferred to others email instead of our account.
Is there any other way to have textbox to provide custom amount by using Encrypted button(without providing Merchant e-mail).

Thanks,
Sandeep M.

navaldesign
10-17-2011, 03:05 PM
You can always create buttons in PayPal site.

However, the only risk you have is that your email address gets "caught" by spam bots so you will be receiving spam mails.

There is no way a payment can be diverted from your account to another one, with buttons that are on YOUR website, even if they are not encrypted, unless they reproduce your own website and fraud customers by making them think that they are purchasing from you whilst, instead, they are purchasing (and paying) from a fraudelent website.

aspen
12-12-2011, 02:08 PM
Thanks for this very helpful article.I read another article (http://www.softcoded.com/paypal/paypal_php.php) where the payment.php page is invisible to the customer and submits itself automatically with javascript when it loads. The Paypal "Buy Now" button is on the first page (the "Generate" button in your example website). The customer is directed straight to Paypal via the invisible, automatic payment.php page, which sends the necessary information using the hidden input fields.Would this method be safe, do you think, for a website selling downloadable products?

navaldesign
12-13-2011, 02:09 PM
Generally speaking selling downloadable products requires a "protection" script.

aspen
12-14-2011, 10:47 AM
In your script above, you have,

<input type="hidden" name="return" value="http://www.yoursite.com/returnpage.php">

If I change this to

<input type="hidden" name="return" value = "http://www.yoursite.com/returnpage.php?status=TRUE">
<input type="hidden" name="cancel_return" value = "http://www.yoursite.com/returnpage.php (http://www.yoursite.com/returnpage.php)?status=FALSE">

do you think this would be a satisfactory protection script to verify whether payment has been made or not?

navaldesign
12-14-2011, 02:21 PM
No. The status is visible in the button code so where knows a bit more than the average user, will be able to reproduce it by simply typing it in the browser address bar.Please note that if you create encrypted buttons in PayPal's site, the return page is not visible. This might give you a minimum of security. However, the download itself is not secured, meaning that if anyone finds the download link and posts it on some interner hacker blog, everyone will be able to download your e-products.

You would need to use a protection script that works with PayPal's IPN and protects the download by actually checking is a user is authorized to download.