Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
Stripe.Net
is a powerful .NET library that allows developers to integrate Stripe's payment processing capabilities into .NET applications. Stripe is a popular payment gateway that enables businesses to accept payments online. With Stripe.Net
, developers can manage transactions, customers, subscriptions, and more using the robust features provided by the Stripe API. In this article, we will discuss how to use Stripe with IronPDF to create PDFs.
To get started with Stripe.Net
, we need to create a new Visual Studio project or open an existing one. For this tutorial, we will use a Console Application project.
Open Visual Studio and click on "Create a New Project".
A new window will appear. Select Console Application and click on Next.
In the next window, enter your project name and select the location, then click on Next.
In the next window, select the framework and click on Create.
Just like that, your new Visual Studio Console Application project is created.
To start using Stripe.Net
in your project, you need to install the Stripe.Net package via NuGet. You can do this using the Package Manager Console or the NuGet Package Manager in Visual Studio.
Using the Package Manager Console:
Install-Package Stripe.net
Or
dotnet add package Stripe.net
Using the NuGet Package Manager, search for "Stripe.net" and install the package.
Once installed, you need to configure your Stripe API key, which you can find on your Stripe account. This key is essential for authenticating your requests to the Stripe API. Typically, this key is stored in a configuration file or environment variable for security purposes.
Here’s an example of how to set up your API key:
StripeConfiguration.ApiKey = "your_secret_api_key";
StripeConfiguration.ApiKey = "your_secret_api_key";
StripeConfiguration.ApiKey = "your_secret_api_key"
Creating a customer is one of the fundamental operations when working with Stripe.Net
. Customers can be associated with payment methods and subscriptions.
var options = new CustomerCreateOptions
{
Email = "customer@example.com",
Name = "John Doe",
};
var service = new CustomerService();
Customer customer = service.Create(options);
var options = new CustomerCreateOptions
{
Email = "customer@example.com",
Name = "John Doe",
};
var service = new CustomerService();
Customer customer = service.Create(options);
Dim options = New CustomerCreateOptions With {
.Email = "customer@example.com",
.Name = "John Doe"
}
Dim service = New CustomerService()
Dim customer As Customer = service.Create(options)
A PaymentIntent
is an object that represents a payment process in Stripe. It is designed to track the lifecycle of a payment from creation through completion.
var options = new PaymentIntentCreateOptions
{
Amount = 2000,
Currency = "usd",
PaymentMethodTypes = new List<string>
{
"card",
},
};
var service = new PaymentIntentService();
PaymentIntent paymentIntent = service.Create(options);
var options = new PaymentIntentCreateOptions
{
Amount = 2000,
Currency = "usd",
PaymentMethodTypes = new List<string>
{
"card",
},
};
var service = new PaymentIntentService();
PaymentIntent paymentIntent = service.Create(options);
Dim options = New PaymentIntentCreateOptions With {
.Amount = 2000,
.Currency = "usd",
.PaymentMethodTypes = New List(Of String) From {"card"}
}
Dim service = New PaymentIntentService()
Dim paymentIntent As PaymentIntent = service.Create(options)
Stripe supports various subscription models, and managing subscriptions via Stripe.Net
is straightforward. You can create, update, and cancel subscriptions.
var options = new SubscriptionCreateOptions
{
Customer = "cus_123456789",
Items = new List<SubscriptionItemOptions>
{
new SubscriptionItemOptions
{
Plan = "plan_123456789",
},
},
};
var service = new SubscriptionService();
Subscription subscription = service.Create(options);
var options = new SubscriptionCreateOptions
{
Customer = "cus_123456789",
Items = new List<SubscriptionItemOptions>
{
new SubscriptionItemOptions
{
Plan = "plan_123456789",
},
},
};
var service = new SubscriptionService();
Subscription subscription = service.Create(options);
Dim options = New SubscriptionCreateOptions With {
.Customer = "cus_123456789",
.Items = New List(Of SubscriptionItemOptions) From {
New SubscriptionItemOptions With {.Plan = "plan_123456789"}
}
}
Dim service = New SubscriptionService()
Dim subscription As Subscription = service.Create(options)
Disputes occur when a customer questions a charge with their bank or credit card company. Stripe.Net
allows you to list, retrieve, and respond to disputes.
var service = new DisputeService();
Dispute dispute = service.Get("dp_123456789");
var service = new DisputeService();
Dispute dispute = service.Get("dp_123456789");
Dim service = New DisputeService()
Dim dispute As Dispute = service.Get("dp_123456789")
Stripe.Net
library documentation for up-to-date information and examples.IronPDF
is a C# library that allows developers to create, edit, and extract content from PDF documents. It is an ideal tool for generating PDFs in .NET applications, whether for reports, invoices, or other documentation needs.
IronPDF allows developers to create PDF documents easily by converting HTML strings, URLs, and HTML files to PDF.
Edit existing PDF documents with ease. IronPDF allows you to manipulate existing PDFs by enabling users to add pages at specific indexes, copy or delete pages, split a PDF, and extract pages to create new PDFs, etc.
IronPDF's merge functionality allows developers to combine two or more PDF documents into one.
IronPDF enables users to add passwords and permissions to PDFs to enhance PDF security.
IronPDF supports 128-bit encryption, decryption, and password protection of PDF documents.
Developers can programmatically add digital signatures to PDFs using IronPDF. It supports multiple ways to sign a PDF with a digital signature certificate of .pfx
and .p12
formats.
Let's create a practical example where we generate a PDF invoice using IronPDF after processing a payment with Stripe.Net
.
Steps to install IronPDF using NuGet Package Manager:
In the "Browse" tab, search for "IronPDF" and select the desired version. Click on "Install" to add the package to your project. IronPDF and its dependencies will be automatically downloaded and integrated, allowing you to start leveraging its functionality in your ASP.NET application seamlessly.
Here's a complete example that demonstrates creating a new payment with Stripe.Net
API and generating a PDF invoice with IronPDF
.
using Stripe;
using IronPdf;
using System;
public class PaymentService
{
public void ProcessPaymentAndGenerateInvoice()
{
// Configure Stripe API key
StripeConfiguration.ApiKey = "your_secret_key";
// Create a PaymentIntent
var paymentIntentOptions = new PaymentIntentCreateOptions
{
Amount = 2000,
Currency = "usd",
PaymentMethodTypes = new List<string> { "card" },
};
var paymentIntentService = new PaymentIntentService();
PaymentIntent paymentIntent = paymentIntentService.Create(paymentIntentOptions);
// Assuming payment succeeded, create a PDF invoice
GeneratePdfInvoice(paymentIntent);
}
private void GeneratePdfInvoice(PaymentIntent paymentIntent)
{
// Create HTML content for the invoice
var htmlContent = $@"
<html>
<head>
<title>Invoice</title>
</head>
<body>
<h1>Invoice</h1>
<p>Payment ID: {paymentIntent.Id}</p>
<p>Amount: {paymentIntent.Amount / 100.0:C}</p>
<p>Status: {paymentIntent.Status}</p>
</body>
</html>";
// Convert HTML to PDF
var renderer = new ChromePdfRenderer();
var pdfDocument = renderer.RenderHtmlAsPdf(htmlContent);
// Save PDF to file
var filePath = "invoice.pdf";
pdfDocument.SaveAs(filePath);
Console.WriteLine($"Invoice saved to {filePath}");
}
}
class Program
{
static void Main(string[] args)
{
var service = new PaymentService();
service.ProcessPaymentAndGenerateInvoice();
}
}
using Stripe;
using IronPdf;
using System;
public class PaymentService
{
public void ProcessPaymentAndGenerateInvoice()
{
// Configure Stripe API key
StripeConfiguration.ApiKey = "your_secret_key";
// Create a PaymentIntent
var paymentIntentOptions = new PaymentIntentCreateOptions
{
Amount = 2000,
Currency = "usd",
PaymentMethodTypes = new List<string> { "card" },
};
var paymentIntentService = new PaymentIntentService();
PaymentIntent paymentIntent = paymentIntentService.Create(paymentIntentOptions);
// Assuming payment succeeded, create a PDF invoice
GeneratePdfInvoice(paymentIntent);
}
private void GeneratePdfInvoice(PaymentIntent paymentIntent)
{
// Create HTML content for the invoice
var htmlContent = $@"
<html>
<head>
<title>Invoice</title>
</head>
<body>
<h1>Invoice</h1>
<p>Payment ID: {paymentIntent.Id}</p>
<p>Amount: {paymentIntent.Amount / 100.0:C}</p>
<p>Status: {paymentIntent.Status}</p>
</body>
</html>";
// Convert HTML to PDF
var renderer = new ChromePdfRenderer();
var pdfDocument = renderer.RenderHtmlAsPdf(htmlContent);
// Save PDF to file
var filePath = "invoice.pdf";
pdfDocument.SaveAs(filePath);
Console.WriteLine($"Invoice saved to {filePath}");
}
}
class Program
{
static void Main(string[] args)
{
var service = new PaymentService();
service.ProcessPaymentAndGenerateInvoice();
}
}
Imports Stripe
Imports IronPdf
Imports System
Public Class PaymentService
Public Sub ProcessPaymentAndGenerateInvoice()
' Configure Stripe API key
StripeConfiguration.ApiKey = "your_secret_key"
' Create a PaymentIntent
Dim paymentIntentOptions = New PaymentIntentCreateOptions With {
.Amount = 2000,
.Currency = "usd",
.PaymentMethodTypes = New List(Of String) From {"card"}
}
Dim paymentIntentService As New PaymentIntentService()
Dim paymentIntent As PaymentIntent = paymentIntentService.Create(paymentIntentOptions)
' Assuming payment succeeded, create a PDF invoice
GeneratePdfInvoice(paymentIntent)
End Sub
Private Sub GeneratePdfInvoice(ByVal paymentIntent As PaymentIntent)
' Create HTML content for the invoice
'INSTANT VB WARNING: Instant VB cannot determine whether both operands of this division are integer types - if they are then you should use the VB integer division operator:
Dim htmlContent = $"
<html>
<head>
<title>Invoice</title>
</head>
<body>
<h1>Invoice</h1>
<p>Payment ID: {paymentIntent.Id}</p>
<p>Amount: {paymentIntent.Amount / 100.0:C}</p>
<p>Status: {paymentIntent.Status}</p>
</body>
</html>"
' Convert HTML to PDF
Dim renderer = New ChromePdfRenderer()
Dim pdfDocument = renderer.RenderHtmlAsPdf(htmlContent)
' Save PDF to file
Dim filePath = "invoice.pdf"
pdfDocument.SaveAs(filePath)
Console.WriteLine($"Invoice saved to {filePath}")
End Sub
End Class
Friend Class Program
Shared Sub Main(ByVal args() As String)
Dim service = New PaymentService()
service.ProcessPaymentAndGenerateInvoice()
End Sub
End Class
Stripe.Net
is a comprehensive and powerful library that simplifies integrating Stripe’s payment processing into .NET applications. With features ranging from basic transaction handling to managing subscriptions and disputes, it covers a wide range of payment-related needs.
IronPDF
complements Stripe.Net
by enabling developers to generate, edit, and manage PDF documents. Together, these libraries provide a robust solution for handling payments and generating corresponding documentation in .NET applications.
By leveraging the capabilities of both Stripe.Net
and IronPDF
, developers can create seamless and efficient workflows that handle everything from payment processing to document generation, enhancing the overall functionality and user experience of their applications.
IronPDF offers developers a chance to test out its extensive features by providing a free trial page.
IronPDF provides customer support and updates, along with code examples and thorough documentation to help users make the most out of it. To explore the topic further, refer to our extensive tutorial on HTML to PDF Conversion.
9 .NET API products for your office documents