Add visitor-IP header setting, checkout-button toggles, and configurable timer maximum
Test and Release / test (push) Successful in 1m13s
Test and Release / release (push) Successful in 5s

- Core\ClientIp: trusted-header resolution for rate limiting behind Cloudflare/proxies
- Settings: show/hide Pay Later and Debit/Credit Card (Pay Later off by default)
- add_time rule: optional max_timer_seconds (uncapped by default), editable in rule form

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
shadowdaoandClaude Sonnet 5.5 committed 2026-11-15 11:40:06 -08:00
1 parent 4f92cfdade
commit e4d9042aba
14 files changed
+278 -16

No files matched your search

+13 -6
View File
@@ -6,7 +6,8 @@ namespace StreamGoals\Rules;
/**
* Adds seconds to a goal timer. Proportional: seconds = floor(amount * seconds_per_unit / unit_minor).
* cap_seconds_per_donation limits one donation; max_total_seconds limits the cumulative seconds
* this rule may ever add (net of reversals). The timer is an absolute ends_at timestamp.
* this rule may ever add (net of reversals). maxTimer caps the remaining time on the clock (ends_at - now);
* null = uncapped. A timer already above the cap is never shortened, it just gets 0 added. The timer is an absolute ends_at timestamp.
*/
final class AddTimeRule {
@@ -15,9 +16,10 @@ final class AddTimeRule {
public readonly int $unitMinor,
public readonly ?int $capPerDonation = null,
public readonly ?int $maxTotal = null,
public readonly string $basis = 'base'
public readonly string $basis = 'base',
public readonly ?int $maxTimer = null
) {
if ( $unitMinor <= 0 || $secondsPerUnit < 0 ) {
if ( $unitMinor <= 0 || $secondsPerUnit < 0 || ( null !== $maxTimer && $maxTimer < 1 ) ) {
throw new \InvalidArgumentException( 'Invalid add_time config.' );
}
}
@@ -28,7 +30,8 @@ final class AddTimeRule {
(int) ( $c['unit_minor'] ?? 0 ),
isset( $c['cap_seconds_per_donation'] ) ? (int) $c['cap_seconds_per_donation'] : null,
isset( $c['max_total_seconds'] ) ? (int) $c['max_total_seconds'] : null,
'total' === ( $c['basis'] ?? 'base' ) ? 'total' : 'base'
'total' === ( $c['basis'] ?? 'base' ) ? 'total' : 'base',
isset( $c['max_timer_seconds'] ) ? (int) $c['max_timer_seconds'] : null
);
}
@@ -41,14 +44,18 @@ final class AddTimeRule {
if ( null !== $this->maxTotal ) {
$delta = min( $delta, max( 0, $this->maxTotal - $addedTotal ) );
}
// Expired (or never started) timers restart from now.
$start = max( $endsAt, $now );
if ( null !== $this->maxTimer ) {
$delta = min( $delta, max( 0, $this->maxTimer - ( $start - $now ) ) );
}
$delta = max( 0, $delta );
if ( 0 === $delta ) {
return array( 'delta' => 0, 'ends_at' => $endsAt, 'added_total' => $addedTotal );
}
// Expired (or never started) timers restart from now.
return array(
'delta' => $delta,
'ends_at' => max( $endsAt, $now ) + $delta,
'ends_at' => $start + $delta,
'added_total' => $addedTotal + $delta,
);
}