Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

1.1 KB
Raw Blame
import { prisma } from "@/lib/prisma";
import Stripe from "stripe";
import { processDomainRenewalFailure } from "./utils/process-domain-renewal-failure";

export async function paymentIntentRequiresAction(
  event: Stripe.PaymentIntentRequiresActionEvent,
) {
  const { transfer_group: invoiceId } = event.data.object;

  if (!invoiceId) {
    return "No transfer group found, skipping...";
  }

  let invoice = await prisma.invoice.findUnique({
    where: {
      id: invoiceId,
    },
  });

  if (!invoice) {
    return `Invoice with transfer group ${invoiceId} not found.`;
  }

  invoice = await prisma.invoice.update({
    where: {
      id: invoiceId,
    },
    data: {
      status: "failed",
      failedReason:
        "Your payment requires additional authentication to complete.",
      failedAttempts: {
        increment: 1,
      },
    },
  });

  if (invoice.type === "domainRenewal") {
    await processDomainRenewalFailure({ invoice });
    return `Processed domain renewal failure for invoice ${invoice.id}.`;
  }

  return `Unsupported invoice type (${invoice.type}), skipping...`;
}