In this tutorial, I will show you how to Authorized.Net and PayPal Express Gateway. Now write the following code:

Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 
 
<!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></title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div align="center"> 
      <table style="border: 1px solid black; vertical-align: middle;" id="table3">       
        <tr><td colspan="2" align="center"> 
            <asp:ValidationSummary ID="ValidationSummary1" ShowSummary="false" ShowMessageBox="true" ValidationGroup="fldGrp1" runat="server" /> 
        </td></tr> 
        <tr> 
            <td align="right"> 
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="ddlPaymentMethod" InitialValue="SELECT" ValidationGroup="fldGrp1" runat="server" ErrorMessage="Method is required"> * </asp:RequiredFieldValidator>Method:</td> 
            <td align="left"><asp:DropDownList ID="ddlPaymentMethod" onselectedindexchanged="ddlPyamentMethod_SelectedIndexChanged" AutoPostBack="true" runat="server"> 
                <asp:ListItem>SELECT</asp:ListItem> 
                <asp:ListItem>American Express</asp:ListItem> 
                <asp:ListItem>Discover</asp:ListItem> 
                <asp:ListItem>Master</asp:ListItem> 
                <asp:ListItem>Visa</asp:ListItem> 
                <asp:ListItem>Paypal</asp:ListItem> 
            </asp:DropDownList></td> 
        </tr> 
        <tr> 
            <td align="right"> 
                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" ControlToValidate="txtNameOnCard" ValidationGroup="fldGrp1" runat="server" ErrorMessage="Name on card is required"> * </asp:RequiredFieldValidator>Name of the card:</td> 
            <td align="left"><asp:TextBox ID="txtNameOnCard" Width="250px" runat="server"></asp:TextBox></td> 
        </tr> 
        <tr> 
            <td align="right"> 
                <asp:RequiredFieldValidator ID="RequiredFieldValidator3" ControlToValidate="txtCreditCardNumber" ValidationGroup="fldGrp1" runat="server" ErrorMessage="Credit card number is required"> * </asp:RequiredFieldValidator>Credit card number:</td> 
            <td align="left"><asp:TextBox ID="txtCreditCardNumber" Width="250px" MaxLength="20" runat="server"></asp:TextBox></td> 
        </tr> 
        <tr> 
            <td align="right"><asp:RequiredFieldValidator ID="RequiredFieldValidator4" ControlToValidate="ddlExpMonth" InitialValue="0" ValidationGroup="fldGrp1" runat="server" ErrorMessage="Expiration month is required"> * </asp:RequiredFieldValidator>Expiration month:</td> 
            <td align="left"> 
                <asp:DropDownList ID="ddlExpMonth" runat="server"> 
                    <asp:ListItem Value="0">SELECT</asp:ListItem> 
                    <asp:ListItem Value="1">January</asp:ListItem> 
                    <asp:ListItem Value="2">February</asp:ListItem> 
                    <asp:ListItem Value="3">March</asp:ListItem> 
                    <asp:ListItem Value="4">April</asp:ListItem> 
                    <asp:ListItem Value="5">May</asp:ListItem> 
                    <asp:ListItem Value="6">June</asp:ListItem> 
                    <asp:ListItem Value="7">July</asp:ListItem> 
                    <asp:ListItem Value="8">August</asp:ListItem> 
                    <asp:ListItem Value="9">September</asp:ListItem> 
                    <asp:ListItem Value="10">October</asp:ListItem> 
                    <asp:ListItem Value="11">November</asp:ListItem> 
                    <asp:ListItem Value="12">December</asp:ListItem> 
                </asp:DropDownList> /<asp:RequiredFieldValidator ID="RequiredFieldValidator5" ControlToValidate="ddlExpYear" InitialValue="0" ValidationGroup="fldGrp1" runat="server" ErrorMessage="Expiration year is required"> * </asp:RequiredFieldValidator> 
                <asp:DropDownList ID="ddlExpYear" runat="server"></asp:DropDownList> 
            </td> 
        </tr> 
        <tr> 
            <td align="right"> 
                <asp:RequiredFieldValidator ID="RequiredFieldValidator6" ControlToValidate="txtSecurityCode" ValidationGroup="fldGrp1" runat="server" ErrorMessage="Security code is required"> * </asp:RequiredFieldValidator>Security Code:</td> 
            <td align="left"><asp:TextBox ID="txtSecurityCode" Width="60px" MaxLength="5" runat="server"></asp:TextBox></td> 
        </tr> 
        <tr><td colspan="2" align="center"><asp:Label ID="lblGatewayMessage" Font-Bold="true" runat="server"></asp:Label></td></tr> 
        <tr><td colspan="2" align="center"> 
                 <asp:Button ID="btnChargeCard" Text="Pay-Now" OnClick="AuthorizedDotNet_Collect" ValidationGroup="fldGrp1" runat="server" />                  
        </td></tr> 
        <tr><td colspan="2" align="center"> </td></tr> 
      </table> 
    </div> 
    </form> 
</body> 
</html> 

Default.aspx.cs

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using ncMerchantGateway; 
 
public partial class _Default : System.Web.UI.Page 

    protected void Page_Load(object sender, EventArgs e) 
    { 
        if (!Page.IsPostBack) 
        { 
            //- Let's do 10 years of credit card expiration year. 
            this.ddlExpYear.Items.Clear(); 
            this.ddlExpYear.Items.Add(new ListItem("SELECT", "0")); 
            for (int i = 0; i <= 10; i++) 
            { 
                if (i > 0) 
                { 
                    this.ddlExpYear.Items.Add(new ListItem(DateTime.Now.AddYears(i).Year.ToString(), i.ToString())); 
                } 
            } 
        } 
    } 
    protected void ddlPyamentMethod_SelectedIndexChanged(object sender, EventArgs e) 
    { 
        if (ddlPaymentMethod.Text.Trim().ToUpper() == "PAYPAL") 
        {    
            PayPalExpress_Collect(sender, e); 
        }         
    }     
    //--------------------------------------------------------------------------------- 
    //- Warning: a merchant account from authorized.net is required. 
    //--------------------------------------------------------------------------------- 
    protected void AuthorizedDotNet_Collect(object sender, EventArgs e) 
    {    
        //- Entantiate the class here 
        oAuthorizedotnet oGateway = new oAuthorizedotnet(); 
 
        //- very important information must be entered here 
        oGateway.MerchantAccount_Version = "3.1"; // Authorized.net api version. 
        oGateway.AccountHolder_LoginId = "valid login id goes here"; 
        oGateway.AccountHolder_TransactionKey = "valid merchant transaction key goes here"; 
        oGateway.AccountHolder_EMail = "merchart email registered with authorized.net goes here"; 
        oGateway.CompanyCollectorName = "ABC, Inc."; //- Merchant Company name goes here 
        oGateway.AuthorizeChargesOnly = true; // Authorized Only (False = {Authorized and Capture}) 
        oGateway.Country = "USA"; 
        oGateway.Currency = "USD"; 
        oGateway.IsTestMode_Environment = false; //- Live  
 
        //- Amount to be charged 
        double dblCharges = 50.00; 
        //- Sales Tax if there is any based on NYC sales tax. 
        double dblSalesTax = (50.00 * 0.09); 
        //- Total to Collect 
        double dblTotalCharges = dblCharges + dblSalesTax; 
 
        List<string> lstCCPaymentData = new List<string>(); 
        //- Please follow this order 0 throught 12 
        lstCCPaymentData.Add("Jane"); //-Billing First-Name 
        lstCCPaymentData.Add("Doe"); //-Billing Last-Name 
        lstCCPaymentData.Add("123 Apple Road"); //-Billing Address 
        lstCCPaymentData.Add("New York"); //-Billing City 
        lstCCPaymentData.Add("NY"); //-Billing State 
        lstCCPaymentData.Add("10040"); //-Billing Zipcode 
        lstCCPaymentData.Add("212-555-5555"); //-Billing Telephone 
        lstCCPaymentData.Add("[email protected]"); //-shipping email //-7 
         
        //- Credit card info. exactly in this order. 
        lstCCPaymentData.Add(this.txtCreditCardNumber.Text); //-Credit Card number 
        lstCCPaymentData.Add(this.ddlExpMonth.Text); //- Credit card expiration month 
        lstCCPaymentData.Add(this.ddlExpYear.Text); //-Credit card expiration year 
        lstCCPaymentData.Add(this.txtSecurityCode.Text); //-Credit card security code 
        lstCCPaymentData.Add(dblTotalCharges.ToString()); //-Total Amount to be either authorized or capture 
 
        //- Connect with Authorize.net gateway now. 
        oGateway.AuthorizeCaptureCharges(lstCCPaymentData); 
 
        //- Return Message.(Display any error message returned from the Authorized.net gateway here) 
        this.lblGatewayMessage.Text = oGateway.GatewayReturnedMessage.Trim(); 
    } 
    //--------------------------------------------------------------------------------- 
    //- Warning: you must have a paypal account with valid email registered. 
    //--------------------------------------------------------------------------------- 
    protected void PayPalExpress_Collect(object sender, EventArgs e) 
    { 
         
        //- Entantiate the class here 
        oPayPalExpress oGateway = new oPayPalExpress(); 
 
        //- very important information must be entered here 
        oGateway.ECommerce_SiteEMail = "[email protected]"; 
        oGateway.ECommerce_SiteUrl = "www.johndoe.com"; 
        oGateway.Country_Code = "US"; 
        oGateway.Currency_Code = "USD"; 
        oGateway.CancelledTransaction_Url = "http://www.johndoe.com/CancelledTransaction.html"; 
        oGateway.ReturnToECommerce_SiteUrl = "http://www.johndoe.com/Thankyou.html"; 
 
        //- Amount to be charged 
        double dblCharges = 50.00; 
        //- Pay Pal Fee if there is any [Warning: you must let the user know about this fee charges.] 
        double dblProcessingFee = (dblCharges * 2.75) / 100;        
        //- Sales Tax if there is any based on NYC sales tax. 
        double dblSalesTax = (50.00 * 0.09); 
        //- Total to Collect 
        double dblTotalCharges = dblCharges + dblSalesTax + dblProcessingFee; 
         
        List<string> lstPaymentInfo = new List<string>(); 
        //- Please follow this order 
        lstPaymentInfo.Add("10012A"); //- Item Number 
        lstPaymentInfo.Add("Tennis Shoes Size 10"); //- Item Description 
        lstPaymentInfo.Add("1"); //- Qty goes here at least 1 
        lstPaymentInfo.Add(dblTotalCharges.ToString()); //- Amount to charge goes here 
        lstPaymentInfo.Add("20160813104523"); //- Invoice Number goes here 
        lstPaymentInfo.Add(""); //- Shipping charges if any goes here otherwise blank 
        lstPaymentInfo.Add(""); //- Handling charges if any goes here otherwise blank 
        lstPaymentInfo.Add(dblSalesTax.ToString()); //- Sales Taxes if any goes here otherwise blank  
         
        //- This part from here down is not necessary could all be blank "" 
        lstPaymentInfo.Add("Jane"); //- First-name 
        lstPaymentInfo.Add("Doe"); //- Last-name 
        lstPaymentInfo.Add("123 Somewhere in the city"); //- Address 
        lstPaymentInfo.Add("New York"); //- City 
        lstPaymentInfo.Add("NY"); //- State 
        lstPaymentInfo.Add("10005"); //- Zipcode 
        lstPaymentInfo.Add("212-555-5555"); //- Telephone 
        lstPaymentInfo.Add("[email protected]"); //- E-Mail 
         
        //- Go to paypal now and collect 
        oGateway.ProcessPayment(lstPaymentInfo);         
    } 

 

HostForLIFE.eu ASP.NET Core 1.0 Hosting

European best, cheap and reliable ASP.NET hosting with instant activation. HostForLIFE.eu is #1 Recommended Windows and ASP.NET hosting in European Continent. With 99.99% Uptime Guaranteed of Relibility, Stability and Performace. HostForLIFE.eu security team is constantly monitoring the entire network for unusual behaviour. We deliver hosting solution including Shared hosting, Cloud hosting, Reseller hosting, Dedicated Servers, and IT as Service for companies of all size.