$donation_data Donation data.
* @param string $campaign_name Campaign name ('' for standalone forms).
* @return string Receipt card HTML.
* @since 1.0.0
*/
public static function render_donation_receipt( $donation_data, $campaign_name = '' ) {
$currency = isset( $donation_data['currency'] ) && is_string( $donation_data['currency'] ) ? $donation_data['currency'] : 'USD';
$base_amount = isset( $donation_data['amount'] ) && is_numeric( $donation_data['amount'] ) ? (float) $donation_data['amount'] : 0.0;
$fees_covered = isset( $donation_data['fees_covered'] ) && is_numeric( $donation_data['fees_covered'] ) ? (float) $donation_data['fees_covered'] : 0.0;
$total = $base_amount + $fees_covered;
$donor_name = isset( $donation_data['donor_name'] ) && is_string( $donation_data['donor_name'] ) ? $donation_data['donor_name'] : '';
$donor_email = isset( $donation_data['donor_email'] ) && is_string( $donation_data['donor_email'] ) ? $donation_data['donor_email'] : '';
$gateway = isset( $donation_data['gateway'] ) && is_string( $donation_data['gateway'] ) ? $donation_data['gateway'] : '';
$status = isset( $donation_data['payment_status'] ) && is_string( $donation_data['payment_status'] ) ? $donation_data['payment_status'] : '';
$rows = [
[
'label' => __( 'Donor Name', 'suredonation' ),
'value' => esc_html( $donor_name ),
],
[
'label' => __( 'Donor Email', 'suredonation' ),
'value' => esc_html( $donor_email ),
],
];
if ( '' !== $campaign_name ) {
$rows[] = [
'label' => __( 'Campaign Name', 'suredonation' ),
'value' => esc_html( $campaign_name ),
];
}
$rows[] = [
'label' => __( 'Payment Status', 'suredonation' ),
'value' => self::render_payment_status_badge( $status ),
];
$rows[] = [
'label' => __( 'Payment Method', 'suredonation' ),
'value' => esc_html( self::get_payment_method_label( $gateway ) ),
];
$rows[] = [
'label' => __( 'Donation Amount', 'suredonation' ),
'value' => esc_html( Payment_Helper::format_amount( $base_amount, $currency ) ),
];
$rows_html = '';
foreach ( $rows as $row ) {
$rows_html .= sprintf(
'%1$s%2$s
',
esc_html( $row['label'] ),
$row['value']
);
}
$rows_html .= sprintf(
'%1$s%2$s
',
esc_html__( 'Donation Total', 'suredonation' ),
esc_html( Payment_Helper::format_amount( $total, $currency ) )
);
return sprintf(
'',
esc_html__( 'Donation Receipt', 'suredonation' ),
$rows_html
);
}
/**
* Default confirmation message template (receipt layout with smart tags).
*
* @return string Message HTML template.
* @since 1.0.0
*/
public static function get_default_confirmation_message() {
return '{success_badge}
'
. ''
/* translators: {donor_name} is a smart tag replaced with the donor's name. */
. esc_html__( 'Thank you {donor_name} for your Donation', 'suredonation' )
. '
'
. ''
. esc_html__( 'Your contribution means a lot. We have sent an email to your registered account along with a receipt for your donation.', 'suredonation' )
. '
{donation_receipt}';
}
/**
* Build the rendered confirmation/thank-you HTML for a donation.
*
* Resolves the form's confirmation message template against the donation's
* real data (smart tags) so the frontend can display the receipt.
*
* @param int $donation_id Donation ID.
* @return string Sanitized confirmation HTML, or '' on failure.
* @since 1.0.0
*/
public static function render_confirmation_message( $donation_id ) {
$donation = Donations::get( $donation_id );
if ( ! is_array( $donation ) ) {
return '';
}
$form_id = isset( $donation['form_id'] ) ? absint( $donation['form_id'] ) : 0;
$campaign_id = isset( $donation['campaign_id'] ) ? absint( $donation['campaign_id'] ) : 0;
$settings = self::get_form_confirmation_settings( $form_id );
$template = ! empty( $settings['message'] ) ? $settings['message'] : self::get_default_confirmation_message();
$donation_data = [
'id' => $donation_id,
'donor_name' => $donation['donor_name'] ?? '',
'donor_email' => $donation['donor_email'] ?? '',
'amount' => $donation['amount'] ?? 0,
'fees_covered' => $donation['fees_covered'] ?? 0,
'currency' => $donation['currency'] ?? Payment_Helper::get_currency(),
'gateway' => $donation['gateway'] ?? '',
'payment_status' => $donation['payment_status'] ?? '',
'transaction_id' => $donation['transaction_id'] ?? '',
'donation_type' => $donation['donation_type'] ?? 'one-time',
];
$campaign = $campaign_id ? get_post( $campaign_id ) : null;
$rendered = Email_Handler::process_smart_tags( $template, $donation_data, $campaign );
return wp_kses_post( $rendered );
}
}