16 Replies Latest reply on May 31, 2006 10:23 AM by kglad

    Paypal add to cart button & combobox variable question

    ccesca
      HI,

      I am using Flash MX 2004 on the mac platform.

      A while backcI found the following code that enabled me to set up paypal donatoins from my flash site. It was after searching through a huge amount of complicated code and help forum ideas that I eventually found what turned out to be incredibly simple (in my opinion). I have a button on the stage called button1 , and I place the following code in the first frame of my main timeline.

      stop();

      function makeDonation1() {
      var lv : LoadVars = new LoadVars();
      lv.cmd = "_xclick";
      lv.business = "me@mydomain.com";
      lv.item_name = "monkey";
      lv.item_number = "monkey01";
      lv.no_note = 1;
      lv.currency_code = "USD";
      lv.tax = 0;
      lv.lc = "US";

      lv.send("https://www.paypal.com/cgi-bin/webscr", "POST");
      }

      Button1.addEventListener("click", makeDonation1);



      I'm definitely not a coder and understand actionscript only just enough to get through each project - no matter how much I try at this point however, most knowledge slips through the seive in my brain by the time it comes to use that knowledge again - grrrr.

      What I am trying to do is two things.

      1. Convert the above code to an add to cart button. (I know that the donation code above might have to change to different variables for an add-to-cart button, but I'm not sure what they are or which ar erequired by paypal at the very least.)

      2. have the item name, item reference & price be determined by the value of a combobox selection. (download link to my fla below to understand better).

      I have never used comboxes before, and my first challenge is figuring out how to make a combobox user selection change the value of a variable (or three variables in this instance - item name /item ref/item cost). How do I do this???? surely there is not much other use for a combobox than to change the values of variables but I can't find any simple info on this online! Is the 'data' where i put the variable value??? how do i refer to this elsewhere?? woudl it be:

      myvariable1 = combobox1.data

      (Total guess - no idea if that's even valid code or if the data is where I would get the value from)

      I will try to figure this out by myself, but if anyone can help me out I'd be really grateful,

      Thanks in advance

      Cheska

      PS) here is a link to download my zipped FLA ( I haven't added any code yet for the three variables relating to the combobox choices - because I don't know how !) [url]http://www.lucid-life.com/paypaltest.fla.zip[/url]
        • 1. Re: Paypal add to cart button & combobox variable question
          kglad Adobe Community Professional & MVP
          the code you show calls paypal. you don't want to do that with an add-cart-button. you want to do that when your user has added all the items to their cart that they want and are ready to purchse.

          your add-to-cart button should be updating your total purchase value variable. i believe for paypal that's something like amount_1. to use a combobox to updata that variable use the combobox'es value property (and make sure your combobox is not editable).
          • 2. Re: Paypal add to cart button & combobox variable question
            ccesca Level 1
            Hi Kglad!

            Thanks for your response,

            the thing is, i want the user to be able to see a list of the items they purchase when they get to paypal, not just the totl amount. I dont mind if the user has to keep clicking 'continue shopping' from within paypal each time...

            does that make any sense?

            Cheska
            • 3. Re: Paypal add to cart button & combobox variable question
              kglad Adobe Community Professional & MVP
              your shoppers will have to make 3 visits to paypal and execute payment instructions 3 times in order to purchase 3 items. is that what you want?
              • 4. Re: Paypal add to cart button & combobox variable question
                ccesca Level 1
                Hi,

                hmm..well no, not really.

                isnt there an in-between way where they add an item to a cart , which directs them to paypal, where they hit 'contiue shopping', where they then return to my site to continue shopping....

                yes they will have to visit paypal 3 times to buy three things, but they dont have to checkout each time.......

                in th ecase that they will need to finally checkout from my site without adding a fnal buton i suppose i will need a chekout button also....

                Cheska

                (ps. are yo uable to clue me in on the combobox proble at all Kglad? basically, how do i get myVariable to be the data from myCombobox user selectoin?)

                • 5. Re: Paypal add to cart button & combobox variable question
                  kglad Adobe Community Professional & MVP
                  paypal has more than 1 level of service. i believe with their lowest level you can only see one total purchase price for one item (or group of items). i'm not aware that the lowest level of service offers what you suggested in your last message, but i'm not an expert on paypal.

                  i'm pretty sure paypal does have a level of service that lets your user see an itemized list of the items they are purchasing, but you should check with paypal's instructions to determine how to use that service.

                  for your combobox, use its value property as i mentioned above.
                  • 6. Paypal add to cart button & combobox variable question
                    ccesca Level 1
                    Hi Kglad / Anyone else,

                    Well I'm using Paypal Payments Standard, which has cart capabilities where it lists each item each tim eyou add something new

                    An Update:.

                    In Flash, I've gotten as far as:

                    function addCart1() {
                    var lv : LoadVars = new LoadVars();
                    lv.add = "1";
                    lv.cmd = "_cart";
                    lv.business = "info@vitaledgeaid.org";
                    lv.item_name = "hat";
                    lv.item_number = "hat01";
                    lv.amount = "10.00";
                    lv.no_shipping = "2";
                    lv.no_note = "1";
                    lv.currency_code = "USD";
                    lv.bn = "PP-ShopCartBF";

                    lv.send("https://www.paypal.com/cgi-bin/webscr", "POST");
                    }

                    Button1.addEventListener("click", addCart1);


                    The above are the variables that paypal needs (I looked at the html code generated by the paypal button generaor) but when I use the above code with flash it returns an error on the paypal page......could it have to do with the first variable 'add' ...because in flash it returns an error on the output window saying it expects something after the 'add' ....i guess this word is an 'illegal' word in the code....how do i work around this?

                    Thanks anybody in advance

                    Cheska
                    • 7. Re: Paypal add to cart button & combobox variable question
                      kglad Adobe Community Professional & MVP
                      add is a reserved word in flash so you can't use it to define a variable's name. to work-around paypal's request for a variable named add, append it to the url:

                      lv.send("https://www.paypal.com/cgi-bin/webscr?add=1", "POST");

                      p.s. what is the purpose of that variable/value?
                      • 8. Re: Paypal add to cart button & combobox variable question
                        ccesca Level 1
                        Hi Kglad,

                        I'm not sure what its for...perhaps to 'add new items to the cart list ' instead of just adding the total to the amount (as happened with some previous failed experiments of mine)...or ..sorry i dont know, lol.

                        I have made considerable progress (spent all day saerching forums) and now have the following code, but i still have a stumbling stone, i wonder if you can help??? so now, i ahev my stage, with a button and a combobox. in the first frame of my movie i have:



                        stop();

                        var myVB = "hat";
                        var myVB2 = "ref-h";
                        var myVB3 = "10.00";

                        function setDisplays(){
                        myVariable = myCombo.getValue();
                        if (myVariable == "a"){
                        myVB="hat";
                        myVB2="ref-hat";
                        myVB3="10.00";
                        } else if (myVariable == "b"){
                        myVB="hat&g";
                        myVB2="ref-hg";
                        myVB3="20.00";
                        } else if (myVariable == "c"){
                        myVB="hat,g&s";
                        myVB2="ref-hgs";
                        myVB3="30.00";
                        }
                        }

                        myCombo.addEventListener("change", setDisplays);



                        and on my button i have:

                        on (press) {
                        paypal = new LoadVars();
                        paypal.cmd="_cart";
                        paypal.item_number= myVB2;
                        paypal.item_name= myVB;
                        paypal.upload="1";
                        paypal.business="sales@mydomain.com";
                        paypal.currency_code="USD";
                        paypal.amount= myVB3;
                        paypal.handling ="2.00";
                        paypal.send("https://www.paypal.com/cart/add=","_blank","post");
                        }




                        i found this button event code on a forum and it works (i guess the url is what i notice to be primarily different from all other code i've seen before) great (if i put the variable values directly in this bit of code). however, as you know, i want three of the variables to change depending on teh combobox sselection. So you can see what i did (and i checked that my variables are working because i set 4 dynamic text boxes on the stage to display the contenst of my 4 variables (myvariable, myVB, myVB2, myVB3)...and they are changing appropriately.

                        But it doesn't work

                        the paypal page i get returns an error saying i sent incorrect item values or something.....i guess flsh actually sends " myVB' etc..instead of the content of that variable of the same name.

                        is there an obvious reason for this that you know of or can help me with? I'm hoping my order of code is just backwards or something...

                        Thanks as always for your help (you have helped me MANY times before over the years!)

                        Cheska


                        • 9. Re: Paypal add to cart button & combobox variable question
                          kglad Adobe Community Professional & MVP
                          does paypal expect a number for any of those variable values or are they all expected to be strings?
                          • 10. Re: Paypal add to cart button & combobox variable question
                            ccesca Level 1
                            Hi Kglad,

                            Well, I've just looked through their documentation and could only find definitions and explanations for each variable, but not what type each where. Unfortunately also, I find no record anywhere in teh paypal help or manuals or on any other forums other than the paypaldev one thread, where thi smethod is used to add individual items to the cart. I dont know how he knew to use this different url.

                            anyway..... I guess item_name & item_number must be strings, because they are defined by me and can be anything (e.g. blue sweater, ref:BS1). I assume that the amount must be a number (right?) - since it s a currency amount.

                            if i have mine declared as a string, how do i change it to be a number?

                            Cheska


                            • 11. Re: Paypal add to cart button & combobox variable question
                              kglad Adobe Community Professional & MVP
                              use the Number() function to convert from a string to a number. the last time i had a project that used paypal i used

                              amount_1=Number(grandTotalF());
                              shipping_1 = 0;
                              handling_1 = 0;
                              upload = 1;

                              (all numbers). even the phone number was a number. the address and the following were strings:

                              item_name_1 = "Luckey Tech Computer Order";
                              cmd = "_cart";
                              business = "sales@ltpcs.com";
                              item_name = "LuckeyTech Computer";
                              currency_code = "USD";
                              • 12. Paypal add to cart button & combobox variable question
                                ccesca Level 1
                                hi kglad,

                                firstly thanks so much for your time.
                                secondly i will go and see if i can figure out what you mean (each new step is a total learning curve for me).

                                finally, would you mind looking here:

                                http://www.atinybitofgod.com/kids/paypal.html

                                where you can see exactly where im at now, and test my swf and see what happens....it should only take a few secons to view and tes...

                                thanks.....

                                Cheska

                                • 13. Paypal add to cart button & combobox variable question
                                  ccesca Level 1
                                  kglad,

                                  Sorry - me again. my above link is incorrect it should be http://www.atinybitofgod.com/kids/paypal.html

                                  My actual site that I'm working on is http://www.atinybitofgod.com/kids/new/index.html (right now there is no code on the add-to-cart button) . But you can see why I'd be really be frustrated at having to make single buttons for each item.

                                  I am really sad not to be able to make the variable thing work...i have posted on sooo many forums. Is' weird...the paypal forum is so out-of-date...there are not many posts from this year!

                                  of course all night in my dreams I am trying to figure out a way round this and have come up with a posisble solution - maybe you can tell me if it can work....is there a way that depending on a variable, the code attached to a button can be changed? so...if myVariable == something , then the button on the stage will grab a whole selection of code to perform on it's release....that way I can write whole individual code for the loadvars to send to paypal, where each variable is an actual value and not a reference to another variable.....i know it would be a lot of code (whole new loadvars for each item).

                                  This is a nightmare : (

                                  Thanks for the loan of your brain though : )

                                  Cheska
                                  • 14. Re: Paypal add to cart button & combobox variable question
                                    kglad Adobe Community Professional & MVP
                                    you still haven't changed those strings to numbers. and you should be using "POST" instead of "post".
                                    • 15. Paypal add to cart button & combobox variable question
                                      ccesca Level 1
                                      hi,

                                      i tried with the following code in the first frame:

                                      stop();

                                      var myVB = "hat";
                                      var myVB2 = "ref-hat";
                                      var myVB3:Number = 10.00;


                                      function setDisplays(){
                                      myVariable = myCombo.getValue();
                                      if (myVariable == "a"){
                                      myVB="hat";
                                      myVB2="ref-hat";
                                      myVB3= 10.00;
                                      } else if (myVariable == "b"){
                                      myVB="gloves";
                                      myVB2="ref-gloves";
                                      myVB3= 20.00;
                                      } else if (myVariable == "c"){
                                      myVB="carf";
                                      myVB2="ref-scarf";
                                      myVB3= 30.00;
                                      }
                                      }

                                      myCombo.addEventListener("change", setDisplays);



                                      and the following code now on my button:

                                      on (press) {
                                      paypal = new LoadVars();
                                      paypal.cmd="_cart";
                                      paypal.item_number= myVB2;
                                      paypal.item_name= mvVB;
                                      paypal.upload="1";
                                      paypal.business="info@vitaledgeaid.org";
                                      paypal.currency_code="USD";
                                      paypal.amount= myVB3;
                                      //paypal.handling ="2.00";
                                      paypal.send("https://www.paypal.com/cart/add=","_blank","POST");
                                      }



                                      still no joy : (


                                      Also...i tried leaving the amount as "10.00" in the LoadVars (i.e. didn't reference my other variable) just to see if it was the amount variable specifically that was causing the problem) and it turns out it's actually all three referenced variables....because where on the paypal cart it should have my item name & ref etc... it says 'undefined' .....so it's something to do with the way my loadvars passes the variables to flash.....

                                      It's so frustrating because other people were apparently able to get their code to work when their same three variables were collected from a database.....

                                      Did I change my variable type correctly?

                                      cheska

                                      • 16. Re: Paypal add to cart button & combobox variable question
                                        kglad Adobe Community Professional & MVP
                                        you should be using item_name_1, item_number_1, amount_1, shipping_1 for the first item. and, i no longer see a need for an add variable.

                                        http://www.paypal.com/cgi-bin/webscr?cmd=_pdn_howto_checkout_outside