PlexySDK DOCS
Donations

Donation Web Component

Integrate Plexy's pre-built donation form with customizable styling, preset amounts, and recurring donation support

Donation Web Component

The Plexy Donation Web Component provides a ready-to-use, customizable donation form that handles payment collection, donor information, and recurring donations. It's the fastest way to start accepting donations with minimal development effort.

Features

  • Pre-built responsive design
  • Customizable preset amounts and styling
  • One-time and recurring donation support
  • Donor information collection
  • Dedication and tribute options
  • Built-in validation and error handling
  • PCI DSS compliant (SAQ-A)

Quick Start

Add the Plexy Donate JavaScript to your page:

<script src="https://js.plexy.money/v2/donate.js"></script>

Create a container where the donation form will render:

<div id="donation-form"></div>

Create the donation form with your configuration:

const donationForm = Plexy.createDonationForm('#donation-form', {
  publicKey: 'pb_live_your_public_key',
  campaignId: 'camp_spring_2026',
  amounts: [1000, 2500, 5000, 10000, 25000],
  currency: 'KZT',
  allowCustomAmount: true,
  allowRecurring: true,
  onSuccess: (donation) => {
    console.log('Donation completed:', donation.id);
    window.location.href = '/thank-you?id=' + donation.id;
  },
  onError: (error) => {
    console.error('Donation failed:', error.message);
  }
});

Configuration Options

Basic Configuration

OptionTypeRequiredDescription
publicKeystringYesYour Plexy public API key
campaignIdstringNoCampaign identifier for tracking
amountsnumber[]NoPreset donation amounts (in minor units)
currencystringNoThree-letter currency code (default: KZT)
defaultAmountnumberNoPre-selected amount
allowCustomAmountbooleanNoAllow donors to enter custom amounts (default: true)
minimumAmountnumberNoMinimum donation amount
maximumAmountnumberNoMaximum donation amount

Recurring Donations

OptionTypeDefaultDescription
allowRecurringbooleanfalseEnable recurring donation option
recurringIntervalsstring[]['monthly']Available intervals: weekly, monthly, quarterly, annually
defaultRecurringbooleanfalsePre-select recurring option

Donor Information

OptionTypeDefaultDescription
collectAddressbooleanfalseCollect donor's mailing address
collectPhonebooleanfalseCollect donor's phone number
requireEmailbooleantrueRequire email address
allowAnonymousbooleantrueAllow anonymous donations
allowDedicationbooleanfalseEnable "In honor/memory of" option

Styling

OptionTypeDescription
themestringlight or dark
primaryColorstringPrimary brand color (hex)
borderRadiusstringBorder radius for elements
fontFamilystringFont family for the form

Full Example

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Support Our Cause</title>
    <script src="https://js.plexy.money/v2/donate.js"></script>
  </head>
  <body>
    <div class="container">
      <h1>Make a Donation</h1>
      <p>Your support helps us continue our mission.</p>
      <div id="donation-form"></div>
    </div>

    <script>
      const donationForm = Plexy.createDonationForm('#donation-form', {
        // Authentication
        publicKey: 'pb_live_your_public_key',

        // Campaign
        campaignId: 'camp_annual_fund_2026',

        // Amounts
        amounts: [2500, 5000, 10000, 25000, 50000],
        currency: 'KZT',
        defaultAmount: 5000,
        allowCustomAmount: true,
        minimumAmount: 500,

        // Recurring
        allowRecurring: true,
        recurringIntervals: ['monthly', 'annually'],
        defaultRecurring: false,

        // Donor info
        collectAddress: true,
        collectPhone: false,
        requireEmail: true,
        allowAnonymous: true,
        allowDedication: true,

        // Styling
        theme: 'light',
        primaryColor: '#6366f1',
        borderRadius: '8px',
        fontFamily: 'Inter, system-ui, sans-serif',

        // Callbacks
        onSuccess: (donation) => {
          // Redirect to thank you page
          window.location.href = `/thank-you?donation_id=${donation.id}`;
        },
        onError: (error) => {
          // Show error to user
          alert('Donation failed: ' + error.message);
        },
        onCancel: () => {
          console.log('Donation cancelled by user');
        },
      });
    </script>
  </body>
</html>

Customizing Appearance

Using CSS Variables

The donation form exposes CSS variables for customization:

:root {
  --plexy-donate-primary: #6366f1;
  --plexy-donate-primary-hover: #4f46e5;
  --plexy-donate-background: #ffffff;
  --plexy-donate-text: #1f2937;
  --plexy-donate-text-muted: #6b7280;
  --plexy-donate-border: #e5e7eb;
  --plexy-donate-error: #ef4444;
  --plexy-donate-success: #22c55e;
  --plexy-donate-radius: 8px;
  --plexy-donate-font: 'Inter', system-ui, sans-serif;
}

Custom CSS Classes

Target specific elements with these CSS classes:

/* Container */
.plexy-donate-form {
}

/* Amount buttons */
.plexy-donate-amounts {
}
.plexy-donate-amount-btn {
}
.plexy-donate-amount-btn--selected {
}
.plexy-donate-amount-custom {
}

/* Recurring toggle */
.plexy-donate-recurring {
}
.plexy-donate-recurring-toggle {
}
.plexy-donate-recurring-interval {
}

/* Donor info */
.plexy-donate-donor-info {
}
.plexy-donate-input {
}
.plexy-donate-input--error {
}

/* Dedication */
.plexy-donate-dedication {
}

/* Submit button */
.plexy-donate-submit {
}
.plexy-donate-submit--loading {
}

/* Messages */
.plexy-donate-error-message {
}
.plexy-donate-success-message {
}

Dark Theme Example

const donationForm = Plexy.createDonationForm('#donation-form', {
  publicKey: 'pb_live_your_public_key',
  theme: 'dark',
  primaryColor: '#a78bfa',
});
/* Additional dark theme customization */
.dark .plexy-donate-form {
  --plexy-donate-background: #1f2937;
  --plexy-donate-text: #f9fafb;
  --plexy-donate-border: #374151;
}

Handling Donations

Success Callback

The onSuccess callback receives the completed donation object:

onSuccess: (donation) => {
  console.log('Donation ID:', donation.id);
  console.log('Amount:', donation.amount.value);
  console.log('Donor:', donation.donor.email);
  console.log('Recurring:', donation.recurring?.interval);
  console.log('Receipt URL:', donation.tax_receipt_url);

  // Track in analytics
  analytics.track('donation_completed', {
    donation_id: donation.id,
    amount: donation.amount.value,
    currency: donation.amount.currency,
    campaign: donation.campaign_id,
    recurring: !!donation.recurring,
  });

  // Redirect to thank you page
  window.location.href = `/thank-you?id=${donation.id}`;
};

Error Callback

Handle errors gracefully:

onError: (error) => {
  console.error('Donation error:', error.code, error.message);

  switch (error.code) {
    case 'card_declined':
      showMessage('Your card was declined. Please try a different card.');
      break;
    case 'insufficient_funds':
      showMessage('Insufficient funds. Please try a smaller amount.');
      break;
    case 'invalid_card':
      showMessage('Invalid card details. Please check and try again.');
      break;
    case 'network_error':
      showMessage('Network error. Please check your connection.');
      break;
    default:
      showMessage('An error occurred. Please try again.');
  }
};

Form Methods

Programmatic Control

const donationForm = Plexy.createDonationForm('#donation-form', config);

// Set amount programmatically
donationForm.setAmount(10000);

// Set recurring interval
donationForm.setRecurring('monthly');

// Pre-fill donor information
donationForm.setDonorInfo({
  email: 'donor@example.com',
  firstName: 'Jane',
  lastName: 'Smith',
});

// Submit the form programmatically
donationForm.submit();

// Reset the form
donationForm.reset();

// Destroy the form
donationForm.destroy();

Event Listeners

// Listen for amount changes
donationForm.on('amountChange', (amount) => {
  console.log('Amount changed to:', amount);
});

// Listen for recurring toggle
donationForm.on('recurringChange', (isRecurring, interval) => {
  console.log('Recurring:', isRecurring, interval);
});

// Listen for validation errors
donationForm.on('validationError', (errors) => {
  console.log('Validation errors:', errors);
});

// Listen for form ready
donationForm.on('ready', () => {
  console.log('Donation form loaded');
});

React Integration

import { useEffect, useRef } from 'react';

function DonationForm({ campaignId, onSuccess }) {
  const containerRef = useRef(null);
  const formRef = useRef(null);

  useEffect(() => {
    // Load Plexy script
    const script = document.createElement('script');
    script.src = 'https://js.plexy.money/v2/donate.js';
    script.onload = () => {
      formRef.current = window.Plexy.createDonationForm(containerRef.current, {
        publicKey: process.env.NEXT_PUBLIC_PLEXY_KEY,
        campaignId,
        amounts: [2500, 5000, 10000, 25000],
        allowRecurring: true,
        onSuccess,
        onError: (error) => console.error(error),
      });
    };
    document.body.appendChild(script);

    return () => {
      if (formRef.current) {
        formRef.current.destroy();
      }
      document.body.removeChild(script);
    };
  }, [campaignId, onSuccess]);

  return <div ref={containerRef} />;
}

export default DonationForm;

Localization

The donation form supports multiple languages:

const donationForm = Plexy.createDonationForm('#donation-form', {
  publicKey: 'pb_live_your_public_key',
  locale: 'ru', // 'en', 'ru', 'kk'

  // Or provide custom labels
  labels: {
    title: 'Make a Donation',
    amountLabel: 'Donation Amount',
    customAmountPlaceholder: 'Enter amount',
    recurringLabel: 'Make this a recurring donation',
    emailLabel: 'Email Address',
    firstNameLabel: 'First Name',
    lastNameLabel: 'Last Name',
    submitButton: 'Donate Now',
    processingButton: 'Processing...',
    successMessage: 'Thank you for your donation!',
    errorMessage: 'Something went wrong. Please try again.',
  },
});

Security Considerations

The Donation Web Component is PCI DSS compliant (SAQ-A). Card data is collected in a secure iframe and never touches your servers.

  • All card data is tokenized before submission
  • Form uses HTTPS-only communication
  • Built-in CSRF protection

Next Steps

On this page