From 9249b80cb623d6595e92d9937e13b60f49b8d26e Mon Sep 17 00:00:00 2001 From: Josh Knapp Date: Sun, 15 Nov 2026 13:34:54 -0800 Subject: [PATCH] Donation form: non-refundable notice under the PayPal buttons (editable in Settings) Co-Authored-By: Claude Sonnet 5.5 --- assets/donate/donate.css | 2 ++ assets/donate/donate.js | 1 + includes/Admin/SettingsPage.php | 2 ++ includes/Core/Settings.php | 1 + includes/Rest/DonateController.php | 1 + tests/Unit/DonationNoticeTest.php | 36 ++++++++++++++++++++++++++++++ 6 files changed, 43 insertions(+) create mode 100644 tests/Unit/DonationNoticeTest.php diff --git a/assets/donate/donate.css b/assets/donate/donate.css index c2e2643..281b65c 100644 --- a/assets/donate/donate.css +++ b/assets/donate/donate.css @@ -40,3 +40,5 @@ .sg-donate .sg-next-unlock[hidden]{display:none} .sg-donate .sg-presets button.sg-action{padding-right:2.2em} .sg-donate .sg-presets.sg-actions{padding:0 5px} + +.sg-donate .sg-notice{margin:.6rem 0 0;font-size:.9em;line-height:1.4;opacity:.85;overflow-wrap:anywhere} diff --git a/assets/donate/donate.js b/assets/donate/donate.js index 29405cb..ba81190 100644 --- a/assets/donate/donate.js +++ b/assets/donate/donate.js @@ -121,6 +121,7 @@ root.appendChild(row([total])); root.appendChild(status); // messages sit above the PayPal buttons, next to the form fields root.appendChild(buttons); + if (C.notice) { root.appendChild(el('p', { 'class': 'sg-notice', text: String(C.notice) })); } // e.g. "Donations are non-refundable." right where the donor pays function say(text, cls) { status.textContent = text || ''; status.className = 'sg-msg' + (cls ? ' ' + cls : ''); } function amountStr() { return amount.value.trim().replace(',', '.'); } diff --git a/includes/Admin/SettingsPage.php b/includes/Admin/SettingsPage.php index a7953ae..9f51291 100644 --- a/includes/Admin/SettingsPage.php +++ b/includes/Admin/SettingsPage.php @@ -34,6 +34,7 @@ final class SettingsPage { } 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 '

Shown right under the PayPal buttons so donors see it before paying. Plain text, up to 200 characters. The default says donations are non-refundable. Leave it empty to hide the notice.

'; echo ' characters (0 to 500; 0 = no messages)'; echo 'Names
'; foreach ( self::POLICIES as $k => $l ) { @@ -147,6 +148,7 @@ final class SettingsPage { } $upd['funding_card'] = ! empty( $post['funding_card'] ); $upd['funding_paylater'] = ! empty( $post['funding_paylater'] ); + $upd['donation_notice'] = Input::text( $post['donation_notice'] ?? '', 200 ); $upd['moderate_messages'] = ! empty( $post['moderate_messages'] ); $upd['profanity_filter'] = ! empty( $post['profanity_filter'] ); $upd['profanity_use_builtin'] = ! empty( $post['profanity_use_builtin'] ); diff --git a/includes/Core/Settings.php b/includes/Core/Settings.php index c897c55..e6e91b0 100644 --- a/includes/Core/Settings.php +++ b/includes/Core/Settings.php @@ -34,6 +34,7 @@ final class Settings { 'profanity_words' => '', // streamer's extra words, one per line 'message_max_length' => 200, 'min_donation_minor' => 100, + 'donation_notice' => 'Donations are non-refundable.', // shown under the donation form; empty hides it 'overlay_token' => '', 'visitor_ip_header' => 'auto', // auto | '' (direct) | cloudflare | real_ip | forwarded (see Core\ClientIp) 'funding_paylater' => false, // show PayPal "Pay Later" button diff --git a/includes/Rest/DonateController.php b/includes/Rest/DonateController.php index 96934f3..a56d80e 100644 --- a/includes/Rest/DonateController.php +++ b/includes/Rest/DonateController.php @@ -188,6 +188,7 @@ final class DonateController { 'policy' => (string) $s['anonymity_policy'], 'minMinor' => \StreamGoals\Core\Settings::effectiveMin( (int) $s['min_donation_minor'] ), 'messageMax' => min( 500, (int) $s['message_max_length'] ), + 'notice' => (string) ( $s['donation_notice'] ?? '' ), 'disableFunding' => array_values( array_filter( array( empty( $s['funding_paylater'] ) ? 'paylater' : '', empty( $s['funding_card'] ) ? 'card' : '' ) ) ), 'goals' => $goals, 'i18n' => array( diff --git a/tests/Unit/DonationNoticeTest.php b/tests/Unit/DonationNoticeTest.php new file mode 100644 index 0000000..e896779 --- /dev/null +++ b/tests/Unit/DonationNoticeTest.php @@ -0,0 +1,36 @@ +assertArrayHasKey( 'donation_notice', $d ); + $this->assertStringContainsString( 'non-refundable', strtolower( (string) $d['donation_notice'] ) ); + } + + public function test_admin_input_is_plain_text_and_length_capped(): void { + $this->assertSame( 'No refunds, sorry.', Input::text( ' No refunds, sorry. ', 200 ) ); + $this->assertStringNotContainsString( '<', Input::text( 'Hi', 200 ), 'no markup survives (and it is rendered as text anyway)' ); + $this->assertStringNotContainsString( '<', Input::text( 'Bold text', 200 ) ); + $this->assertSame( 200, strlen( Input::text( str_repeat( 'a', 500 ), 200 ) ) ); + $this->assertSame( '', Input::text( "\x00\x1F", 200 ) ); + } + + public function test_form_script_renders_the_notice_with_textcontent_only(): void { + $js = (string) file_get_contents( dirname( __DIR__, 2 ) . '/assets/donate/donate.js' ); + $this->assertMatchesRegularExpression( '/if \(C\.notice\).*sg-notice.*text: String\(C\.notice\)/s', $js, 'notice must be rendered as text, never HTML' ); + $this->assertStringNotContainsString( 'innerHTML', $js ); + } + + public function test_form_config_passes_the_notice_through(): void { + $php = (string) file_get_contents( dirname( __DIR__, 2 ) . '/includes/Rest/DonateController.php' ); + $this->assertStringContainsString( "'notice' => (string) ( \$s['donation_notice'] ?? '' )", $php ); + } +}