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,73 @@
|
||||
<?php
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace StreamGoals\Tests\Unit;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use StreamGoals\Core\FeeCalculator;
|
||||
use StreamGoals\Core\Settings;
|
||||
use StreamGoals\PayPal\OrderValidator;
|
||||
use StreamGoals\PayPal\ValidationException;
|
||||
|
||||
final class MinimumDonationTest extends TestCase {
|
||||
|
||||
private const NOW = 1800000000;
|
||||
|
||||
private function quote( string $amount, int $configuredMin, string $currency = 'USD' ): array {
|
||||
$goal = array( 'id' => 1, 'currency' => $currency, 'status' => 'active', 'starts_at' => null, 'ends_at' => null );
|
||||
$settings = array_merge( Settings::defaults(), array( 'min_donation_minor' => $configuredMin ) );
|
||||
return OrderValidator::quote( array( 'amount' => $amount ), $goal, $settings, new FeeCalculator( 349, 49 ), self::NOW );
|
||||
}
|
||||
|
||||
public function test_effective_min_never_below_hard_floor(): void {
|
||||
$this->assertSame( 100, Settings::effectiveMin( 0 ) );
|
||||
$this->assertSame( 100, Settings::effectiveMin( 1 ) );
|
||||
$this->assertSame( 100, Settings::effectiveMin( 99 ) );
|
||||
$this->assertSame( 500, Settings::effectiveMin( 500 ) );
|
||||
}
|
||||
|
||||
public function test_configured_zero_or_tiny_minimum_still_enforces_floor(): void {
|
||||
foreach ( array( 0, 1, 50 ) as $configured ) {
|
||||
try {
|
||||
$this->quote( '0.50', $configured );
|
||||
$this->fail( "0.50 accepted with configured min $configured" );
|
||||
} catch ( ValidationException $e ) {
|
||||
$this->assertSame( 'amount_too_small', $e->errorCode );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function test_exactly_the_floor_is_accepted(): void {
|
||||
$this->assertSame( 100, $this->quote( '1.00', 0 )['base_minor'] );
|
||||
$this->assertSame( 100, $this->quote( '1', 100 )['base_minor'] );
|
||||
}
|
||||
|
||||
public function test_higher_configured_minimum_wins_and_error_names_it(): void {
|
||||
$this->assertSame( 500, $this->quote( '5.00', 500 )['base_minor'] );
|
||||
try {
|
||||
$this->quote( '4.99', 500 );
|
||||
$this->fail( 'expected rejection' );
|
||||
} catch ( ValidationException $e ) {
|
||||
$this->assertSame( 'amount_too_small', $e->errorCode );
|
||||
$this->assertStringContainsString( '5.00 USD', $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function test_zero_and_negative_rejected(): void {
|
||||
foreach ( array( '0', '0.00', '-5' ) as $amt ) {
|
||||
try {
|
||||
$this->quote( $amt, 100 );
|
||||
$this->fail( "amount '$amt' was accepted" );
|
||||
} catch ( ValidationException $e ) {
|
||||
$this->assertContains( $e->errorCode, array( 'amount_too_small', 'invalid_amount' ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function test_fee_cover_does_not_change_the_floor_check(): void {
|
||||
// The floor applies to the base amount the streamer receives, not the fee-inflated total.
|
||||
$this->expectException( ValidationException::class );
|
||||
$goal = array( 'id' => 1, 'currency' => 'USD', 'status' => 'active', 'starts_at' => null, 'ends_at' => null );
|
||||
OrderValidator::quote( array( 'amount' => '0.60', 'cover_fees' => true ), $goal, Settings::defaults(), new FeeCalculator( 349, 49 ), self::NOW );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user