On This Page
Sample ASP.NET Code Using Visual Basic
The following sample files illustrate how to use the Name-Value Pair client in ASP.NET
using Visual Basic. The
web.config
file is a sample web application
configuration file containing sample entries required by the client. The other files are
simple web forms and their corresponding code-behind files. The
Checkout.aspx
file contains a pre-filled form. When you press the
Submit button, it will post the entered data to Checkout2.aspx
, which will
send the transaction to Cybersource
.Listing 1: web.config
<?xml version="1.0"?> <configuration> <appSettings> <add key="cybs.merchantID" value="your_merchant_id"/> <add key="cybs.keysDirectory" value="c:\keys"/> <add key="cybs.sendToProduction" value="false"/> <!-- Logging should normally be disabled in production as it would --> <!-- slow down the processing. Enable it only when troubleshooting --> <!-- an issue. --> <add key="cybs.enableLog" value="false"/> <add key="cybs.logDirectory" value="C:\Program Files\CyberSource Corporation\simapi-net-2.0-5.0.0\logs"/> <!-- Please refer to the Connection Limit section in the README for --> <!-- details on this setting and alternate ways to set the --> <!-- connection limit. When not specified or is set to -1, the --> <!-- client will implicitly use the connection limit currently in --> <!-- force, which would be 2 if none of the alternate methods are --> <!-- used. --> <add key="cybs.connectionLimit" value="-1"/> </appSettings> </configuration>
Listing 2: Checkout.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Checkout.aspx.vb" Inherits="NVP" Debug="true"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Name Value Pair - Order Page</title> </head> <body> <form action="Checkout2.aspx" method="post"> Please confirm the information below and click the Submit button to perform the authorization. <br/> <h3>Billing Information</h3> First Name:<br/> <input type="text" name="billTo_firstName" value="John"/> <br/>Last Name:<br/> <input type="text" name="billTo_lastname" value="Doe"/> <br/>Street Address:<br/> <input type="text" name="billTo_street1" value="1295 Charleston Road"/> <br/>City:<br/> <input type="text" name="billTo_city" value="Mountain View"/> <br/>State:<br/> <input type="text" name="billTo_state" value="CA"/> <br/>Postal Code:<br/> <input type="text" name="billTo_postalCode" value="94043"/> <br/>Country:<br/> <input type="text" name="billTo_country" value="US"/> <br/> <h3>Credit Card Information</h3> Amount:<br/> <input type="text" name="item_0_unitPrice" value="10.00"/> <br/>Credit Card Number:<br/> <input type="text" name="card_accountNumber" value="4111111111111111"/> <br/>Expiration month (mm):<br/> <input type="text" name="card_expirationMonth" value="12"/> <br/>Expiration year (yyyy):<br/> <input type="text" name="card_expirationYear" value="2010"/> <br/>Email Address:<br/> <input type="text" name="billTo_email" value="[email protected]"/> <br/><input type="submit" value="Submit"/> </form> </body> </html>
Listing 3: Checkout.aspx.vb
Partial Class NVP Inherits System.Web.UI.Page End Class
Listing 4: Checkout2.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Checkout2.aspx.vb" Inherits="NVP2" Debug="true"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Name Value Pair - Receipt</title> </head> <body> <form id="form1" runat="server"> <div> </div> </form> </body> </html>
Listing 5: Checkout2.aspx.vb
Imports CyberSource.Clients.NVPClient Partial Class NVP2 Inherits System.Web.UI.Page Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Declare the request hashtable Dim oRequest As New Hashtable 'Add non-user input fields oRequest.Add("ccAuthService_run", "true") oRequest.Add("merchantReferenceCode", "MRC-5254555") 'Add user input fields from post oRequest.Add("billTo_firstName", Request.Form("billTo_firstName")) oRequest.Add("billTo_lastName", Request.Form("billTo_lastName")) oRequest.Add("billTo_street1", Request.Form("billTo_street1")) oRequest.Add("billTo_city", Request.Form("billTo_city")) oRequest.Add("billTo_state", Request.Form("billTo_state")) oRequest.Add("billTo_postalCode", Request.Form("billTo_postalCode")) oRequest.Add("billTo_country", Request.Form("billTo_country")) oRequest.Add("billTo_email", Request.Form("billTo_email")) oRequest.Add("card_accountNumber", Request.Form("card_accountNumber")) oRequest.Add("card_expirationMonth", Request.Form("card_expirationMonth")) oRequest.Add("card_expirationYear", Request.Form("card_expirationYear")) oRequest.Add("item_0_unitPrice", Request.Form("item_0_unitPrice")) oRequest.Add("purchaseTotals_currency", "USD") 'Declare the reply hashtable Dim varReply As New Hashtable 'Run the transaction varReply = CyberSource.Clients.NVPClient.RunTransaction(oRequest) 'Print reply data to the browser Response.Write("reasonCode: " & varReply("reasonCode").ToString) Response.Write("<BR>Decision: " & varReply("decision").ToString) Response.Write("<BR>RequestID: " & varReply("requestID").ToString) Response.Write("<BR>Merchant Reference Code: " & varReply("merchantReferenceCode").ToString) End Sub End Class