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" />
                    
Directory.Packages.props
<PackageReference Include="Bitzsoft.Integrations.Payment.PayPal" />
                    
Project file
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
                    
#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
                    
Install as a Cake Addin
#tool nuget:?package=Bitzsoft.Integrations.Payment.PayPal&version=1.0.1
                    
Install as a Cake Tool

Bitzsoft.Integrations.Payment.PayPal

PayPal 支付服务实现,实现 IPaymentProvider 统一接口。

功能特性

  • Orders REST API v2:基于 PayPal Orders v2 实现 CAPTURE 下单、查询、关闭、退款全流程
  • OAuth2 Client Credentials 鉴权:使用 ClientId + ClientSecret 换取 access_tokenPayPalTokenManager 缓存令牌,双重检查锁防止并发刷新,提前 60 秒过期
  • Webhook 验签:通过 VERIFY-WEBHOOK-SIGNATURE 端点校验回调签名(需配置 WebhookId
  • 沙箱自动切换UseSandboxtrue 时基地址自动切换为 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 基地址(UseSandboxtrue 时自动切换为 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 日志抽象

相关包

供应商 包名
统一抽象 Bitzsoft.Integrations.Payment
支付宝 Bitzsoft.Integrations.Payment.Alipay
微信支付 Bitzsoft.Integrations.Payment.WeChatPay
Stripe Bitzsoft.Integrations.Payment.Stripe
PayPal Bitzsoft.Integrations.Payment.PayPal
银联 Bitzsoft.Integrations.Payment.UnionPay
聚合包 Bitzsoft.Integrations.Payment.All
Product 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.

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.

Version Downloads Last Updated
1.0.1 32 8/3/2026
1.0.0 40 8/2/2026