'Donors choose: they can give a name or stay anonymous',
'require_name' => 'Donors must give a name',
'force_anonymous' => 'Everyone is anonymous (no names are collected or stored)',
);
public static function render(): void {
Admin::open( 'StreamGoals settings' );
$s = Settings::all();
$cur = Admin::currency();
echo '
One currency for the whole site. It applies to goals you create from now on; existing goals keep their currency. Check the fixed fee below after changing it.
';
echo '
At least ' . esc_html( Format::money( \StreamGoals\Core\Settings::HARD_MIN_MINOR, $cur ) ) . '. Visitors cannot donate less than this.
';
echo '
characters (0 to 500; 0 = no messages)
';
echo '
Names
Anonymous donors\' names are never saved.
';
echo '
Messages
';
echo '
Moderation
';
echo '
Profanity filter
';
echo '';
echo '
';
echo '
PayPal fee estimate
';
echo '
When a donor chooses "cover the fees", the form adds the estimated PayPal fee so you receive the amount they intended. The defaults (3.49% + $0.49) are US domestic estimates. Fees for international (cross-border) payments and currency conversion are higher and are not included, so you may receive slightly less than expected in those cases. Check PayPal\'s current fee page for your country and adjust.
';
echo '
%
';
echo '
';
echo '';
Admin::close();
}
public static function handleSave(): void {
Admin::guard( 'sg_settings_save' );
$post = Admin::post_raw();
$back = Admin::url( 'streamgoals-settings' );
$errors = array();
$cur = Format::currency( $post['currency'] ?? 'USD' );
$upd = array();
$min = Input::amountToMinor( $post['min_donation'] ?? '', $cur );
if ( null === $min || $min < \StreamGoals\Core\Settings::HARD_MIN_MINOR ) {
$errors[] = 'Minimum donation must be at least ' . Format::money( \StreamGoals\Core\Settings::HARD_MIN_MINOR, $cur ) . '. PayPal\'s fixed fee makes smaller donations lose money.';
} else {
$upd['min_donation_minor'] = $min;
}
$len = Input::int( $post['message_max_length'] ?? '', 0, 500 );
if ( null === $len ) {
$errors[] = 'Longest message must be a number from 0 to 500.';
} else {
$upd['message_max_length'] = $len;
}
$pct = Input::percentToBps( $post['fee_percent'] ?? '' );
if ( null === $pct ) {
$errors[] = 'Percentage fee must be between 0 and 30 (for example 3.49).';
} else {
$upd['fee_percent_bps'] = $pct;
}
$fix = Input::amountToMinor( $post['fee_fixed'] ?? '', $cur );
if ( null === $fix || $fix > 10000 ) {
$errors[] = 'Fixed fee must be a small amount (for example 0.49).';
} else {
$upd['fee_fixed_minor'] = $fix;
}
$pol = isset( $post['anonymity_policy'] ) && is_string( $post['anonymity_policy'] ) ? $post['anonymity_policy'] : '';
if ( ! isset( self::POLICIES[ $pol ] ) ) {
$errors[] = 'Please choose a names option.';
} else {
$upd['anonymity_policy'] = $pol;
}
$upd['moderate_messages'] = ! empty( $post['moderate_messages'] );
$upd['profanity_filter'] = ! empty( $post['profanity_filter'] );
$upd['profanity_use_builtin'] = ! empty( $post['profanity_use_builtin'] );
$upd['profanity_words'] = Input::words( isset( $post['profanity_words'] ) && is_string( $post['profanity_words'] ) ? $post['profanity_words'] : '' );
Settings::update( $upd );
update_option( 'sg_currency', $cur, false ); // Settings has no currency key, so it lives in its own option.
if ( $errors ) {
Admin::redirect( $back, 'warning', 'Some settings were not saved: ' . implode( ' ', $errors ) . ' Everything else was saved.' );
}
Admin::redirect( $back, 'success', 'Settings saved.' );
}
}