Skip to content

Commit

Permalink
Buy plugin: Fix currency conversion fee calc
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasbestle committed Nov 11, 2024
1 parent 8104608 commit cbf83c0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
12 changes: 12 additions & 0 deletions site/plugins/buy/src/Paddle.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@

class Paddle
{
public const CONVERSION_FEES = [
'USD' => 0.02,
'GBP' => 0.02,
'CZK' => 0.025,
'DKK' => 0.025,
'NOK' => 0.025,
'THB' => 0.025,

// all other currencies
'...' => 0.03
];

// cache
protected static Visitor $visitor;

Expand Down
4 changes: 1 addition & 3 deletions site/plugins/buy/src/RevenueLimit.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ public static function approximation(Visitor|null $visitor = null, bool $verbose

// remove the Paddle currency conversion fee
// (not relevant for the revenue limit)
if ($visitor->currency() !== 'EUR') {
$value /= 1.02;
}
$value /= 1 + $visitor->conversionFee();

return '' . $visitor->currencySign() . static::formatMagnitude($value, $verbose);
}
Expand Down
12 changes: 12 additions & 0 deletions site/plugins/buy/src/Visitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,18 @@ public static function createFromError(string $error): static
);
}

/**
* Returns the Paddle currency conversion fee for the current currency
*/
public function conversionFee(): float
{
if ($this->currency() === 'EUR') {
return 0;
}

return Paddle::CONVERSION_FEES[$this->currency()] ?? Paddle::CONVERSION_FEES['...'];
}

/**
* Returns the user's two-character ISO country code if available
*/
Expand Down

0 comments on commit cbf83c0

Please sign in to comment.