Purchasing On-line

When customers have completed their software selections and are ready to purchase the products, they click the "Checkout" button to finalize their purchases.

Normally, customers are connected to an on-line credit processing company that collects credit card information, approves the purchase, and ties into the national banking system to debit and credit the appropriate bank accounts. When these transactions are completed, the customer is returned to the shopping site where confirmation of their orders is provided.

At the same time, the credit card company returns information to the site pertaining to any non-private billing information it collected from the customer. This information, then, can be used to create a permanent order record for that customer for future reference and to recreate the original order if necessary. The returned information, in effect, can be used to link with the company's accounting and inventory systems. Although we can't tie into the Federal banking system for this example application, we can closely simulate the processing with the credit card company; and, we can archive the order information even though we won't be tying directly into any other systems.

Submitting Order Information

The shopcart.php page includes this "Checkout" button within a separate form from that used to update purchase quantities. This is because the checkout form is transmitted to the credit card company whereas the update form links back to the shopcart.php page.

<?php if ($OrderTotal != 0) {?>

  <div style="width:375px; line-height:8pt">
  <form action="https://.../creditcheck.php" method="post">
    <input type="hidden" name="ReturnURL" value="https://..../ordercapture.php">
    <input type="hidden" name="CompanyID" value="Webwarehouse.com">
    <input type="hidden" name="CustomerID" value="<?php echo $_SESSION[OrderNo]?>">
    <input type="hidden" name="Amount" value="<?php echo $OrderTotal ?>">
    <input type="submit" name="CheckoutButton" class="buttonM" 
      style="float:left;margin-right:5px" value="Checkout"
      onMouseOver="OverMouse(this)"; onMouseOut="OutMouse(this)">
    <span class="small">Click to finalize on-line purchase through secure connection
    to Credit Payment Systems.</span>
    
  </form>
  </div>
  
<?php } 

For purposes of this example, the ACTION URL for the form is

http://msconline.maconstate.edu/Tutorials/php/ecommerce/creditcheck.php

This address links to the simulated credit card company, which is simply a page within the tutorial directory. It could, however, link to a real company just as easily.

A typical method used to correspond with a credit processing company is to pass information related to the current purchase within a set of hidden form fields. At minimum, the company needs to know (1) the total amount of the purchase, (2) the identification of the site submitting the information (the account ID with the credit card company), and (3) the URL of the page to which confirmation of the transaction will be returned. The sales site also needs to submit (4) a customer identification that can be returned with the confirmation. These four hidden fields appear on the form containing the "Checkout" button.

The ReturnURL field is used to provide the address to which information from the credit card company is returned to the present site. In this example, the information is returned to our ordercapture.php page at

http://msconline.maconstate.edu/Tutorials/php/ecommerce/ordercapture.php

The customer is returned from the credit card company to this intermediate page prior to arriving at the salesorder.asp page on which we present the final sales order and a confirmation message. It is on this ordercapture.asp page that we capture the information returned from the credit card company to create a sales order record and clean up the shopping cart. The customer doesn't see this page. It contains only PHP scripting to process the returned information and then automatically redirects to the salesorder.phppage for customer display. More about all of this later.

The CompanyID field contains the account identification for the site submitting the order. We're using "Webwarehouse.com" as this identification. If you are using this credit-checking URL, then you can enter any text string in this field.

The CustomerID field contains an identification for this customer. This value is returned by the credit card company so that we'll know to which customer, or to which order, the returned information pertains. Here we're using the $_SESSION[OrderNo] value to identify this customer.

The Amount field contains the total dollar amount of the order. This field is valued with the OrderTotal variable that is available on this page.

After submitting the form, we just sit back and wait. The credit card company takes over the processing. When the company has completed its processing, it automatically issues the ReturnURL address to return to our ordercapture.php page where we pick up the processing.

Credit Card Processing

When the customer is directed to the credit card company, the first form presented appears as below:

The customer fills out the credit card and billing information and clicks the "Continue Purchase" button. The form is checked to make sure the information is complete and then a confirmation page is displayed:

When the customer verifies the information by clicking the "Verify Information" button, the credit card information is checked. We'll use the following procedure: If the first four digits of the Account number is "0000," then the order is rejected; if the first four digits of the number are any other digits, then the order is accepted. Following processing, the customer sees a screen accepting or rejecting the order:

When the customer clicks the "Continue" button, a link is made back to the page identified in the submission form as the ReturnURL. This page, ordercapture.php in the example, receives the order and billing information that was collected from the customer. Its receipt and processing is discussed on the following page.