#How can I obtain the Retry Payment Link when a subscription creation fails due to payment issues?
1 messages · Page 1 of 1 (latest)
If a subscription creation fails due to a mandate or payment failure, the subscription.failed webhook will be triggered. This event specifically indicates that the subscription creation failed during the mandate creation process【4:0†source】.
To address the situation by triggering an email to the customer with a retry payment link, you can use the payment.failed webhook to notify the customer. Here's how you can implement this:
- Webhook Handling: Set up your webhook endpoint to listen for
payment.failedevents. - Email Trigger: Upon receiving a
payment.failedevent, use a service like SendGrid or Resend to send an email to the customer. - Email Content: The email should include a message about the payment failure and a link for the customer to retry the payment. You can construct the retry link using the payment ID or a similar identifier.
Here's a basic example of how you could structure the email notification using JavaScript:
function handler(webhook) {
if (webhook.eventType === "payment.failed") {
const p = webhook.payload.data;
webhook.url = "https://api.your-email-service.com/send";
webhook.payload = {
from: "[email protected]",
to: [p.customer.email],
subject: "Payment Failed - Action Required",
html: `
<h2>Payment Failed</h2>
<p>Hi ${p.customer.name},</p>
<p>We were unable to process your payment of $${(p.total_amount / 100).toFixed(2)}.</p>
<ul>
<li><strong>Payment ID:</strong> ${p.payment_id}</li>
<li><strong>Amount:</strong> $${(p.total_amount / 100).toFixed(2)}</li>
<li><strong>Error:</strong> ${p.error_message || "Payment processing failed"}</li>
</ul>
<p>Please update your payment method or contact support for assistance.</p>
<a href="https://yourdomain.com/retry-payment/${p.payment_id}">Retry Payment</a>
, text: Payment Failed: We couldn't process your $${(p.total_amount / 100).toFixed(2)} payment. Please update your payment method.`
};
}
return webhook;
}
This approach ensures that your customers are informed promptly and have a clear path to resolve the payment issue【4:2†source】【4:6†source】.
### Helpful Links
- [Dodo Payments Webhook Events Guide](https://docs.dodopayments.com/developer-resources/webhooks/intents/webhook-events-guide)
- [Integrating Webhooks with Dodo Payments](https://docs.dodopayments.com/developer-resources/integration-guide#implementing-webhooks)
- [Using SendGrid for Transactional Emails](https://docs.dodopayments.com/integrations/sendgrid)
Understand the different webhook events triggered by Dodo Payments during payment, refund, subscription, dispute, and license key activities
Send transactional emails based on Dodo Payments events using SendGrid's Mail Send API.
https://yourdomain.com/retry-payment/${p.payment_id}
Here for the retry payment link, for the testing and production what will be yourdomain.com value
@rugged cypress
You can create a new payment link and share it to your customer.
Is there any resource to make payment link