Bitzsoft.Integrations.Payment.Stripe 1.0.1

dotnet add package Bitzsoft.Integrations.Payment.Stripe --version 1.0.1
                    
NuGet\Install-Package Bitzsoft.Integrations.Payment.Stripe -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.Stripe" 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.Stripe" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Bitzsoft.Integrations.Payment.Stripe" />
                    
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.Stripe --version 1.0.1
                    
#r "nuget: Bitzsoft.Integrations.Payment.Stripe, 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.Stripe@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.Stripe&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Bitzsoft.Integrations.Payment.Stripe&version=1.0.1
                    
Install as a Cake Tool

Bitzsoft.Integrations.Payment.Stripe

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

功能特性

  • Checkout Session 下单:基于 Stripe Checkout Session 创建支付订单,返回支付链接
  • 全流程覆盖:下单、查单、关单、退款均通过统一 IPaymentProvider 接口暴露
  • Webhook 验签:除 IPaymentProvider.VerifyCallbackAsync 兼容入口外,额外注册 IWebhookVerifier,可接入 Bitzsoft.Integrations.Webhooks 原始字节验签、防重放、幂等 Inbox、重试与 DLQ
  • 多租户凭据:支持按 WebhookRoute 租户解析 Webhook 密钥,防止租户间误用全局密钥
  • 零厂商 SDK 依赖:裸 HttpClient 直调 REST API,包体积小
  • 请求审计:内置 RequestLogging 管道,记录出站请求

安装

dotnet add package Bitzsoft.Integrations.Payment.Stripe
<PackageReference Include="Bitzsoft.Integrations.Payment.Stripe" Version="1.0.0" />

配置

appsettings.json

{
  "Stripe": {
    "SecretKey": "sk_live_xxx",
    "WebhookSecret": "whsec_xxx"
  }
}
配置项 说明 必填 默认值
SecretKey API 密钥(sk_live_xxx 正式环境 / sk_test_xxx 测试环境) -
WebhookSecret Webhook 签名密钥(whsec_xxx),用于验证回调签名 -
UseTenantWebhookCredentials 是否强制按 WebhookRoute 租户解析 WebhookSecret;多租户宿主必须设为 true,此时不会回退到全局密钥 false
ApiBase API 基地址 https://api.stripe.com
Timeout HTTP 请求超时时间 30s
HttpClientName 命名 HttpClient 标识 StripePaymentProvider

注册服务

从 IConfiguration 绑定(推荐)

using Microsoft.Extensions.DependencyInjection;

builder.Services.AddBitzsoftStripePayment(
    builder.Configuration.GetSection("Stripe"));

委托配置

builder.Services.AddBitzsoftStripePayment(options =>
{
    options.SecretKey = "sk_live_xxx";
    options.WebhookSecret = "whsec_xxx";
});

使用示例

注入 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;
    }
}

Webhook Gateway(多租户)

宿主以可信 endpoint 解析租户后调用 Gateway:

var route = new WebhookRoute(
    tenantId,
    "Payment:stripe",
    endpointId,
    region: "global",
    environment: "Live");

var result = await gateway.ReceiveAsync(
    route,
    new WebhookRequest(rawBody, headers, contentType: "application/json"),
    cancellationToken);

多租户宿主应设置 UseTenantWebhookCredentials = true,并按 Payment:stripeIntegrationCredentialKey 配置 WebhookSecret 字段。该模式下缺失租户凭据会直接失败,不会回退到全局 WebhookSecret

依赖

说明
Bitzsoft.Integrations.Payment 抽象层(IPaymentProvider 接口 / 模型)
Bitzsoft.Integrations.Webhooks Webhook 验签基础设施(IWebhookVerifier
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.Stripe:

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 0 8/3/2026
1.0.0 0 8/2/2026
1.0.0-alpha.10 48 7/26/2026
1.0.0-alpha.9 388 7/12/2026