-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDonationFundsService.php
More file actions
37 lines (31 loc) · 1.05 KB
/
DonationFundsService.php
File metadata and controls
37 lines (31 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
namespace MatchBot\Domain;
use MatchBot\Client\Stripe;
class DonationFundsService
{
/**
* @psalm-suppress PossiblyUnusedMethod - used by DI container
*/
public function __construct(
private readonly Stripe $stripe
) {
}
public function refundFullBalanceToCustomer(DonorAccount $donorAccount): void
{
$stripeCustomer = $this->stripe->retrieveCustomer($donorAccount->stripeCustomerId, ['expand' => ['cash_balance']]);
if ($stripeCustomer->cash_balance === null || $stripeCustomer->cash_balance->available === null) {
return;
}
/**
* @var string $currencyCode
* @var int $amount
*/
foreach ($stripeCustomer->cash_balance->available->toArray() as $currencyCode => $amount) {
if ($amount === 0) {
continue;
}
$money = Money::fromPence($amount, Currency::fromIsoCode($currencyCode));
$this->stripe->refundCustomerBalance($donorAccount->stripeCustomerId, $money);
}
}
}