Linked In Profile 
Posted 12 February 2008
4 Comments

Just recently I started playing around with adding PayPal buttons to a Flash file and was pleasantly surprised at how simple it was. Granted, I only did a basic “buy now” button which is about the simplest piece of code they offer. For those of you interested (and for my own code archiving), here is how to go about doing it:

Set up your Sandbox

First thing I did was set up a sandbox so I could spend money like it’s going out of style. Monopoly money that is. Paypal has set up a nice area for developers to test their applications and their code. And considering all of this is dealing with money, it’s a good thing to test things out before you go live.

To set up your sandbox account, point your browser to: developer.paypal.com and sign up for an account. Once you have an account, you can set up as many users as you’d like, but you will need at least two: a seller and a buyer.

Once you’re up and running with that, you will need your seller email to do some testing.

Make your button

Open up Flash and design a great-looking button. More importantly though, be sure your button is indicative of the action the user is about to take (i.e. Buy Now, or Buy via PayPal are both good options). Now add some simple code:


paypal_btn.onRelease = function() {
//create the LoadVars that will hold our paypal information
var paypal = new LoadVars();

//specify the business, amount of the item, shipping, etc.
paypal.cmd = "_xclick";
paypal.upload = "1";
paypal.business = "your_seller_email@yourdomain.com";
paypal.item_name = "Your great product";
paypal.item_number = "001"; // this is a product or part number.
paypal.amount = "25.00";
paypal.shipping = "5.00";
paypal.tax = "2.50";
paypal.currency_code = "USD";

//send information to PayPal
paypal.send("https://www.paypal.com/cgi-bin/webscr","_blank", "POST");
}

While testing, you will want your paypal.business to reflect the email address you set up for your sandbox. Be sure to change it to your real address when you’re ready to go live.

And that’s it folks. I told you it was simple. Now a word of caution: I have no tested this thoroughly, but my initial tests seem to work just fine. I’m sure there are better and more complicated implementations of PayPal using Flash, but for my intents and purposes, this will suffice.

4 Responses to “PayPal buttons in Flash”

  1. john Says:


    dude, you just saved me hardcore. i was freaking out trying to figure out if i was going to embed html into my flash, embed flash into my html, use one of these paypal flash button makers, or have use dreaded html or dreamweaver to actually make my store. you just saved me and i cant thank you enough.

  2. D Molanphy Says:


    That’s awesome! I hope you find it as simple as I did. I think the folks at PayPal have really done a nice job of implementing this.

  3. Natalie Says:


    Hi!

    I followed the instructions here to create a ‘buy now’ button in flash. I have a question about the paypal.send part – the URL you call there is the paypal website. Do I need to replace that URL with something else to test with the sandbox? Because of course when I try to login there with the buyer info created by my sandbox it doesnt work.

    I was also curious as to how this works… Does paypal automatically read the vars set up in the actionscript, or do I need to set up another document using POST method so that paypal can read the variables?

    ps. Your website is VERY well designed – beautiful to look at and works perfectly

  4. D Molanphy Says:


    Hi Natalie:

    First of all, thank you! Secondly, no, you don’t need to change the URL. All I did to make it work on my end was change this line:

    paypal.business = "your_seller_email@yourdomain.com";

    to include my sandbox seller email. The variables get handled directly by Flash using the LoadVars object. If you notice the URL, it already sends the variables using POST – PayPal simply takes them from the browser and uses them.