We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21671
    • 244 Posts
    I have a bike reservation page available at: http://www.youngsbicycleshop.com/index.php?q=181

    Via ditto, it populates the list of items available for rent. Each ditto chunk is a separate form where the user can choose qty of bikes and timeframe to rent them. When the click ’add to cart’ they are taken to Paypal’s shopping cart (website payments standard) where they can adjust quantities of items, proceed to checkout, or continue shopping.
    This was easy to implement, but leaves a lot to be desired from a usability perspective.

    How can I consolidate the 15 forms into one form and make it so that:

    • when the user clicks ’add to cart’ it only submits the items that have been chosen. I have figured out how to make it into one form, but it submits fields that were not selected and throws errors in payapal’s checkout system
    • have an addition contact us section that prepopulates the paypal payment section in their checkout
    • when the user makes a payment with paypal, it returns to a page on my site that shows the user all the details of the order
    • the order details are emailed to me
    • the order details are stored in a db

    I understand how to take a reservation, we currently have one available at http://www.youngsbicycleshop.com/index.php?q=bike-reservations.html which does everything out of my wishlist above, except for taking money from the user via paypal.
    I really appreciate any help you could provide.

    Has anyone done this before? I am hoping to learn how to do this inside modx not in foxycart or treasurechest as I don’t want to use a shopping cart solution., and because I like Paypal’s order management capabilities.

    Many Thanks in advance,

    Noah
      • 21671
      • 244 Posts
      Okay all,

      I have figured out how to prepopulate the checkout page by having a contact page at http://www.youngsbicycleshop.com/index.php?q=187powered by eform with a snippet call of:
      [!eForm? &formid=`bikeForm` &subject=`[+subject+]` &to=`[email protected]` &ccsender=`1` &tpl=`prepaidContact` &report=`ContactFormReport` &invalidClass=`invalidValue` &requiredClass=`requiredValue` &cssStyle=`ContactStyles` &gotoid=`181`  !]
      [[multiFormFunctions]]  


      the form’s code is:

       <form method="post" action="[~181~]" id="bikeForm" name="bikeForm">
      
      		
      <input type="hidden"  name="subject" value="Bike Reservation" id="cfRegarding" eform="Form Subject::1" value="Bike Reservation"> 
      		<input name="formid" type="hidden" value="bikeForm" />
      <fieldset>
      <input type="hidden" name="formStep" value="1" />
      <legend>Contact Information <strong>all fields are required</strong> </legend>
      		<p><label for="first_name">Your first name:
      		<input name="first_name" id="first_name"  class="text" type="text" eform="Your Name::1:" /> </label></p>
      		
      		<p><label for="last_name">Your last name:
      		<input name="last_name" id="last_name"  class="text" type="text" eform="Your Name::1:" /> </label></p>
      
      		<p><label for="address1">Your Home Street Address:
      		<input name="address1" id="address1"  class="text" type="text" eform="Your Home Street Address::1:" /> </label></p>
      		
      		<p><label for="city">City:
      		<input name="city" id="city"  class="text" type="text" eform="Your Home City::1:" /> </label></p>
      		
      		<p><label for="state">State:
      		<input name="state" id="state" class="text" type="text" eform="state::1:" /> </label></p>
      		
      		<p><label for="zip">Zip:
      		<input name="zip" id="zip" class="text" type="text" eform="zip::1:" /> </label></p>
      		
      		<p><label for="country">Country:
      		<input name="country" id="country" class="text" type="text" eform="country::1:" /> </label></p>
      		
      		<p><label for="islandAddress">Your Island Address:
      		<input name="islandAddress" id="islandAddress" class="text" type="text" eform="Your Island Address::1:" /> </label></p>
      		
      		<p><label for="email">Your Email Address:
      		<input name="email" id="email" class="text" type="text" eform="Email Address:email:1" /> </label></p>
      		
      		<p><label for="homePhone">Home Phone:
      		<input name="homePhone" id="homePhone" class="text" type="text" eform="Home Phone:1" /> </label>   
      		<label for="cellPhone">Cell Phone:
      		<input name="cellPhone" id="cellPhone" class="text" type="text" eform="Cell Phone:1" /> </label>
      </fieldset>
      <fieldset><legend>Rental info <strong>all fields are required</strong></legend>
      <p><label for="cfpickup">Start Date and Time <strong>You'll choose the length of rental on the next step.</strong></label>
      <select id="startMonth" onkeypress="return handleEnter(this, event)" name="startMonth" size="1"  eform="startMonth:date:1"
      <option selected="65535">Month</option> 
      <option value="">Month</option>
      <option value="03">March</option> 
      <option value="04">April</option> 
      <option value="05">May</option> 
      <option value="06">June</option> 
      <option value="07">July</option> 
      <option value="08">August</option> 
      <option value="09">September</option> 
      <option value="10">October</option> 
      <option value="11">November</option> 
      <option value="12">December</option></select> 
      
      
      <select id="startDay" onkeypress="return handleEnter(this, event)" name="startDay" size="1"> <option selected="65535">day</option> 
      
      <option value="01">01</option> 
      <option value="02">02</option> 
      <option value="03">03</option> 
      <option value="04">04</option> 
      <option value="05">05</option> 
      <option value="06">06</option> 
      <option value="07">07</option> 
      <option value="08">08</option> 
      <option value="09">09</option> 
      <option value="10">10</option> 
      <option value="11">11</option> 
      <option value="12">12</option> 
      <option value="13">13</option> 
      <option value="14">14</option> 
      <option value="15">15</option> 
      <option value="16">16</option> 
      <option value="17">17</option> 
      <option value="18">18</option> 
      <option value="19">19</option> 
      <option value="20">20</option> 
      <option value="21">21</option> 
      <option value="22">22</option> 
      <option value="23">23</option> 
      <option value="24">24</option> 
      <option value="25">25</option> 
      <option value="26">26</option> 
      <option value="27">27</option> 
      <option value="28">28</option> 
      <option value="29">29</option> 
      <option value="30">30</option> 
      <option value="31">31</option></select>
      
      
      		<select name="startTime" id="startTime" onkeypress="return handleEnter(this, event)" size="1" eform="startTime::1:" /> 
      <option value="">time</option> <option value="9-10">9:00-10:00 AM</option> 
      <option value="10-11">10:00-11:00 AM</option> 
      <option value="11-12">11:00-NOON</option> 
      <option value="12-1">12:00-1:00 PM</option> 
      <option value="1-2">1:00-2:00 PM</option> 
      <option value="2-3">2:00-3:00 PM</option> 
      <option value="3-4">3:00-4:00 PM</option> 
      <option value="4-5">4:00-5:00 PM</option> 
      </select></p>
      
      </fieldset>
      
      <fieldset>
      <legend>Delivery</legend>
       <p><label for="Name">I need my bicycles delivered / Picked up.  
      		<input name="delivery" id="delivery"  value="Yes" type="checkbox" /> </label></p>
      <p>I also understand that there might be fees associated with having my bicycles picked up and or dropped off.  I also understand that I need to be present in order to receive the bikes at the time of rental and that Young's Bicycle Shop will not deliver the bikes unless I'm there.</p>
      <p><label> </label><input type="submit" name="contact" id="cfContact" class="button" value="Continue to bike choices" /></p>
      
      
      </fieldset>
      </form> 


      http://www.youngsbicycleshop.com/index.php?q=181. When the user goes there, they add bikes to the cart. When they go to checkout, their checkout form is prepoluted already. After the payment is taken, the user is returned to http://www.youngsbicycleshop.com/index.php?q=188 where the user sees the standard thank you message that paypal says you should have on the return page.

      I need a bit of help though. I took their sample script and pasted it into a snippet called paypalReturn as follows:
        
      <?php
      // read the post from PayPal system and add 'cmd'
      $req = 'cmd=_notify-synch';
      
      $tx_token = $_GET['tx'];
      $auth_token = "62nLcAT8G0Sd8sx7pzxxxxxxxxxxxxxxxxxxxxxxx";
      $req .= "&tx=$tx_token&at=$auth_token";
      
      // post back to PayPal system to validate
      $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
      $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
      $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
      $fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);
      // If possible, securely post back to paypal using HTTPS
      // Your PHP server will need to be SSL enabled
      // $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
      
      if (!$fp) {
      // HTTP ERROR
      } else {
      fputs ($fp, $header . $req);
      // read the body data
      $res = '';
      $headerdone = false;
      while (!feof($fp)) {
      $line = fgets ($fp, 1024);
      if (strcmp($line, "\r\n") == 0) {
      // read the header
      $headerdone = true;
      }
      else if ($headerdone)
      {
      // header has been read. now read the contents
      $res .= $line;
      }
      }
      
      // parse the data
      $lines = explode("\n", $res);
      $keyarray = array();
      if (strcmp ($lines[0], "SUCCESS") == 0) {
      for ($i=1; $i<count($lines);$i++){
      list($key,$val) = explode("=", $lines[$i]);
      $keyarray[urldecode($key)] = urldecode($val);
      }
      // check the payment_status is Completed
      // check that txn_id has not been previously processed
      // check that receiver_email is your Primary PayPal email
      // check that payment_amount/payment_currency are correct
      // process payment
      $firstname = $keyarray['first_name'];
      $lastname = $keyarray['last_name'];
      $itemname = $keyarray['item_name'];
      $amount = $keyarray['payment_gross'];
      
      return ("<p><h3>Thank you for your purchase!</h3></p>");
      
      return ("<b>Payment Details</b><br>\n");
      return ("<li>Name: $firstname $lastname</li>\n");
      return ("<li>Item: $itemname</li>\n");
      return ("<li>Amount: $amount</li>\n");
      return ("");
      }
      else if (strcmp ($lines[0], "FAIL") == 0) {
      // log for manual investigation
      }
      
      }
      
      fclose ($fp);
      
      
      
      <p>Your transaction has been completed, and a receipt for your purchase has been emailed to you.<br> You may log into your account at <a href='https://www.paypal.com'>www.paypal.com</a> to view details of this transaction.<br></p>
      ?>
      

      which is called on the return page with this snippet call
      [[paypalReturn]]


      The user does in fact get redirected to the page but they don’t see any of the order details. Can you see what I’m doing wrong?

      The next step after that is to figure out how to get all the information stored in a db, but that is for another day. . .