退款与争议处理
使用 Stripe API 发起退款、处理部分退款,并响应拒付和争议,完善一次性支付流程。
退款与争议处理 是 CoddyKit 上的免费 AI Powered SaaS: Stripe + Auth + Billing + Deploy 课时。 这是第 4 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 AI Powered SaaS: Stripe + Auth + Billing + Deploy 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 AI Powered SaaS: Stripe + Auth + Billing + Deploy 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
Why Refunds Matter
Charging customers is only half the job. A smooth refund process builds trust, meets legal obligations, and reduces costly chargebacks. Stripe makes refunds a single API call.
What You Need to Refund
To refund, you need the original PaymentIntent or charge ID. Store it on your order record at purchase time so you can look it up later.
await prisma.order.update({
where: { id },
data: { paymentIntentId: session.payment_intent }
});Issuing a Full Refund
Create a refund by passing the PaymentIntent. With no amount, Stripe refunds the full charge.
const refund = await stripe.refunds.create({
payment_intent: order.paymentIntentId
});Partial Refunds
To refund part of a payment, pass an amount in the smallest currency unit (cents).
await stripe.refunds.create({
payment_intent: order.paymentIntentId,
amount: 500
});Refund Reasons
Tag refunds with a reason for your records and Stripe's analytics. Valid values include requested_by_customer, duplicate, and fraudulent.
await stripe.refunds.create({
payment_intent: id,
reason: 'requested_by_customer'
});Updating Your Database
Reflect the refund in your own system so the order status is accurate and the customer cannot use a refunded product.
await prisma.order.update({
where: { id }, data: { status: 'REFUNDED' }
});Refund Webhooks
Refunds can also be issued from the Stripe Dashboard. Listen for the charge.refunded webhook so your database stays in sync no matter where the refund originates.
if (event.type === 'charge.refunded') {
await markOrderRefunded(event.data.object);
}What is a Dispute?
A dispute (chargeback) happens when a customer asks their bank to reverse a charge. Stripe withdraws the funds and a dispute fee, then asks you for evidence.
Responding to Disputes
Listen for charge.dispute.created and submit evidence — receipts, delivery proof, customer communication — to contest it.
await stripe.disputes.update(disputeId, {
evidence: { receipt: fileId, customer_email_address: email }
});Preventing Chargebacks
The best defense is prevention:
- Use a clear billing descriptor
- Send receipts immediately
- Offer easy self-serve refunds
- Keep records of every transaction
Best Practices
Handle money responsibly:
- Store the PaymentIntent on each order
- Support full and partial refunds with reasons
- Sync via the charge.refunded webhook
- Contest disputes with evidence and prevent them upfront
Quick Check
Test your refund knowledge.
Recap
You completed the payment lifecycle:
- Store the PaymentIntent to enable refunds
- Issue full or partial refunds with a reason
- Sync via the
charge.refundedwebhook - Respond to disputes with evidence and prevent chargebacks
Your one-time payment flow now handles money end to end.
常见问题解答
「退款与争议处理」课时是免费的吗?
是的 — 「退款与争议处理」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 AI Powered SaaS: Stripe + Auth + Billing + Deploy 课程的其余内容,请升级到 CoddyKit PRO。 AI Powered SaaS: Stripe + Auth + Billing + Deploy 课程共包含 4 节课。
「退款与争议处理」这节课中我会学到什么?
使用 Stripe API 发起退款、处理部分退款,并响应拒付和争议,完善一次性支付流程。 你通过在浏览器中直接运行的动手代码来练习 AI Powered SaaS: Stripe + Auth + Billing + Deploy,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 AI Powered SaaS: Stripe + Auth + Billing + Deploy 需要有经验吗?
无需任何先前经验。CoddyKit 上的 AI Powered SaaS: Stripe + Auth + Billing + Deploy 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 4 节课,共 4 节。
「退款与争议处理」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 AI Powered SaaS: Stripe + Auth + Billing + Deploy 课中编写并运行代码吗?
能。每节 AI Powered SaaS: Stripe + Auth + Billing + Deploy 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。