diff --git a/assets/admin/rules.js b/assets/admin/rules.js index 940547d..72185e2 100644 --- a/assets/admin/rules.js +++ b/assets/admin/rules.js @@ -42,7 +42,8 @@ if ( ! c.unit_minor ) { return null; } var d = Math.floor( amount * c.seconds_per_unit / c.unit_minor ); if ( c.cap_seconds_per_donation != null ) { d = Math.min( d, c.cap_seconds_per_donation ); } - return d > 0 ? 'Timer: +' + duration( d ) : 'Timer: no time added'; + var note = c.max_timer_seconds != null ? ' (the timer never goes above ' + duration( c.max_timer_seconds ) + ')' : ''; + return ( d > 0 ? 'Timer: +' + duration( d ) : 'Timer: no time added' ) + note; } if ( rule.type === 'counter' ) { if ( ! c.per_minor ) { return null; } @@ -74,6 +75,7 @@ /* Type switch + preview of the rule being edited. */ if ( ! form ) { return; } + var typeSel = document.getElementById( 'sg-rule-type' ); var typeHidden = form.querySelector( 'input[name="type"]' ); var formPrev = document.getElementById( 'sg-form-preview' ); @@ -93,7 +95,8 @@ var n = parseInt( val( g, 'time_amount' ), 10 ); if ( ! unit || ! n ) { return null; } var cap = parseInt( val( g, 'cap_minutes' ), 10 ); - return { type: type, config: { seconds_per_unit: n * mult, unit_minor: unit, cap_seconds_per_donation: cap > 0 ? cap * 60 : null } }; + var clock = parseInt( val( g, 'max_timer_minutes' ), 10 ); + return { type: type, config: { seconds_per_unit: n * mult, unit_minor: unit, cap_seconds_per_donation: cap > 0 ? cap * 60 : null, max_timer_seconds: clock > 0 ? clock * 60 : null } }; } if ( type === 'counter' ) { var step = parseInt( val( g, 'step' ), 10 ); diff --git a/assets/donate/donate.js b/assets/donate/donate.js index 4b88671..abed65f 100644 --- a/assets/donate/donate.js +++ b/assets/donate/donate.js @@ -41,7 +41,8 @@ var s = document.createElement('script'); s.id = 'sg-paypal-sdk'; s.src = 'https://www.paypal.com/sdk/js?client-id=' + encodeURIComponent(C.clientId) + - '¤cy=' + encodeURIComponent(currency) + '&intent=capture&components=buttons'; + '¤cy=' + encodeURIComponent(currency) + '&intent=capture&components=buttons' + + ((C.disableFunding && C.disableFunding.length) ? '&disable-funding=' + encodeURIComponent(C.disableFunding.join(',')) : ''); s.onload = function () { window.paypal ? resolve(window.paypal) : reject(new Error(T.sdkError)); }; s.onerror = function () { reject(new Error(T.sdkError)); }; document.head.appendChild(s); diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 6861b63..fa0fb9c 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -37,9 +37,9 @@ Rules engine entry point (Agent 2 implements, Agent 1 calls after a capture is r Rules\Engine::applyDonation(Donation $d): void; // idempotent via sg_rule_events UNIQUE Rules\Engine::reverseDonation(Donation $d): void; // honors per-rule "reverse on refund" ``` -Rule `config` examples: +Rule `config` examples (`max_total_seconds` caps what one rule has added over time; `max_timer_seconds` caps how long the timer can ever get, null = uncapped): ```json -{"type":"add_time","seconds_per_unit":60,"unit_minor":100,"cap_seconds_per_donation":null,"max_total_seconds":null,"basis":"base"} +{"type":"add_time","seconds_per_unit":60,"unit_minor":100,"cap_seconds_per_donation":null,"max_total_seconds":null,"max_timer_seconds":null,"basis":"base"} {"type":"counter","step":1,"per_minor":1000,"carry_over":true,"basis":"base","label":"Pies"} {"type":"bonus","min_minor":5000,"event":"big_donation"} ``` diff --git a/includes/Admin/GoalsPage.php b/includes/Admin/GoalsPage.php index 919cfb0..8f51570 100644 --- a/includes/Admin/GoalsPage.php +++ b/includes/Admin/GoalsPage.php @@ -249,9 +249,10 @@ final class GoalsPage { echo ''; } echo ' to the timer for every ' . esc_html( $cur ) . ' donated.
'; - echo 'Leave empty for no limit. For example, 1440 means the clock never shows more than 24 hours.
'; echo 'Add to the counter for every ' . esc_html( $cur ) . ' donated.
'; diff --git a/includes/Admin/RuleConfig.php b/includes/Admin/RuleConfig.php index e0e6072..cba5536 100644 --- a/includes/Admin/RuleConfig.php +++ b/includes/Admin/RuleConfig.php @@ -46,6 +46,7 @@ final class RuleConfig { } $cap = self::optionalMinutes( $in['cap_minutes'] ?? '', 'The per-donation limit', $errors ); $max = self::optionalMinutes( $in['max_total_minutes'] ?? '', 'The total limit', $errors ); + $clk = self::optionalMinutes( $in['max_timer_minutes'] ?? '', 'The longest the timer can get', $errors ); if ( $errors ) { return array( 'config' => null, 'errors' => $errors ); } @@ -59,6 +60,7 @@ final class RuleConfig { 'unit_minor' => $unit, 'cap_seconds_per_donation' => $cap, 'max_total_seconds' => $max, + 'max_timer_seconds' => $clk, 'basis' => $basis, ), 'errors' => array(), @@ -128,6 +130,9 @@ final class RuleConfig { if ( isset( $c['max_total_seconds'] ) ) { $s .= ', ' . Format::duration( (int) $c['max_total_seconds'] ) . ' in total'; } + if ( isset( $c['max_timer_seconds'] ) ) { + $s .= ', up to ' . Format::duration( (int) $c['max_timer_seconds'] ) . ' on the clock'; + } return $s; case 'counter': $label = (string) ( $c['label'] ?? '' ); @@ -158,6 +163,9 @@ final class RuleConfig { if ( 'add_time' === $type ) { $res = AddTimeRule::fromConfig( $cfg )->apply( $d, 0, 0, 0 ); $lines[] = $res['delta'] > 0 ? 'Timer: +' . Format::duration( $res['delta'] ) : 'Timer: no time added'; + if ( isset( $cfg['max_timer_seconds'] ) ) { + $lines[ count( $lines ) - 1 ] .= ' (the timer never goes above ' . Format::duration( (int) $cfg['max_timer_seconds'] ) . ')'; + } } elseif ( 'counter' === $type ) { $res = CounterRule::fromConfig( $cfg )->apply( $d, 0, 0 ); $lbl = (string) ( $cfg['label'] ?? '' ); @@ -182,6 +190,7 @@ final class RuleConfig { $f['unit_amount'] = Format::decimal( (int) ( $c['unit_minor'] ?? 100 ), $currency ); $f['cap_minutes'] = isset( $c['cap_seconds_per_donation'] ) ? (string) intdiv( (int) $c['cap_seconds_per_donation'], 60 ) : ''; $f['max_total_minutes'] = isset( $c['max_total_seconds'] ) ? (string) intdiv( (int) $c['max_total_seconds'], 60 ) : ''; + $f['max_timer_minutes'] = isset( $c['max_timer_seconds'] ) ? (string) intdiv( (int) $c['max_timer_seconds'], 60 ) : ''; } elseif ( 'counter' === $type ) { $f['step'] = (int) ( $c['step'] ?? 1 ); $f['unit_amount'] = Format::decimal( (int) ( $c['per_minor'] ?? 1000 ), $currency ); diff --git a/includes/Admin/SettingsPage.php b/includes/Admin/SettingsPage.php index 5e9afa9..37f8c58 100644 --- a/includes/Admin/SettingsPage.php +++ b/includes/Admin/SettingsPage.php @@ -47,6 +47,17 @@ final class SettingsPage { echo ''; echo '| Payment options | ';
+ echo ' '; + echo ''; + echo ' The PayPal button is always shown. Which extra buttons appear can also depend on the donor\'s country. |
|---|
Donation forms limit how fast one visitor can start payments (to stop abuse). If your site is behind Cloudflare or another proxy, choose it here so each visitor is counted separately; otherwise everyone looks like the same visitor and a busy moment, like a raid, could block donations. Only choose a proxy option if all traffic to your site really goes through it. |
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 '| % |