在生產環境中測試,無水印。
在任何需要的地方都能運行。
獲得 30 天的全功能產品。
在幾分鐘內上手運行。
試用產品期間完全訪問我們的支援工程團隊
Stripe.Net
是一個強大的 .NET 程式庫,讓開發人員能將 Stripe 的支付處理功能整合到 .NET 應用程式中。 Stripe 是一個受歡迎的支付網關,讓企業能夠在線接受支付。使用 Stripe.Net
,開發人員可以利用 Stripe API 提供的強大功能來管理交易、客戶、訂閱等。 在本文中,我們將討論如何使用 Stripe 與 IronPDF 來創建 PDF。
要開始使用Stripe.Net
,我們需要創建一個新的 Visual Studio 專案或打開現有的專案。 在本教程中,我們將使用一個主控台應用程式專案。
打開 Visual Studio,然後點擊「建立新專案」。
將會出現一個新視窗。 選擇控制台應用程式,然後點擊下一步。
![Stripe .NET(開發者運作方式):圖2 - 選擇 C# 控制台應用程式作為專案類型。 按一下下一步。
在下一個視窗中,輸入您的專案名稱並選擇位置,然後點擊「下一步」。
![Stripe .NET(它對開發者的運作方式):圖 3 - 配置您的項目,指定項目名稱、位置和解決方案名稱。 然後點擊下一步。
在下一個視窗中,選擇框架並點擊創建。
就這樣,您的新 Visual Studio 主控台應用程式專案已建立。
要在您的專案中開始使用Stripe.Net
,您需要通過 NuGet 安裝 Stripe.Net 套件。 您可以使用套件管理員主控台或 Visual Studio 中的 NuGet 套件管理員來執行此操作。
使用套件管理器主控台:
Install-Package Stripe.net
Install-Package Stripe.net
或
dotnet add package Stripe.net
dotnet add package Stripe.net
使用 NuGet 套件管理器,搜索 "Stripe.net" 並安裝該套件。
安裝後,您需要配置您的 Stripe API 密鑰,您可以在您的 Stripe 帳戶中找到該密鑰。 此密鑰對於驗證您對 Stripe API 的請求是至關重要的。 通常,這個密鑰會出於安全目的存儲在配置文件或環境變數中。
以下是一個設置您的 API 金鑰的範例:
StripeConfiguration.ApiKey = "your_secret_api_key";
StripeConfiguration.ApiKey = "your_secret_api_key";
StripeConfiguration.ApiKey = "your_secret_api_key"
在使用Stripe.Net
時,創建客戶是基本操作之一。 客戶可以與支付方式和訂閱相關聯。
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)
PaymentIntent
是一個在 Stripe 中表示付款處理的物件。它旨在跟蹤付款的生命週期,從創建到完成。
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 支援各種訂閱模式,並且透過 Stripe.Net
管理訂閱非常簡單。 您可以建立、更新和取消訂閱。
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)
當客戶向他們的銀行或信用卡公司質疑交易時,便會發生爭議。 Stripe.Net
允許您列出、檢索和回應爭議。
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")
安全性:始終保障您的 API 金鑰安全,切勿在源文件中硬編碼它們。
錯誤處理:實施穩健的錯誤處理來管理異常和失敗的 API 調用。
測試:使用 Stripe 的測試模式並提供測試卡號,以徹底測試您的整合。
Stripe.Net
庫文件,獲取最新信息和範例。IronPDF
是一個C#庫,允許開發人員創建、編輯和提取PDF文件中的內容。 它是生成.NET應用程式中的PDF的理想工具,無論是用於報告、發票還是其他文檔需求。
IronPDF 可以準確地將網頁、URL 和HTML 轉換為 PDF格式,使其成為從在線內容(如報告和發票)創建 PDF 文件的完美工具。
using IronPdf;
class Program
{
static void Main(string[] args)
{
var renderer = new ChromePdfRenderer();
// 1. Convert HTML String to PDF
var htmlContent = "<h1>Hello, IronPDF!</h1><p>This is a PDF from an HTML string.</p>";
var pdfFromHtmlString = renderer.RenderHtmlAsPdf(htmlContent);
pdfFromHtmlString.SaveAs("HTMLStringToPDF.pdf");
// 2. Convert HTML File to PDF
var htmlFilePath = "path_to_your_html_file.html"; // Specify the path to your HTML file
var pdfFromHtmlFile = renderer.RenderHtmlFileAsPdf(htmlFilePath);
pdfFromHtmlFile.SaveAs("HTMLFileToPDF.pdf");
// 3. Convert URL to PDF
var url = "http://ironpdf.com"; // Specify the URL
var pdfFromUrl = renderer.RenderUrlAsPdf(url);
pdfFromUrl.SaveAs("URLToPDF.pdf");
}
}
using IronPdf;
class Program
{
static void Main(string[] args)
{
var renderer = new ChromePdfRenderer();
// 1. Convert HTML String to PDF
var htmlContent = "<h1>Hello, IronPDF!</h1><p>This is a PDF from an HTML string.</p>";
var pdfFromHtmlString = renderer.RenderHtmlAsPdf(htmlContent);
pdfFromHtmlString.SaveAs("HTMLStringToPDF.pdf");
// 2. Convert HTML File to PDF
var htmlFilePath = "path_to_your_html_file.html"; // Specify the path to your HTML file
var pdfFromHtmlFile = renderer.RenderHtmlFileAsPdf(htmlFilePath);
pdfFromHtmlFile.SaveAs("HTMLFileToPDF.pdf");
// 3. Convert URL to PDF
var url = "http://ironpdf.com"; // Specify the URL
var pdfFromUrl = renderer.RenderUrlAsPdf(url);
pdfFromUrl.SaveAs("URLToPDF.pdf");
}
}
Imports IronPdf
Friend Class Program
Shared Sub Main(ByVal args() As String)
Dim renderer = New ChromePdfRenderer()
' 1. Convert HTML String to PDF
Dim htmlContent = "<h1>Hello, IronPDF!</h1><p>This is a PDF from an HTML string.</p>"
Dim pdfFromHtmlString = renderer.RenderHtmlAsPdf(htmlContent)
pdfFromHtmlString.SaveAs("HTMLStringToPDF.pdf")
' 2. Convert HTML File to PDF
Dim htmlFilePath = "path_to_your_html_file.html" ' Specify the path to your HTML file
Dim pdfFromHtmlFile = renderer.RenderHtmlFileAsPdf(htmlFilePath)
pdfFromHtmlFile.SaveAs("HTMLFileToPDF.pdf")
' 3. Convert URL to PDF
Dim url = "http://ironpdf.com" ' Specify the URL
Dim pdfFromUrl = renderer.RenderUrlAsPdf(url)
pdfFromUrl.SaveAs("URLToPDF.pdf")
End Sub
End Class
IronPDF可以讓開發人員輕鬆創建PDF文件,透過將HTML字串、URL和HTML文件轉換為PDF。
輕鬆編輯現有的 PDF 文件。 IronPDF 允許您透過添加頁面到特定索引、複製或刪除頁面、拆分 PDF 以及提取頁面以創建新的 PDF 等功能來操作現有的 PDF。
IronPDF 的合併功能允許開發人員將兩個或多個 PDF 文件合併為一個。
IronPDF 讓用戶可以為 PDF 添加密碼和權限,以增強 PDF 的安全性。
IronPDF 支援 128 位加密、解密和 PDF 文件的密碼保護。
開發人員可以使用 IronPDF 以程式方式向 PDF 添加數位簽章。 它支持使用格式為 .pfx
和 .p12
的數位簽章證書以多種方式對 PDF 進行簽署。
讓我們創建一個實用的範例,使用 IronPDF 在處理 Stripe.Net
付款後生成 PDF 發票。
使用 NuGet 套件管理器安裝 IronPDF 的步驟:
在 Visual Studio 中打開您的 ASP.NET 專案,然後導航到「工具」選單。
選擇「NuGet 套件管理員」,然後點擊「管理解決方案的 NuGet 套件」。
在「瀏覽」標籤中,搜尋「IronPDF」並選擇所需版本。 點擊「安裝」將套件新增至您的專案。 IronPDF及其依賴項將自動下載並集成,讓您能夠無縫地在您的ASP.NET應用程序中開始利用其功能。
以下是一個完整的範例,演示如何使用Stripe.Net
API創建新的支付並使用IronPDF
生成PDF發票。
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
是一個全面且強大的函式庫,能夠簡化將Stripe的支付處理整合到 .NET 應用程式中的過程。 具有從基本交易處理到管理訂閱和爭議等功能,它涵蓋了廣泛的支付相關需求。
IronPDF
通過讓開發人員生成、編輯和管理 PDF 文件來補充 Stripe.Net
。 這些函式庫共同為 .NET 應用程式中的付款處理和生成相應文檔提供了一個強大的解決方案。
通過利用Stripe.Net
和IronPDF
兩者的功能,開發人員可以創建無縫且高效的工作流程,從支付處理到文件生成,提升其應用程序的整體功能和用戶體驗。
IronPDF 透過提供IronPDF 的免費試用,讓開發者有機會測試其豐富的功能。
IronPDF 提供客戶支持和更新,以及代碼示例和詳細的文檔,幫助用戶充分利用其功能。 要進一步探索這個主題,請參考我們關於使用IronPDF進行HTML轉換為PDF的詳細教程。