Skip to main content
Login Register
Code2night
  • Home
  • Blog Archive
  • Learn
    • Tutorials
    • Videos
  • Interview Q&A
  • Languages
    • Angular Angular js ASP.NET Asp.net Core ASP.NET Core, C# C C# C#, ASP.NET Core, Dapper
      C#, ASP.NET Core, Dapper, Entity Framework DotNet HTML/CSS Java JavaScript Node.js Python Python 3.11, Pandas, SQL
      Python 3.11, SQL Python 3.11, SQLAlchemy Python 3.11, SQLAlchemy, SQL Python 3.11, SQLite React Security SQL Server TypeScript
  • Post Blog
  • Tools
    • Beautifiers
      JSON Beautifier HTML Beautifier XML Beautifier CSS Beautifier JS Beautifier SQL Formatter
      Dev Utilities
      JWT Decoder Regex Tester Diff Checker Cron Explainer String Escape Hash Generator Password Generator
      Converters
      Base64 Encode/Decode URL Encoder/Decoder JSON to CSV CSV to JSON JSON to TypeScript Markdown to HTML Number Base Converter Timestamp Converter Case Converter
      Generators
      UUID / GUID Generator Lorem Ipsum QR Code Generator Meta Tag Generator
      Image Tools
      Image Converter Image Resizer Image Compressor Image to Base64 PNG to ICO Background Remover Color Picker
      Text & Content
      Word Counter PDF Editor
      SEO & Web
      SEO Analyzer URL Checker World Clock
  1. Home
  2. Blog
  3. ASP.NET Web Forms
  4. How to implement Paypal in Asp.Net Webforms

How to implement Paypal in Asp.Net Webforms

Date- Jan 24,2024 Updated Mar 2026 7270 Free Download Pay & Download
Paypal

Paypal Integration in Webforms

Using PayPal in ASP.NET (ASPX) involves integrating PayPal's payment processing functionality into your web application to enable users to make online payments securely. Here's a general guide on how you can implement PayPal in an ASP.NET web application:

Paypal is a payment gateway which provides secure payments across the world. It help you accept international payment at some price per transaction. There is no initial setup fee for implementing paypal.So for integrating paypal in Asp.Net aspx Webforms we have to follow these steps :

First of all take one Asp.net Webform application and we will install paypal nuget package which is showed in the image belowHow to implement Paypal in AspNet Webforms

After you have done installing paypal nuget package we will have to take one new form where we will add paypal integration code. You have to add these namespaces on the controller

using PayPalCheckoutSdk.Core;
using PayPalCheckoutSdk.Orders;
using PayPalHttp;

So, now we have to add these methods in our aspx webpage, this method will help us initialize payment and redirect to payment page

 using PayPalCheckoutSdk.Core;
using PayPalCheckoutSdk.Orders;
using PayPalHttp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PaypalWebforms
{
    public partial class _Default : Page
    {
        private static string PayPalClientId => System.Configuration.ConfigurationManager.AppSettings["PayPalClientId"];
        private static string PayPalClientSecret => System.Configuration.ConfigurationManager.AppSettings["PayPalClientSecret"];

        protected void Page_Load(object sender, EventArgs e)
        {

            if (Request.QueryString != null && Request.QueryString.Count != 0)
            {
                string approvalToken = Request.QueryString["token"];
                var response = Task.Run(async () => await captureOrder(approvalToken));  // Use .Result since Page_Load is not asynchronous

                // Process the response or handle errors as needed
                if (response.Result != null)
                {
                    Order result = response.Result.Result<Order>();
                    Label1.Text = result.Status;
                    // Process the response or handle errors
                }
                else
                {
                    // Handle null response (error handling)
                }


            }

        }

        public async static Task<string> createOrder()
        {

            // Construct a request object and set desired parameters
            // Here, OrdersCreateRequest() creates a POST request to /v2/checkout/orders
            var order = new OrderRequest()
            {
                CheckoutPaymentIntent = "CAPTURE",
                PurchaseUnits = new List<PurchaseUnitRequest>()
                {
                    new PurchaseUnitRequest()
                    {
                        AmountWithBreakdown = new AmountWithBreakdown()
                        {
                            CurrencyCode = "USD",
                            Value = "100.00"
                        }
                    }
                },
                ApplicationContext = new ApplicationContext()
                {
                    ReturnUrl = "https://localhost:44355/Default.aspx",
                    CancelUrl = "https://localhost:44355/Default.aspx"
                }
            };


            // Call API with your client and get a response for your call
            var request = new OrdersCreateRequest();
            request.Prefer("return=representation");
            request.RequestBody(order);
            var environment = new SandboxEnvironment(PayPalClientId, PayPalClientSecret);
            var response = await (new PayPalHttpClient(environment).Execute(request));
            var statusCode = response.StatusCode;
            Order result = response.Result<Order>();
            Console.WriteLine("Status: {0}", result.Status);
            Console.WriteLine("Order Id: {0}", result.Id);
            Console.WriteLine("Intent: {0}", result.CheckoutPaymentIntent);
            Console.WriteLine("Links:");
            foreach (LinkDescription link in result.Links)
            {
                Console.WriteLine("\t{0}: {1}\tCall Type: {2}", link.Rel, link.Href, link.Method);
            }
            return GetApprovalUrl(result);
        }



        public async static Task<PayPalHttp.HttpResponse> captureOrder(string token)
        {
            // Construct a request object and set desired parameters
            // Replace ORDER-ID with the approved order id from create order
            var request = new OrdersCaptureRequest(token);
            request.RequestBody(new OrderActionRequest());
            var environment = new SandboxEnvironment(PayPalClientId, PayPalClientSecret);
            var response = await (new PayPalHttpClient(environment).Execute(request));
            var statusCode = response.StatusCode;
            Order result = response.Result<Order>();
            Console.WriteLine("Status: {0}", result.Status);
            Console.WriteLine("Capture Id: {0}", result.Id);
            return response;
        }
        public static string GetApprovalUrl(Order result)
        {

            // Check if there are links in the response
            if (result.Links != null)
            {
                // Find the approval URL link in the response
                LinkDescription approvalLink = result.Links.Find(link => link.Rel.ToLower() == "approve");
                if (approvalLink != null)
                {
                    return approvalLink.Href;
                }
            }


            // Return a default URL or handle the error as needed
            return "https://www.example.com"; // Replace with your default URL
        }

        protected void btnPayment_Click(object sender, EventArgs e)
        {
            var response = Task.Run(async () => await createOrder());
            Response.Redirect(response.Result);
        }
    }
}

After this now you have to go to aspx page and add following code for button and label that will show status of the payment

  
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    <asp:Button ID="btnPayment" runat="server" OnClick="btnPayment_Click" Text="Paypal Payment" />

Now go to your web config file and add two appsettings for clientid and client secret

<appSettings>
  <add key="PayPalClientId" value="AfIlrsSZigMdLni0K2VIUrfLObfNvqtCT2mcBvNUxgLTxPUs_o21gVTjoggSpYFcF2hqkMhfVUSqCv1w" />
  <add key="PayPalClientSecret" value="ECeznQaEnGPzbtq1mNvyZPTUIrZxfsA-XJlZgrDwjJSI1hj1lqT5r1nISJLYeR2xwBarEg5Mq4n18Lm7" />
</appSettings>

Here , please replace the credentials with your original credentials.

Now, we have to run the application and you will see this How to implement Paypal in AspNet Webforms 2

Click on the button and it will call event btnPayment_Click on aspx page. Now , it will create one default item and redirect on the payment page as showed below

How to implement Paypal in AspNet Webforms 3

Now click on Pay with credit or debit card button and it will redirect on a screen where you will have to add card details.

How to implement Paypal in AspNet Webforms 4

You can fill the follow details in here for sandbox testing


Country - United States
Card Type: Visa
Card Number: 4032034155351326
Expiration Date: 09/24
CVV: 275

Street:  4790 Deer Haven Drive
City:  Greenville
State/province/area:   South Carolina
Phone number  864-353-5437
Zip code  29601
Country calling code  +1

Now click on  continue as guest and it will hit back the same method How to implement Paypal in AspNet Webforms 5Here , you can add a breakpoint and check if your payment is approved

How to implement Paypal in AspNet Webforms 6

This is how we can have paypal integration in Asp.net Webforms or this is how we can integrate paypal in Asp.net Webforms. If you want to integrate paypal payment gateway in Asp.net mvc or Asp.Net core then you can check other blogs.

S
Shubham Batra
Programming author at Code2Night — sharing tutorials on ASP.NET, C#, and more.
View all posts →

Related Articles

How to Create Subscriptions in Paypal in Asp.Net Core
Feb 24, 2024
How to refund payment using Paypal in Asp.Net MVC
Jan 30, 2024
How to implement Paypal in Asp.Net Core 8.0
Nov 24, 2023
Payout using Paypal Payment Gateway
Nov 13, 2022
Buy me a pizza

Comments

On this page

🎯

Interview Prep

Ace your ASP.NET Web Forms interview with curated Q&As for all levels.

View ASP.NET Web Forms Interview Q&As

Tags

AspNet C# programming AspNet MVC c programming AspNet Core C software development tutorial MVC memory management Paypal coding coding best practices data structures programming tutorial tutorials object oriented programming Slick Slider StripeNet
Free Download for Youtube Subscribers!

First click on Subscribe Now and then subscribe the channel and come back here.
Then Click on "Verify and Download" button for download link

Subscribe Now | 1770
Download
Support Us....!

Please Subscribe to support us

Thank you for Downloading....!

Please Subscribe to support us

Continue with Downloading
Be a Member
Join Us On Whatsapp
Code2Night

A community platform for sharing programming knowledge, tutorials, and blogs. Learn, write, and grow with developers worldwide.

Panipat, Haryana, India
info@code2night.com
Quick Links
  • Home
  • Blog Archive
  • Tutorials
  • About Us
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Guest Posts
  • SEO Analyzer
Dev Tools
  • JSON Beautifier
  • HTML Beautifier
  • CSS Beautifier
  • JS Beautifier
  • SQL Formatter
  • Diff Checker
  • Regex Tester
  • Markdown to HTML
  • Word Counter
More Tools
  • Password Generator
  • QR Code Generator
  • Hash Generator
  • Base64 Encoder
  • JWT Decoder
  • UUID Generator
  • Image Converter
  • PNG to ICO
  • SEO Analyzer
By Language
  • Angular
  • Angular js
  • ASP.NET
  • Asp.net Core
  • ASP.NET Core, C#
  • C
  • C#
  • C#, ASP.NET Core, Dapper
  • C#, ASP.NET Core, Dapper, Entity Framework
  • DotNet
  • HTML/CSS
  • Java
  • JavaScript
  • Node.js
  • Python
  • Python 3.11, Pandas, SQL
  • Python 3.11, SQL
  • Python 3.11, SQLAlchemy
  • Python 3.11, SQLAlchemy, SQL
  • Python 3.11, SQLite
  • React
  • Security
  • SQL Server
  • TypeScript
© 2026 Code2Night. All Rights Reserved.
Made with for developers  |  Privacy  ·  Terms
Translate Page
We use cookies to improve your experience and analyze site traffic. By clicking Accept, you consent to our use of cookies. Privacy Policy
Accessibility
Text size
High contrast
Grayscale
Dyslexia font
Highlight links
Pause animations
Large cursor