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

المقدمة

قم بمزامنة عملائك الذين يدفعون تلقائيًا إلى قوائم المشتركين في MailerLite عند حدوث أحداث الدفع. أضف العملاء إلى مجموعات محددة، وفعل سير العمل الأوتوماتيكي، وابقِ قوائم التسويق عبر البريد الإلكتروني محدثة ببيانات الدفع الحقيقية. MailerLite هي منصة قوية للتسويق عبر البريد الإلكتروني للنشرات الإخبارية، والحملات، والأتمتة. تساعدك هذه التكاملات على إدارة المشتركين تلقائيًا بناءً على نشاط الدفع - مثالية لتسلسلات الانضمام، وتقسيم العملاء، وحملات التسويق المستهدفة.
تتطلب هذه التكامل مفتاح API الخاص بـ MailerLite للمصادقة. يمكنك إنشاؤه من صفحة تكامل MailerLite.

البدء

1

Open the Webhook Section

في لوحة تحكم Dodo Payments، انتقل إلى Webhooks + Add Endpoint وقم بتوسيع قائمة التكاملات المنسدلة.
إضافة نقطة نهاية وقائمة التكاملات المنسدلة
2

Select MailerLite

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

Enter API Key

قم بتوفير مفتاح API الخاص بـ MailerLite في الإعدادات.
4

Configure Transformation

قم بتحرير كود التحويل لتنسيق بيانات المشتركين لواجهة MailerLite البرمجية.
5

Test & Create

اختبر باستخدام عينات الحمولة وانقر على Create لتفعيل مزامنة المشتركين.
6

Done!

ستقوم أحداث الدفع الآن بمزامنة العملاء تلقائيًا مع قوائم MailerLite الخاصة بك.

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

إضافة عميل عند الدفع الناجح

add_customer.js
function handler(webhook) {
  if (webhook.eventType === "payment.succeeded") {
    const p = webhook.payload.data;
    webhook.url = "https://connect.mailerlite.com/api/subscribers";
    webhook.payload = {
      email: p.customer.email,
      fields: {
        name: p.customer.name,
        company: p.customer.business_name || "",
        last_name: ""
      },
      groups: ["your-group-id-here"],
      status: "active"
    };
  }
  return webhook;
}

إضافة مشترك إلى مجموعات متعددة بناءً على المنتج

product_segmentation.js
function handler(webhook) {
  if (webhook.eventType === "payment.succeeded") {
    const p = webhook.payload.data;
    
    // Determine groups based on product or amount
    const groups = ["customers-group-id"];
    
    // Add to premium group if high-value purchase
    if (p.total_amount >= 10000) { // $100+
      groups.push("premium-customers-group-id");
    }
    
    webhook.url = "https://connect.mailerlite.com/api/subscribers";
    webhook.payload = {
      email: p.customer.email,
      fields: {
        name: p.customer.name,
        last_purchase_amount: (p.total_amount / 100).toFixed(2),
        last_purchase_date: new Date(webhook.payload.timestamp).toISOString().split('T')[0],
        payment_id: p.payment_id
      },
      groups: groups,
      status: "active"
    };
  }
  return webhook;
}

إضافة مشترك جديد عند تفعيل الاشتراك

subscription_subscriber.js
function handler(webhook) {
  if (webhook.eventType === "subscription.active") {
    const s = webhook.payload.data;
    webhook.url = "https://connect.mailerlite.com/api/subscribers";
    webhook.payload = {
      email: s.customer.email,
      fields: {
        name: s.customer.name,
        subscription_plan: s.product_id,
        subscription_amount: (s.recurring_pre_tax_amount / 100).toFixed(2),
        billing_frequency: s.payment_frequency_interval,
        subscription_start: new Date().toISOString().split('T')[0]
      },
      groups: ["subscribers-group-id", "active-subscriptions-group-id"],
      status: "active"
    };
  }
  return webhook;
}

تحديث مشترك عند إلغاء الاشتراك

subscription_cancelled.js
function handler(webhook) {
  if (webhook.eventType === "subscription.cancelled") {
    const s = webhook.payload.data;
    // Use PUT to update existing subscriber
    webhook.url = "https://connect.mailerlite.com/api/subscribers/" + encodeURIComponent(s.customer.email);
    webhook.method = "PUT";
    webhook.payload = {
      fields: {
        subscription_status: "cancelled",
        cancellation_date: new Date().toISOString().split('T')[0]
      },
      groups: ["churned-customers-group-id"]
    };
  }
  return webhook;
}

إضافة عميل مع حقول مخصصة

custom_fields.js
function handler(webhook) {
  if (webhook.eventType === "payment.succeeded") {
    const p = webhook.payload.data;
    webhook.url = "https://connect.mailerlite.com/api/subscribers";
    webhook.payload = {
      email: p.customer.email,
      fields: {
        name: p.customer.name,
        company: p.customer.business_name || "",
        country: p.customer.country || "",
        city: p.customer.city || "",
        phone: p.customer.phone || "",
        // Custom fields (must be created in MailerLite first)
        total_spent: (p.total_amount / 100).toFixed(2),
        customer_since: new Date().toISOString().split('T')[0],
        payment_method: p.payment_method || "unknown",
        currency: p.currency || "USD"
      },
      groups: ["paying-customers-group-id"],
      status: "active",
      subscribed_at: new Date().toISOString().replace('T', ' ').split('.')[0]
    };
  }
  return webhook;
}

تفعيل الأتمتة عبر الحدث

trigger_automation.js
function handler(webhook) {
  if (webhook.eventType === "payment.succeeded") {
    const p = webhook.payload.data;
    
    // First, ensure subscriber exists
    webhook.url = "https://connect.mailerlite.com/api/subscribers";
    webhook.payload = {
      email: p.customer.email,
      fields: {
        name: p.customer.name,
        // Add a trigger field that your automation watches
        last_payment_trigger: new Date().toISOString(),
        last_payment_amount: (p.total_amount / 100).toFixed(2)
      },
      status: "active"
    };
    
    // Tip: Create an automation in MailerLite that triggers
    // when 'last_payment_trigger' field is updated
  }
  return webhook;
}

نصائح

  • أنشئ حقولًا مخصصة في MailerLite قبل استخدامها في التحويلات الخاصة بك
  • استخدم المجموعات لتقسيم العملاء حسب المنتج، أو مستوى الخطة، أو سلوك الشراء
  • قم بإعداد سير العمل الأوتوماتيكي في MailerLite الذي يتم تفعيله عند تحديث الحقول
  • استخدم سلوك upsert (POST إلى /subscribers) لتجنب أخطاء المشتركين المكررين
  • قم بتخزين بيانات الدفع الوصفية في حقول مخصصة للحصول على رؤى أفضل عن العملاء
  • اختبر مع مجموعة صغيرة قبل التفعيل لجميع المدفوعات

إعداد الحقول المخصصة

قبل استخدام الحقول المخصصة، تحتاج إلى إنشائها في MailerLite:
  1. انتقل إلى لوحة تحكم MailerLite الخاصة بك
  2. انتقل إلى حقول المشتركين
  3. انقر على Create field وأضف حقول مثل:
    • total_spent (رقم)
    • customer_since (تاريخ)
    • subscription_plan (نص)
    • payment_method (نص)
    • last_payment_amount (رقم)

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

  • تحقق من أن مفتاح API صحيح ونشط
  • تأكد من أن عنوان البريد الإلكتروني صالح (متوافق مع RFC 2821)
  • تأكد من أن معرفات المجموعات صحيحة وموجودة في حسابك
  • ملاحظة: لا يمكن إعادة تنشيط المشتركين الذين ألغوا الاشتراك أو ارتدت رسائلهم أو تم تصنيفهم كرسائل غير مرغوب فيها عبر واجهة برمجة التطبيقات
  • تحقق من وجود الحقول المخصصة في MailerLite قبل استخدامها
  • تأكد من تطابق أسماء الحقول تمامًا (حساسية لحالة الأحرف)
  • تأكد من أن قيم الحقول تتطابق مع النوع المتوقع (نص، رقم، تاريخ)
  • واجهة برمجة تطبيقات MailerLite لها حد سرعة يبلغ 120 طلبًا في الدقيقة
  • استخدم نقاط النهاية الدُفعية إذا كنت تعالج العديد من المشتركين
  • نفذ استراتيجيات تراجع في حالات الحجم الكبير
  • تحقق من أن معرفات المجموعات هي سلاسل رقمية
  • تحقق من وجود المجموعات في حساب MailerLite الخاص بك
  • ملاحظة: سيؤدي استخدام PUT مع المجموعات إلى إزالة المشترك من المجموعات غير المدرجة

مرجع API

تقبل واجهة برمجة تطبيقات مشتركي MailerLite المعلمات الرئيسية التالية:
الوسيطالنوعمطلوبالوصف
emailstringYesعنوان بريد إلكتروني صالح (RFC 2821)
fieldsobjectNoكائن يحتوي على أزواج اسم/قيمة للحقول
fields.namestringNoالاسم الأول للمشترك
fields.last_namestringNoاسم عائلة المشترك
fields.companystringNoاسم الشركة
fields.countrystringNoالبلد
fields.citystringNoالمدينة
fields.phonestringNoرقم الهاتف
groupsarrayNoمصفوفة بمعرفات المجموعات التي يجب إضافة المشترك إليها
statusstringNoأحد الخيارات: active، unsubscribed، unconfirmed، bounced، junk
subscribed_atstringNoتاريخ بالتنسيق yyyy-MM-dd HH:mm:ss
ip_addressstringNoعنوان بروتوكول الإنترنت (IP) للمشترك
للحصول على وثائق API الكاملة، قم بزيارة مطورين MailerLite.