如何通过C# Stripe API重新发送成功付款的收据邮件?
使用C# Stripe API重新发送付款收据的方法
可以的,Stripe API支持为已完成的付款重新发送收据,在C#中借助Stripe.NET库就能实现,分两种常见集成场景处理:
针对PaymentIntent(新版推荐方案)
如果你的系统使用Stripe新版的PaymentIntent流程,直接调用PaymentIntentService的SendReceiptAsync方法即可,还能指定新的收件邮箱:
using Stripe; // 配置你的Stripe API密钥 StripeConfiguration.ApiKey = "sk_your_secret_key"; var paymentIntentService = new PaymentIntentService(); var sendOptions = new PaymentIntentSendReceiptOptions { Email = "target@example.com" // 这里填写你要发送的指定邮箱 }; // 替换为实际的已完成付款的PaymentIntent ID await paymentIntentService.SendReceiptAsync("pi_1234567890abcdef", sendOptions);
针对Charge(旧版集成场景)
若你的系统仍在使用旧版Charge对象,可通过ChargeService的对应方法实现:
using Stripe; StripeConfiguration.ApiKey = "sk_your_secret_key"; var chargeService = new ChargeService(); var sendOptions = new ChargeSendReceiptOptions { Email = "target@example.com" }; // 替换为实际的已完成付款的Charge ID await chargeService.SendReceiptAsync("ch_0987654321fedcba", sendOptions);
关键注意事项
- 付款状态必须是
succeeded(已完成)才能触发收据发送 - 若不指定
Email参数,Stripe会默认发送到付款时关联的原邮箱 - 确保使用的API密钥拥有
write权限,否则会触发权限错误
内容的提问来源于stack exchange,提问作者Cornel
相关产品推荐
相关产品推荐

