sponsor Vim development Vim logo Vim Book Ad

basic Tip #938: Create PayPal "Buy Now" Buttons from a CSV Buffer

 tip karma   Rating -6/10, Viewed by 1008 

Read and edit this tip on the Vim tip wiki. The wiki may have a more recent version of this tip.

created:   June 1, 2005 3:08      complexity:   basic
author:   Richard Aldridge      as of Vim:   6.0

I started using the PayPal Button Factory the other day, but the button creation process is a bit too slow for me - so I thought I would semi-automate it in VIM ;-)

If you have a list in your buffer such as :

Product 1,PD001,30
Product 2,PD002,130
Product 3,PD003,1130
Product 4,PD004,230

you can use the following command to turn the list into unencrypted PayPal Buy Now buttons :

:%s/\(.*\)\(,\)\(.*\)\(,\)\(.*\)/<form action='https:\/\/www.paypal.com\/cgi-bin\/webscr' method='post'> <input type='hidden' name='cmd' value='_xclick'> <input type='hidden' name='business' value='my_user@my_company.com'> <input type='hidden' name='item_name' value='\1'> <input type='hidden' name='item_number' value='\3'> <input type='hidden' name='amount' value='\5.00'> <input type='hidden' name='no_note' value='1'> <input type='hidden' name='currency_code' value='GBP'> <input type='image' src='https:\/\/www.paypal.com\/en_US\/i\/btn\/x-click-but01.gif' border='0' name='submit' alt='Make payments with PayPal - it's fast, free and secure!'> <\/form>/

which generates the following HTML that you can then insert into your web page:

<form action='https://www.paypal.com/cgi-bin/webscr' method='post'> <input type='hidden' name='cmd' value='_xclick'> <input type='hidden' name='business' value='my_user@my_company.com'> <input type='hidden' name='item_name' value='Product 1'> <input  type='hidden' name='item_number' value='PD001'> <input type='hidden' name='amount' value='30.00'> <input type='hidden' name='no_note' value='1'> <input type='hidden' name='currency_code' value='GBP'> <input type='image' src='https://www.paypal.com/en_US/i/btn/x-click-but01.gif' border='0' name='submit' alt='Make payments with PayPal - it's fast, free and secure!'> </form>

Obviously you are not going to type that onto the command line every time, so you could set this up as a VIM menu button as below :

:amenu PayPal.BuyNow\ from\ CSV :<CR>
\:%s/\(.*\)\(,\)\(.*\)\(,\)\(.*\)/<form action='https:\/\/www.paypal.com\/cgi-bin\/webscr' method='post'> <input type='hidden' name='cmd' value='_xclick'> <input type='hidden' name='business' value='my_user@my_company.com'> <input type='hidden' name='item_name' value='\1'> <input type='hidden' name='item_number' value='\3'> <input type='hidden' name='amount' value='\5.00'> <input type='hidden' name='no_note' value='1'> <input type='hidden' name='currency_code' value='GBP'> <input type='image' src='https:\/\/www.paypal.com\/en_US\/i\/btn\/x-click-but01.gif' border='0' name='submit' alt='Make payments with PayPal - it's fast, free and secure!'> <\/form>/<CR><CR>

Of course you should make sure to change values in the code to match what you want - Probably, the best idea is to use PayPal to get the code for your first button, which you can then use as a template for the rest of them.

 rate this tip  Life Changing Helpful Unfulfilling 

<< tip on looking up vim help topics | Single config file for Vim on Windows with Cygwin installed. >>

Additional Notes

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.
   
Sponsored by Web Concept Group Inc. SourceForge.net Logo