基于 Stripe REST API 实现,采用 Bearer API Key 鉴权。
包信息
- NuGet 包:
Bitzsoft.Integrations.Payment.Stripe - 接口:
IPaymentProvider - 鉴权:Bearer API Key(SecretKey)
- Provider ID:
stripe
配置
| 字段 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
SecretKey | string | 是 | — | API 密钥(sk_live_xxx 正式 / sk_test_xxx 测试) |
WebhookSecret | string | 是 | — | Webhook 签名密钥(whsec_xxx,用于验证回调签名) |
UseTenantWebhookCredentials | bool | 否 | false | 多租户场景下强制按 WebhookRoute 解析 WebhookSecret |
ApiBase | string | 否 | https://api.stripe.com | API 基地址 |
Timeout | TimeSpan | 否 | 00:00:30 | HTTP 请求超时 |
HttpClientName | string | 否 | StripePaymentProvider | 命名 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 验签:使用
WebhookSecret对Stripe-Signature头和请求体做 HMAC-SHA256 验签。
已知限制
多租户宿主场景必须设 UseTenantWebhookCredentials = true,通过 IIntegrationCredentialResolver 按 WebhookRoute 解析租户密钥,此时不回退到全局 WebhookSecret。