Donation form: non-refundable notice under the PayPal buttons (editable in Settings)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cc5b9518e4
commit
9249b80cb6
6 files changed
+43
No files matched your search
@@ -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}
|
||||
@@ -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(',', '.'); }
|
||||
|
||||
@@ -34,6 +34,7 @@ final class SettingsPage {
|
||||
}
|
||||
echo '</select><p class="description">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.</p></td></tr>';
|
||||
echo '<tr><th scope="row"><label for="sg_min">Minimum donation (' . esc_html( $cur ) . ')</label></th><td><input type="text" id="sg_min" name="min_donation" class="small-text" inputmode="decimal" value="' . esc_attr( Format::decimal( \StreamGoals\Core\Settings::effectiveMin( (int) $s['min_donation_minor'] ), $cur ) ) . '"> <span class="description">At least ' . esc_html( Format::money( \StreamGoals\Core\Settings::HARD_MIN_MINOR, $cur ) ) . '. Visitors cannot donate less than this.</span></td></tr>';
|
||||
echo '<tr><th scope="row"><label for="sg_notice">Notice under the donation form</label></th><td><input type="text" id="sg_notice" name="donation_notice" class="large-text" maxlength="200" value="' . esc_attr( (string) $s['donation_notice'] ) . '"><p class="description">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.</p></td></tr>';
|
||||
echo '<tr><th scope="row"><label for="sg_len">Longest message</label></th><td><input type="number" id="sg_len" name="message_max_length" min="0" max="500" class="small-text" value="' . (int) $s['message_max_length'] . '"> characters <span class="description">(0 to 500; 0 = no messages)</span></td></tr>';
|
||||
echo '<tr><th scope="row">Names</th><td><fieldset>';
|
||||
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'] );
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace StreamGoals\Tests\Unit;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use StreamGoals\Admin\Input;
|
||||
use StreamGoals\Core\Settings;
|
||||
|
||||
final class DonationNoticeTest extends TestCase {
|
||||
|
||||
public function test_default_notice_says_donations_are_non_refundable(): void {
|
||||
$d = Settings::defaults();
|
||||
$this->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( '<script>alert(1)</script><b>Hi</b>', 200 ), 'no markup survives (and it is rendered as text anyway)' );
|
||||
$this->assertStringNotContainsString( '<', Input::text( '<b>Bold</b> <i>text</i>', 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 );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user