Skip to content
Bitzsoft.Integrationsbitzsoft.integrations

Reference

Stripe Payment

Stripe 支付服务——Bearer API Key 鉴权。

Last updated

基于 Stripe REST API 实现,采用 Bearer API Key 鉴权。

包信息

  • NuGet 包:Bitzsoft.Integrations.Payment.Stripe
  • 接口:IPaymentProvider
  • 鉴权:Bearer API Key(SecretKey)
  • Provider ID:stripe

配置

字段类型必填默认值说明
SecretKeystringAPI 密钥(sk_live_xxx 正式 / sk_test_xxx 测试)
WebhookSecretstringWebhook 签名密钥(whsec_xxx,用于验证回调签名)
UseTenantWebhookCredentialsboolfalse多租户场景下强制按 WebhookRoute 解析 WebhookSecret
ApiBasestringhttps://api.stripe.comAPI 基地址
TimeoutTimeSpan00:00:30HTTP 请求超时
HttpClientNamestringStripePaymentProvider命名 HttpClient 标识
{
"Stripe": {
"SecretKey": "sk_live_xxx",
"WebhookSecret": "whsec_xxx",
"ApiBase": "https://api.stripe.com"
}
}

注册

// 方式一:IConfiguration(默认读取 "Stripe" 配置节)
services.AddBitzsoftStripePayment(configuration);
// 方式二:委托配置
services.AddBitzsoftStripePayment(options =>
{
options.SecretKey = "sk_live_xxx";
options.WebhookSecret = "whsec_xxx";
});

使用示例

var orderResult = await provider.CreateOrderAsync(new PaymentOrderRequest
{
OutTradeNo = "ORDER_20260801_003",
Subject = "Stripe Order",
TotalAmount = 49.99m,
Scene = PaymentScene.Web
});
// 查询状态
var status = await provider.QueryStatusAsync("ORDER_20260801_003");
// 退款
var refundResult = await provider.RefundAsync(new RefundRequest
{
OutTradeNo = "ORDER_20260801_003",
RefundAmount = 49.99m,
RefundNo = "REFUND_002"
});

鉴权机制

  • 每个请求通过 Authorization: Bearer {SecretKey} 头携带 API 密钥。
  • Webhook 验签:使用 WebhookSecretStripe-Signature 头和请求体做 HMAC-SHA256 验签。

已知限制

多租户宿主场景必须设 UseTenantWebhookCredentials = true,通过 IIntegrationCredentialResolver 按 WebhookRoute 解析租户密钥,此时不回退到全局 WebhookSecret

100%

滚轮或按钮缩放 · 放大后拖动画面 · 双击切换 100% / 200%