الانتقال إلى المحتوى الرئيسي

المقدمة

قم بإرسال رسائل بريد إلكتروني معاملات احترافية تلقائيًا عند حدوث أحداث الدفع. قم بتسليم تأكيدات الدفع، وتحديثات الاشتراك، والإشعارات المهمة من خلال بنية البريد الإلكتروني الموثوقة من Resend ومعدلات التسليم الممتازة.
يتطلب هذا التكامل مفتاح واجهة برمجة تطبيقات Resend للمصادقة.

البدء

1

Open the Webhook Section

في لوحة تحكم Dodo Payments، انتقل إلى Webhooks → + Add Endpoint ووسع قائمة التكاملات.
Add Endpoint and integrations dropdown
2

Select Resend

اختر بطاقة التكامل Resend.
3

Enter API Key

قدم مفتاح واجهة برمجة تطبيقات Resend في الإعدادات.
4

Configure Transformation

حرر كود التحويل لتنسيق الرسائل الإلكترونية وفقًا لواجهة برمجة تطبيقات Resend.
5

Test & Create

اختبر باستخدام بيانات نموذجية وانقر على Create لتفعيل إرسال البريد الإلكتروني.
6

Done!

🎉 ستؤدي أحداث الدفع الآن إلى تشغيل رسائل بريد إلكتروني معاملاتية عبر Resend تلقائيًا.

أمثلة على كود التحويل

بريد تأكيد الدفع

payment_confirmation.js
function handler(webhook) {
  if (webhook.eventType === "payment.succeeded") {
    const p = webhook.payload.data;
    webhook.url = "https://api.resend.com/emails";
    webhook.payload = {
      from: "payments@yourdomain.com",
      to: [p.customer.email],
      subject: "Payment Confirmation - $" + (p.total_amount / 100).toFixed(2),
      html: `
        <h2>Payment Successful!</h2>
        <p>Hi ${p.customer.name},</p>
        <p>Your payment of $${(p.total_amount / 100).toFixed(2)} has been processed successfully.</p>
        <ul>
          <li><strong>Payment ID:</strong> ${p.payment_id}</li>
          <li><strong>Amount:</strong> $${(p.total_amount / 100).toFixed(2)}</li>
          <li><strong>Date:</strong> ${new Date(webhook.payload.timestamp).toLocaleDateString()}</li>
          <li><strong>Method:</strong> ${p.payment_method || "Unknown"}</li>
        </ul>
        <p>Thank you for your business!</p>
      `,
      text: `Payment Successful! Your payment of $${(p.total_amount / 100).toFixed(2)} has been processed. Payment ID: ${p.payment_id}`
    };
  }
  return webhook;
}

بريد الترحيب بالاشتراك

subscription_welcome.js
function handler(webhook) {
  if (webhook.eventType === "subscription.active") {
    const s = webhook.payload.data;
    webhook.url = "https://api.resend.com/emails";
    webhook.payload = {
      from: "welcome@yourdomain.com",
      to: [s.customer.email],
      subject: "Welcome to Your Subscription!",
      html: `
        <h2>Welcome to Your Subscription!</h2>
        <p>Hi ${s.customer.name},</p>
        <p>Your subscription has been activated successfully.</p>
        <ul>
          <li><strong>Subscription ID:</strong> ${s.subscription_id}</li>
          <li><strong>Product:</strong> ${s.product_id}</li>
          <li><strong>Amount:</strong> $${(s.recurring_pre_tax_amount / 100).toFixed(2)}/${s.payment_frequency_interval}</li>
          <li><strong>Next Billing:</strong> ${new Date(s.next_billing_date).toLocaleDateString()}</li>
        </ul>
        <p>You can manage your subscription anytime from your account dashboard.</p>
      `,
      text: `Welcome! Your subscription is now active. Amount: $${(s.recurring_pre_tax_amount / 100).toFixed(2)}/${s.payment_frequency_interval}`
    };
  }
  return webhook;
}

إشعار فشل الدفع

payment_failure.js
function handler(webhook) {
  if (webhook.eventType === "payment.failed") {
    const p = webhook.payload.data;
    webhook.url = "https://api.resend.com/emails";
    webhook.payload = {
      from: "support@yourdomain.com",
      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/update-payment">Update Payment Method</a>
      `,
      text: `Payment Failed: We couldn't process your $${(p.total_amount / 100).toFixed(2)} payment. Please update your payment method.`
    };
  }
  return webhook;
}

نصائح

  • استخدم نطاقات المرسلين المعتمدة لتحسين قابلية التسليم
  • قم بتضمين كل من إصدارات HTML والنص من رسائل البريد الإلكتروني
  • خصص المحتوى باستخدام بيانات العملاء
  • استخدم عناوين موضوع واضحة وموجهة للعمل
  • قم بتضمين روابط إلغاء الاشتراك للامتثال
  • اختبر قوالب البريد الإلكتروني قبل الذهاب مباشرة

استكشاف الأخطاء وإصلاحها

  • تحقق من صحة مفتاح واجهة برمجة التطبيقات وأنه نشط
  • تأكد من أن النطاق المرسل معتمد في Resend
  • تأكد من أن عناوين البريد الإلكتروني للمستلمين صالحة
  • راجع حدود الإرسال والحصص في Resend
  • تحقق من تطابق بنية JSON مع تنسيق واجهة برمجة تطبيقات Resend
  • تأكد من وجود جميع الحقول المطلوبة
  • تأكد من تنسيق المحتوى HTML بشكل صحيح
  • تحقق من أن عنوان البريد الإلكتروني للمرسل معتمد