Scaffold plugin: architecture contract, schema, settings, fee math
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
939193f258
12 files changed
+2081
No files matched your search
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace StreamGoals\Core;
|
||||
|
||||
/**
|
||||
* Computes the amount a donor must pay so the recipient nets the intended base
|
||||
* after PayPal's fee: total = ceil((base + fixed) / (1 - pct)).
|
||||
*
|
||||
* Percent is expressed in basis points (349 = 3.49%) to avoid floats.
|
||||
*/
|
||||
final class FeeCalculator {
|
||||
|
||||
public function __construct( public readonly int $percentBps = 349, public readonly int $fixedMinor = 49 ) {
|
||||
if ( $percentBps < 0 || $percentBps >= 10000 || $fixedMinor < 0 ) {
|
||||
throw new \InvalidArgumentException( 'Invalid fee rates.' );
|
||||
}
|
||||
}
|
||||
|
||||
/** Total the donor pays so the recipient nets $baseMinor. */
|
||||
public function grossUp( int $baseMinor ): int {
|
||||
if ( $baseMinor <= 0 ) {
|
||||
return 0;
|
||||
}
|
||||
$num = ( $baseMinor + $this->fixedMinor ) * 10000;
|
||||
$den = 10000 - $this->percentBps;
|
||||
return intdiv( $num + $den - 1, $den ); // integer ceil
|
||||
}
|
||||
|
||||
/** The extra fee-cover portion for a base amount. */
|
||||
public function feeFor( int $baseMinor ): int {
|
||||
return $this->grossUp( $baseMinor ) - $baseMinor;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user