Donate form: custom-amount label, visible minimum, fee-cover info icon; hard 1.00 floor; purge abandoned checkouts; drop refund filters; soften personal-account wording
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a259c0b0a1
commit
e22675f54b
13 files changed
+177
-15
No files matched your search
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace StreamGoals\Core;
|
||||
|
||||
/**
|
||||
* Daily housekeeping: removes checkouts that were started but never paid.
|
||||
*
|
||||
* Only rows that never received a PayPal capture id are purged, and only after a week, so a slow payment
|
||||
* that PayPal finalizes later through the webhook is never discarded.
|
||||
*/
|
||||
final class Maintenance {
|
||||
|
||||
public const HOOK = 'sg_purge_abandoned';
|
||||
public const MAX_AGE_DAYS = 7;
|
||||
|
||||
public static function register(): void {
|
||||
add_action( self::HOOK, array( self::class, 'purge_abandoned' ) );
|
||||
if ( ! wp_next_scheduled( self::HOOK ) ) {
|
||||
wp_schedule_event( time() + HOUR_IN_SECONDS, 'daily', self::HOOK );
|
||||
}
|
||||
}
|
||||
|
||||
public static function unschedule(): void {
|
||||
wp_clear_scheduled_hook( self::HOOK );
|
||||
}
|
||||
|
||||
/** @return int Number of rows removed. */
|
||||
public static function purge_abandoned(): int {
|
||||
global $wpdb;
|
||||
$table = $wpdb->prefix . 'sg_donations';
|
||||
$cutoff = gmdate( 'Y-m-d H:i:s', time() - self::MAX_AGE_DAYS * DAY_IN_SECONDS );
|
||||
$n = $wpdb->query(
|
||||
$wpdb->prepare(
|
||||
"DELETE FROM {$table} WHERE status = 'pending' AND (paypal_capture_id IS NULL OR paypal_capture_id = '') AND goal_id > 0 AND created_at < %s", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
$cutoff
|
||||
)
|
||||
);
|
||||
return (int) $n;
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ final class Plugin {
|
||||
|
||||
public static function boot(): void {
|
||||
Installer::maybe_upgrade();
|
||||
Maintenance::register();
|
||||
foreach ( self::MODULES as $module ) {
|
||||
if ( class_exists( $module ) && method_exists( $module, 'register' ) ) {
|
||||
$module::register();
|
||||
|
||||
@@ -8,6 +8,17 @@ namespace StreamGoals\Core;
|
||||
*/
|
||||
final class Settings {
|
||||
|
||||
/**
|
||||
* Absolute minimum donation in minor units (1.00 of the currency). PayPal's fixed per-transaction fee
|
||||
* makes smaller donations a net loss for the streamer, so the configured minimum can never go below this.
|
||||
*/
|
||||
public const HARD_MIN_MINOR = 100;
|
||||
|
||||
/** The minimum that is actually enforced: the configured value, but never below the hard floor. */
|
||||
public static function effectiveMin( int $configured ): int {
|
||||
return max( self::HARD_MIN_MINOR, $configured );
|
||||
}
|
||||
|
||||
public static function defaults(): array {
|
||||
return array(
|
||||
'paypal_mode' => 'sandbox', // sandbox | live
|
||||
|
||||
Reference in new issue
Block a user