SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict Owz2004's Avatar
    Join Date
    Mar 2004
    Location
    U.K (Wales)
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question storing variables with php and transferring to paypal

    Hi,

    Im trying to allow users to pay for items using paypal.. Ive managed to store the variables (for postage, item price and total) now I want to transfer them to paypal buy pressing the submit button..

    I have posted on the pay pal developer forum my problem but I was hoping that somone may know how to or has already done something similar..

    The post is here

    Much appreciated...

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you read the documentation for thier API yet? I know there's a lot to read, but this isn't the type of thing where you should just wing it and try to make it work without a very solid understanding of what you're doing.

  3. #3
    SitePoint Addict Owz2004's Avatar
    Join Date
    Mar 2004
    Location
    U.K (Wales)
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've read alot of it. I managed to get it to work to a certain point. I have managed to to calculate the prices of the goods depending on the quanitites ordered. It then passes over to paypal with the correct break downs but, the problem I have now is I need to transfer a variable $title which holds the title of the product along with the price to paypal.

    at the moment the the generic hidden field in the form which holds the description of the item is called basedesc.

    The code for the form is as follows:

    Code PHP:
     
    <form name="wrapperbuy" action="https://www.paypal.com/cgi-bin/webscr" method="post" 
    onsubmit="this.target = 'paypal';
              SetAmt (1, 1.95, 11, 1.75, 21, 1.55, 51, 1.35, 101, 1.30, 201, 1,25);
              return ReadForm (this);">
     
    <input type="hidden" name="cmd" value="_cart" />
    <input type="hidden" name="add" value="1" />
    <input type="hidden" name="business" value="Alyson@chocbars.co.uk" />
    <input type="hidden" name="item_name" value="" />
    <input type="hidden" name="amount" value="" />
    <input type="hidden" name="currency_code" value="GBP" />
    <input type="hidden" name="lc" value="US" />
    <input type="hidden" name="shipping" value="4.95">
    <input type="hidden" name="baseamt" value="1.95" />
    <input type="hidden" name="basedes" value="Choc bars Wrappers order" />
     
    <label name="quantity">Quantity:</label>
    <input name="qty" type="text" size="5"/>
    <input type="image" src="img/addcart.gif" name="submit" alt="cart add" />
    <input type="image" src="img/viewcart.gif" alt="cart view" 
      onclick="document.forms.viewcart.target = 'paypal';
               document.forms.viewcart.submit ();
               return false;" />
     
    </form>

    the javascript which handles the values is:

    Code JavaScript:
     
    <script type="text/javascript">
     
    var ac = 0;    // table for qty/amt pairs
    var aqty = new Array ();  // qty brkpt
    var aamt = new Array ();  // amount to charge
     
    var pc = 0;    // table for qty/percent pairs
    var pqty = new Array ();  // qty brkpt
    var pper = new Array ();  // percent to discount
     
    function Dollar (val) {  // force to valid dollar amount
    var str,pos,rnd=0;
      if (val < .995) rnd = 1;  // for old Netscape browsers
      str = escape (val*1.0 + 0.005001 + rnd);  // float, round, escape
      pos = str.indexOf (".");
      if (pos > 0) str = str.substring (rnd, pos + 3);
      return str;
    }
     
    function ReadForm (wrapperbuy) { // quantity based discounts
    var i,amt,des,qty;
      amt = wrapperbuy.baseamt.value*1.0; // base amount
      des = wrapperbuy.basedes.value;     // base description
      qty = wrapperbuy.qty.value;         // get user quantity
      if (isNaN (qty) || qty < 1) { // make sure it's good
        alert ('"' + qty + '"' + ' is not a valid number!');
        ac = 0;                     // always zap the table
        pc = 0;
        return false;               // th-th-that's all, folks.
      }
      qty = qty*1.0;                // force to numeric
     
      for (i=ac-1; i>=0; i=i-1) {   // run table backwards
        if (qty >= aqty[i]) {       // use this entry
          amt = aamt[i];            // this is the real amount
          break;                    // get out, we're done
        }
      }
      for (i=pc-1; i>=0; i=i-1) {   // run table backwards
        if (qty >= pqty[i]) {       // use this entry
          amt = amt - (amt/100.0 * pper[i]);
          break;                    // get out, we're done
        }
      }
     
      wrapperbuy.item_name.value = des + ", package of " + qty + " items @" +
                             Dollar (amt) + " each.";
      wrapperbuy.amount.value = Dollar (amt * qty);
      ac = 0;  // reset item discount
      pc = 0;
    }
     
    function SetAmt (q1, a1) {  // set up a quantity-based amount table
    var i;
      ac = 0;
      for (i=0; i<arguments.length; i=i+2) {  // build the table
        aqty[ac] = arguments[i];   // get real args and store 
        aamt[ac] = arguments[i+1];
        ac = ac + 1;               // number of pairs in table
      }
    }
    </script>

    The page which holds this information is here

    the title of the product has been pulled from the database and is stored as a variable on the page already. Is there a way of transfering it into the basedesc value before it passes back across?

    Thank you

    O


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •