Files
shadowdaoandClaude Sonnet 5.5 e4d9042aba
Test and Release / test (push) Successful in 1m13s
Test and Release / release (push) Successful in 5s
Add visitor-IP header setting, checkout-button toggles, and configurable timer maximum
- 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>
2026-11-15 11:40:06 -08:00

41 lines
1.8 KiB
PHP

<?php
declare( strict_types=1 );
namespace StreamGoals\Admin;
use StreamGoals\Core\Money;
/** Pure goal templates used by the setup wizard. */
final class Templates {
public const LABELS = array(
'simple' => array( 'Simple goal', 'A progress bar towards a fundraising target. Nothing else.' ),
'subathon' => array( 'Subathon timer: +1 min per $1', 'A countdown that gets longer with every donation (1 minute added for every $1).' ),
'counter' => array( 'Counter: +1 per $10', 'A counter that goes up by 1 for every $10 donated (for example "pies thrown").' ),
);
public static function exists( string $key ): bool {
return isset( self::LABELS[ $key ] );
}
/**
* @return array{goal:array,rules:array<int,array{type:string,config:array}>}
*/
public static function build( string $key, string $currency, int $targetMinor, string $title = '' ): array {
$one = 10 ** Money::exponent( $currency ); // one whole currency unit, in minor units
$name = '' !== trim( $title ) ? trim( $title ) : ( 'subathon' === $key ? 'Subathon' : ( 'counter' === $key ? 'Donation counter' : 'My first goal' ) );
$goal = array( 'title' => $name, 'target_minor' => $targetMinor, 'currency' => $currency, 'status' => 'active', 'counts_fees' => 0 );
$rules = array();
if ( 'subathon' === $key ) {
$rules[] = array( 'type' => 'add_time', 'config' => array(
'seconds_per_unit' => 60, 'unit_minor' => $one, 'cap_seconds_per_donation' => null, 'max_total_seconds' => null, 'max_timer_seconds' => null, 'basis' => 'base',
) );
} elseif ( 'counter' === $key ) {
$rules[] = array( 'type' => 'counter', 'config' => array(
'step' => 1, 'per_minor' => 10 * $one, 'carry_over' => true, 'basis' => 'base', 'label' => 'Count',
) );
}
return array( 'goal' => $goal, 'rules' => $rules );
}
}