Teach Yourself E-Commerce Programming with ASP in 21 Days phần 5 ppsx

62 243 0
Teach Yourself E-Commerce Programming with ASP in 21 Days phần 5 ppsx

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

188 <td> 189 <a href=”processOrders.asp?showpage=<%=showPage%>& ➥ oid=<%=RS( “order_id” )%>&os=2&showOrders=<%=showOrders%>”> 190 Not in Stock</a> 191 </td> 192 <% END IF %> 193 <% IF RS( “order_status” ) = 3 THEN %> 194 <td bgcolor=”lightblue”> 195 <b>Shipped</b> 196 </td> 197 <% ELSE %> 198 <td> 199 <a href=”processOrders.asp?showpage=<%=showPage%>& ➥ oid=<%=RS( “order_id” )%>&os=3&showOrders=<%=showOrders%>”> 200 Shipped</a> 201 </td> 202 <% END IF %> 203 </tr> 204 </table> 205 </tr> 206 </table> 207 <% 208 RS.MoveNext 209 WEND 210 %> 211 <hr> 212 <% IF RS.PageCount > 1 THEN %> 213 Page: 214 <% 215 FOR i = 1 TO RS.PageCount 216 IF cINT( showPage ) = i THEN 217 %> 218 <b><%=i%></b> | 219 <% ELSE %> 220 <a href=”processOrders.asp?showpage=<%=i%>& ➥ showorders=<%=showOrders%>”> 221 <%=i%> 222 </a> | 223 <% 224 END IF 225 NEXT 226 IF allPages <> “” THEN 227 %> 228 <b>All</b> 229 <% ELSE %> 230 <a href=”processOrders.asp?showorders=<%=showOrders%>& ➥ allPages=1”> 231 All 232 Day 10 LISTING 10.8 continued 14 0672318989 ch10 3/30/00 8:18 AM Page 232 Checking Out 233 10 232 </a> 233 <% 234 END IF 235 END IF 236 %> 237 238 </body> 239 </html> The first line in processOrders.asp includes the adovbs.inc file. You must include this file because the processOrders.asp page makes use of the ADO constant adOpenStatic. In lines 3–8, all the form and URL variables are retrieved. These variables represent such things as the current page, the ID of the order being updated, and the new order status. Lines 10–16 assign default values to variables that don’t have a value. For example, if no page of orders has been selected, the page defaults to the first page. In lines 18–20, a connection to the Microsoft Access database is opened. The System DSN named “accessDSN” is used to open the connection. Lines 22–37 are used to update the status of a particular order. This is accomplished with a SQL UPDATE statement. The UPDATE statement changes the value of the order_status column for the database record with a certain order ID. When an order’s status is changed to shipped, the order_shipdate column is also updat- ed to reflect the current date. Otherwise, if any other status is selected, the order_ship- date column is assigned the value NULL. In lines 40–61, the order information is retrieved from the database. The information is drawn from three tables: the Orders table, the Products table, and the Users table. A SQL ORDER BY clause is used to retrieve the last orders placed first. Line 46 is used to restrict the orders retrieved. For example, you can use the HTML pick list to view only shipped orders. Line 46 adds a clause to the SQL SELECT statement that retrieves only the orders with a certain order status. This statement is skipped if the All Orders option is selected. The PageSize and AbsolutePage properties of the Recordset object are used to display only a certain page of orders at a time. The PageSize property sets the number of records to show on a single page. The AbsolutePage property sets the page to display. The HTML pick list is created in lines 74–95. This pick list enables you to view only those orders with a certain status (for example, shipped) or all orders. ANALYSIS 14 0672318989 ch10 3/30/00 8:18 AM Page 233 The bulk of processOrders.asp, lines 97–210, are used to display the details of a partic- ular order. A WHILE WEND loop is used to loop through all the orders for a certain page. The information for each order is formatted and displayed. An HTML table is displayed in lines 160–204. This table contains a list of possible order status values in each of the table cells. The current status of an order is highlighted with a blue background. Finally, in lines 212–236, a list of page numbers is displayed. By clicking on any one of these page numbers, you can navigate to a particular page of orders. The list of page numbers is created with a FOR NEXT loop. The PageCount property of the Recordset object is used to retrieve the number of pages. Summary In today’s lesson, you learned how to work with transactions. You learned how to create both transactional Active Server Pages and ADO transactions. You learned how to use a transaction to guarantee that a series of steps either succeeds or fails as a whole. Next, you learned how to create a checkout page for the shopping cart. You learned how to update a customer’s address and payment information. You also learned how to trans- fer a customer’s shopping cart to the Orders table. Finally, you learned how to process completed orders. You learned how to create a page that enables you to view and update the status of customer orders. Q&A Q ADO transactions seem really great. When shouldn’t I use them? A You should avoid using transactions whenever possible. You must be particularly careful with using transactions when you have a large number of concurrent users. Long running transactions can lock up the records in your database, preventing other users from accessing the records. Q When attempting to use the @TRANSACTION directive, I receive the following error: error ‘ASP 0216’ MSDTC Service not running /tran.asp Transactional web pages cannot be run if the MSDTC service is not running. A ASP transactions rely on the Microsoft Distributed Transaction Coordinator. The Microsoft Distributed Transaction Coordinator is included with both Microsoft 234 Day 10 14 0672318989 ch10 3/30/00 8:18 AM Page 234 Checking Out 235 10 Transaction Server and Microsoft SQL Server. On both Windows 98 and Windows NT computers, the MSDTC service should start automatically when you start your computer. You can manually start MSDTC on either a Windows 98 or Windows NT computer by using the Microsoft Transaction Server Explorer. Launch this program, select the name of your computer, and then choose Action, Start MS DTC. If you have SQL Server installed, you can also enable the Microsoft Distributed Transaction Coordinator from either the SQL Server Service Manager or the MSDTC Administrative Console. (Both programs are located in the SQL Server program group.) Workshop The Quiz and Exercise questions are designed to test your knowledge of the material covered in this chapter. The answers are in Appendix A, “Quiz Answers.” Quiz 1. What’s wrong with the following script? <% Set Con = Server.CreateObject( “ADODB.Connection” ) Con.Open “accessDSN” SET RS = Server.CreateObject( “ADODB.Recordset” ) RS.ActiveConnection = Con RS.BeginTrans RS.Open “select * FROM Orders” RS.CommitTrans %> 2. Suppose that you want to copy a particular row from the Orders table to a second table named Orders_bak. The Orders_bak table is used to back up the data in the Orders table. How can you copy the row from the Orders table in which the value of the order_id column is 17 to the Orders_bak table? Exercise The processOrders.asp page discussed in today’s lesson enables you to assign one of four status values to an order: Pending, Credit Card Declined, Not in Stock, or Shipped. How would you modify the processOrders.asp page (contained in Listing 10.8) to enable a fifth status value, Back Ordered, to be selected? 14 0672318989 ch10 3/30/00 8:18 AM Page 235 14 0672318989 ch10 3/30/00 8:18 AM Page 236 DAY 11 WEEK 2 Working with Credit Cards In today’s lesson, you’ll learn how to implement the most important function for your online store: how to process customer credit cards. The lesson begins with a brief overview of the different options available for credit card process- ing. Next, you’ll be provided with detailed information on implementing one credit card processing system: CyberCash. In today’s lesson, you’ll learn the following: • How to set up and configure CyberCash • How to use CyberCash to authorize credit cards transactions • How to use CyberCash to settle credit card transactions Methods of Processing Credit Cards There is a wide variety of options for processing the credit cards accepted at your Web site, too many to be discussed in a single chapter. However, the vari- ous credit card processing systems can be somewhat arbitrarily divided into 15 0672318989 ch11 3/29/00 4:01 PM Page 237 three different types: offsite payment processors, payment terminals, and component- based solutions. Offsite Payment Processors Severalcompanies enable you to link to their Web sites and they will process the credit card transactions for you. They host the payment page that prompts the customer to enter credit card information. After the customer has completed the payment transaction, the customer is sent back to your Web site. The advantage of this type of system is that it is very easy to set up. You don’t need to configure and use the Secure Sockets Layer, and you don’t need to take special precau- tions to maintain the privacy of the customer’s credit card information. All this is done for you at another Web site. The disadvantage of these offsite payment processors is that you lose some control over the appearance of your payment page. You also never collect credit card information directly from your customers. Finally, if something goes wrong with the offsite payment processor—for example, its Web site goes down—the problem is out of your hands and you can do nothing about it. One example of a company that offers offsite payment processing is Authorize.Net ( www.authorizenet.com). To use the Authorize.Net WebLink service, you include the following HTML form in your ASP page: <form method=”POST” action=”https://secure.authorize.net/gateway/transact.dll”> <input type=”hidden” name=”x_Version” value=”3.0”> <input type=”hidden” name=”x_Login” value=”your login here”> <input type=”hidden” name=”x_Amount” value=”total amount here”> <input type=”hidden” name=”x_Show_Form” value=”Payment_Form”> <input type=”hidden” name=”x_Invoice_Num” value=”your invoice number here”> <input type=”hidden” name=”x_Description” value=”order description here”> <input type=”hidden” name=”x_Cust_ID” value=”customer id here”> <input type=”submit” value=”Click Here for Secure Payment Form”> </form> This HTML form creates a button labeled Click Here for Secure Payment Form that links to the Authorize.Net Web site. You can substitute variables for the value attributes of the HTML form to enable customers to purchase different products. For example, the value of the x_Amount field is the amount that you want to charge the customer’s credit card. Another company that offers offsite payment processing is iBill. Currently, iBill offers a service called the Resellers Subscription Sales service. This service cannot be used to sell tangible goods. You can use this service only to sell Web site subscriptions and 238 Day 11 15 0672318989 ch11 3/29/00 4:01 PM Page 238 Working with Credit Cards 239 11 informational content. The iBill service is worth mentioning, however, because it is the only payment system discussed in this chapter that does not require you to have a credit card merchant account. The only requirement to use this service is that you have a credit card. Payment Terminal Solutions A different approach to processing credit cards is represented by payment terminal solu- tions. A prime example of this type of software is ICVerify (www.icverify.com). ICVerify is a software product that contains an easy-to-use interface for authorizing and settling credit card transactions. You can launch the program, type in a customer’s credit card information, click a button, and the program authorizes a credit card transaction. ICVerify does not work over the Internet. You must use this program with a modem. When you authorize or settle a credit card transaction, the program connects to your processor over the phone line and completes the transaction. Although it is possible to use ICVerify to perform real-time credit card authorizations, I do not recommend doing this. ICVerify is better suited for processing credit card transac- tions in batches. For example, you can manually run ICVerify once a night and run all the credit card transactions for that day in a single batch. ICVerify allows you to import CSV files (comma-separated value files). So, to process the credit cards from your online store, you would need to export the credit card transac- tions from your database to a flat file in CSV format. You can generate CSV files from SQL Server by using the Data Transformation Services (DTS). With Microsoft Access, you can use the Microsoft Access Export option to convert a database table to a delimit- ed text file. The main advantage of using ICVerify is that it is one of the cheapest solutions for pro- cessing credit cards. Because ICVerify uses normal phone lines and not the Internet, the banks do not need to configure special gateways to accept credit card transactions per- formed with ICVerify. The end result is that banks typically charge you much lower fees. Component-Based Solutions The third and final method of processing credit cards is to use a component-based solu- tion. This approach provides you with the greatest flexibility over processing credit cards. You can write Active Server Pages scripts to do such things as authorize, capture, and refund credit card transactions. Two examples of this approach are CyberCash ( www.cybercash.com) and VeriFone’s vPos software (www.verifone.com). We’ll discuss CyberCash in detail for the remainder of this chapter. 15 0672318989 ch11 3/29/00 4:01 PM Page 239 The advantage of a component-based solution to payment processing is that it gives you complete control over credit card transactions from your Active Server Pages scripts. Unlike offsite payment solutions, the customer never needs to leave your Web site. Unlike terminal-based solutions, the credit card transactions can be processed in real- time over the Internet. Component-based solutions have two main disadvantages. First, they are typically more expensive than terminal solutions because they require the bank to set up a custom Internet gateway. Second, setting up a component-based solution requires you to write custom scripts. Writing the scripts can be time-consuming. Choosing a Method of Processing Credit Cards So, you might ask, what is the best method of processing credit cards? Which of the credit card processing systems discussed should I implement at my Web site? If you want a quick and easy method of processing credit cards from your Web site, I recommend using an offsite payment processing method such as Authorize.Net ( www.authorizenet.com). If you want to implement the method with the lowest fees, seriously consider using ICVerify (www.icverify.com). Finally, if you want the greatest flexibility, CyberCash might be the best solution (www.cybercash.com). To make it easier to research the various options for processing credit cards, here is a list of some of the more popular solutions: • Authorize.Net ( www.authorizenet.com) • CyberCash ( www.cybercash.com) • CyberSource ( www.cybersource.com) • iBill ( www.ibill.com) • ICVerify ( www.icverify.com) • OpenMarket ( www.openmarket.com) • Signio ( www.signio.com) Preparing for CyberCash In this section, you’ll learn how to complete the three requirements for using CyberCash. You ’ll learn how to open a credit card merchant account. You will also learn how to reg- ister as a merchant at the CyberCash Web site. Finally, you’ll learn how to download and install the necessary software for communicating with CyberCash. 240 Day 11 15 0672318989 ch11 3/29/00 4:01 PM Page 240 Working with Credit Cards 241 11 Opening a Credit Card Merchant Account Before you can use a credit card processing system such as CyberCash, you must open a credit card merchant account with an acquiring financial institution. Typically, your acquiring financial institution will be a bank such as Wells Fargo, Bank of America, or BankBoston. Your acquiring financial institution works with a third-party processor to process credit card transactions and deposit money into your merchant account. Before opening a credit card merchant account, you need to check whether the bank sup- ports CyberCash because not all banks support it. Most banks select and promote only a handful of credit card processing systems. When choosing a bank to act as your acquiring financial institution, don’t be afraid to comparison shop. Banks might charge any of the following fees: • Application fee—This is a fee that a bank charges you just for applying for a mer- chant account. Not all banks charge this fee, so you should avoid it if possible. • Setup fee—This is a one-time fee that a bank charges you for opening a new mer- chant account. Again, not all banks charge this fee, so try to avoid it. • Transaction fee—Almost all banks charge you a transaction fee. The transaction fee is the amount the bank charges you every time you process a credit card. Transaction fees can range anywhere from 10 cents to 50 cents a transaction. • Monthly minimum fee—Some banks, but not all, charge you a monthly minimum fee. If your sales do not meet a certain threshold, you are charged this fee. • A discount rate—Most banks retain a percentage of each transaction. This percent- age is called the discount rate. Discount rates typically fall in the range of 2.00% to 3.00% per transaction. When researching the fees a bank charges, it is important to separate the bank’s fees from the fees charged by CyberCash. CyberCash charges additional setup, transaction, and monthly fees over and above the bank’s fees. Depending on your credit history, opening a credit card merchant account can be very easy, difficult and time-consuming, or impossible. If you already have an established Unless you plan to use a wallet (see Day 20, “Working with Wallets”), you must install a server certificate and enable the Secure Sockets Layer (SSL) before you can use the CyberCash service. You must use SSL to protect the privacy of customer credit card information when the information is entered at your Web site. For more information on configuring SSL, see Day 8, “Building the Transaction Databases.” Note 15 0672318989 ch11 3/29/00 4:01 PM Page 241 [...]... ZIP: Customer Country: 11 continues 252 Day 11 LISTING 11.3 49 50 51 52 53 54 55 56 57 58 59 60 continued FIGURE 11.4 Submitting an authorization... form in Listing 11.3 is submitted, the authorize() function is called in processCards2 .asp The processCards2 .asp page simply shows the result of the transaction (see Figure 11 .5) The complete code for processCards2 .asp is included in Listing 11.4 (processCards2 .asp is also included on the CD-ROM that accompanies this book.) Working with Credit Cards INPUT LISTING 11.4 253 processCards2 .asp 1 Letting Customers Track Their Orders 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 263 ... component with the Personal Web Server running on Windows 95 or Windows 98, you’ll need to execute the script named win9x.bat Otherwise, if you are using the component with Internet Information Server running on Windows NT or Windows 2000, execute the script named winNT.bat If everything goes smoothly, a dialog box should pop up reporting that the DLLs were successfully installed iisCARTship Properties and... be integrated into the online store discussed in previous lessons The first thing we need to do is to convert the script in Listing 11.1 into a function By making the script into a function, we can pass different values for the credit card number and purchase price Listing 11.2 contains the modified script (The authorizeFunction .asp script is included on the CD-ROM that accompanies this book.) INPUT... company in real-time We’ll begin by discussing the procedure for installing the component Next, you’ll be provided with an overview of the component’s methods and properties Finally, we’ll build an ASP page that demonstrates how you can use this component in a real-world application Letting Customers Track Their Orders 2 65 Installing the iisCARTship Component The iisCARTship component isn’t included with. .. is named processCards .asp on the CD-ROM that accompanies this book.) By completing the form fields and clicking Authorize, you can authorize a credit card transaction (see Figure 11.4) Working with Credit Cards INPUT 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 LISTING 11.3 251 processCards .asp Process... item.cShipTime & “” 15 NEXT 16 %> Calling the ShipCalc() method returns a collection named ShipInfo that contains the shipping rates In the previous script, a VBScript FOR EACH loop is used to loop through each item of the ShipInfo collection and display its properties All the interesting information is contained in the ShipInfo collection Each item in this collection has the following properties: • cError—Service... table Line 46 displays an order’s status This is accomplished with the showOrderStatus() function This function is defined in the storefuncs .asp file Listing 12.3 contains the showOrderStatus() function INPUT 1 2 3 4 5 LISTING 12.3 Showing an Order’s Status FUNCTION showOrderStatus( theStatus, theShipDate ) SELECT CASE theStatus CASE 0 showOrderStatus = “Pending” CASE 1 continues 12 264 Day 12 LISTING... showorders .asp page retrieves all the rows for a customer from the database table named Orders The list of orders is retrieved in lines 2–9 In lines 3–7, the SQL string is constructed In line 9, the SQL string is executed and the records are retrieved into a Recordset named RS ANALYSIS The remainder of the script loops through each record in the Recordset Each field of the Recordset is displayed within an . </table> 2 05 </tr> 206 </table> 207 <% 208 RS.MoveNext 209 WEND 210 %> 211 <hr> 212 <% IF RS.PageCount > 1 THEN %> 213 Page: 214 <% 2 15 FOR i = 1 TO RS.PageCount 216 . </html> The first line in processOrders .asp includes the adovbs.inc file. You must include this file because the processOrders .asp page makes use of the ADO constant adOpenStatic. In lines 3–8, all. displayed in lines 160–204. This table contains a list of possible order status values in each of the table cells. The current status of an order is highlighted with a blue background. Finally, in lines

Ngày đăng: 13/08/2014, 08:21

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan