Bitzsoft.Integrations.Payment.PayPal
1.0.1
dotnet add package Bitzsoft.Integrations.Payment.PayPal --version 1.0.1
NuGet\Install-Package Bitzsoft.Integrations.Payment.PayPal -Version 1.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Bitzsoft.Integrations.Payment.PayPal" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Bitzsoft.Integrations.Payment.PayPal" Version="1.0.1" />
<PackageReference Include="Bitzsoft.Integrations.Payment.PayPal" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Bitzsoft.Integrations.Payment.PayPal --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Bitzsoft.Integrations.Payment.PayPal, 1.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Bitzsoft.Integrations.Payment.PayPal@1.0.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Bitzsoft.Integrations.Payment.PayPal&version=1.0.1
#tool nuget:?package=Bitzsoft.Integrations.Payment.PayPal&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Bitzsoft.Integrations.Payment.PayPal
PayPal 支付服务实现,实现 IPaymentProvider 统一接口。
功能特性
- Orders REST API v2:基于 PayPal Orders v2 实现
CAPTURE下单、查询、关闭、退款全流程 - OAuth2 Client Credentials 鉴权:使用
ClientId+ClientSecret换取access_token,PayPalTokenManager缓存令牌,双重检查锁防止并发刷新,提前 60 秒过期 - Webhook 验签:通过
VERIFY-WEBHOOK-SIGNATURE端点校验回调签名(需配置WebhookId) - 沙箱自动切换:
UseSandbox为true时基地址自动切换为 sandbox - 零厂商 SDK 依赖:裸 HttpClient 直调 REST API,包体积小
- 请求审计:内置 RequestLogging 管道,记录出站请求
安装
dotnet add package Bitzsoft.Integrations.Payment.PayPal
<PackageReference Include="Bitzsoft.Integrations.Payment.PayPal" Version="1.0.0" />
配置
appsettings.json
{
"PayPal": {
"ClientId": "your-client-id",
"ClientSecret": "your-client-secret",
"UseSandbox": true,
"WebhookId": "your-webhook-id"
}
}
| 配置项 | 说明 | 必填 | 默认值 |
|---|---|---|---|
ClientId |
应用 Client Id | 是 | - |
ClientSecret |
应用 Client Secret | 是 | - |
BaseUrl |
API 基地址(UseSandbox 为 true 时自动切换为 sandbox 地址) |
否 | https://api-m.paypal.com |
UseSandbox |
是否使用沙箱环境 | 否 | false |
WebhookId |
Webhook ID(回调验签所需) | 否 | - |
HttpClientName |
业务 HttpClient 命名 | 否 | PayPalPaymentProvider |
TokenHttpClientName |
令牌 HttpClient 命名 | 否 | PayPalPaymentProviderToken |
Timeout |
HTTP 请求超时时间 | 否 | 30s |
注册服务
从 IConfiguration 绑定(推荐)
using Microsoft.Extensions.DependencyInjection;
builder.Services.AddPayPalPayment(
builder.Configuration.GetSection("PayPal"));
委托配置
builder.Services.AddPayPalPayment(options =>
{
options.ClientId = "your-client-id";
options.ClientSecret = "your-client-secret";
options.UseSandbox = true;
options.WebhookId = "your-webhook-id";
});
使用示例
注入 IPaymentProvider 调用
using Bitzsoft.Integrations.Payment;
public class OrderService(IPaymentProvider payment)
{
public async Task<string> CreatePaymentAsync(string outTradeNo, long amountCents, string subject)
{
var result = await payment.CreateOrderAsync(new PaymentOrderRequest
{
OutTradeNo = outTradeNo,
Subject = subject,
TotalAmount = amountCents,
Currency = "USD",
Scene = PaymentScene.Web
});
if (!result.IsSuccess)
throw new PaymentException(payment.Code, result.ErrorCode, result.ErrorMessage);
return result.Data!.PayUrl!;
}
public async Task<bool> IsPaidAsync(string outTradeNo)
{
var result = await payment.QueryStatusAsync(outTradeNo);
return result.IsSuccess && result.Data!.Status == PaymentStatus.Success;
}
}
接口映射
IPaymentProvider 方法 |
PayPal 端点 |
|---|---|
CreateOrderAsync |
POST /v2/checkout/orders(intent=CAPTURE) |
QueryStatusAsync |
GET /v2/checkout/orders/{id} |
CloseOrderAsync |
POST /v2/checkout/orders/{id}/void |
RefundAsync |
POST /v2/payments/captures/{captureId}/refund |
VerifyCallbackAsync |
POST /v1/notifications/verify-webhook-signature |
金额换算:统一接口以「分」为单位,PayPal 以主货币单位(元)字符串表示,内部按 1:100 自动换算。
依赖
| 包 | 说明 |
|---|---|
Bitzsoft.Integrations.Payment |
抽象层(IPaymentProvider 接口 / 模型) |
Bitzsoft.Integrations.RequestLogging |
出站请求审计 |
Bitzsoft.Integrations.Compatibility |
基础工具库 |
Microsoft.Extensions.Http |
IHttpClientFactory |
Microsoft.Extensions.Options.ConfigurationExtensions |
Options 配置绑定 |
Microsoft.Extensions.Logging.Abstractions |
日志抽象 |
相关包
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Bitzsoft.Integrations.Compatibility (>= 1.0.1)
- Bitzsoft.Integrations.Payment (>= 1.0.1)
- Bitzsoft.Integrations.RequestLogging (>= 1.0.1)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Http (>= 10.0.10)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.10)
-
net5.0
- Bitzsoft.Integrations.Compatibility (>= 1.0.1)
- Bitzsoft.Integrations.Payment (>= 1.0.1)
- Bitzsoft.Integrations.RequestLogging (>= 1.0.1)
- Microsoft.Extensions.Configuration.Abstractions (>= 5.0.0)
- Microsoft.Extensions.Http (>= 5.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 5.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 5.0.0)
-
net8.0
- Bitzsoft.Integrations.Compatibility (>= 1.0.1)
- Bitzsoft.Integrations.Payment (>= 1.0.1)
- Bitzsoft.Integrations.RequestLogging (>= 1.0.1)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Http (>= 10.0.10)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.10)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Bitzsoft.Integrations.Payment.PayPal:
| Package | Downloads |
|---|---|
|
Bitzsoft.Integrations.Payment.All
支付聚合包 — 包含支付宝 / 微信支付 / Stripe / PayPal / 银联 全部实现 |
GitHub repositories
This package is not used by any popular GitHub repositories.