<?php
namespace App\Security;
use App\Entity\BFFestival;
use App\Entity\BFEdition;
use App\Entity\BFChallenge;
use App\Entity\BFChallengeEdition;
use App\Entity\BFOption;
use App\Utilities\OptionUtilities;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Component\Security\Core\Security;
use Stripe\Stripe;
use Stripe\StripeClient;
use Stripe\StripeAccount;
class PaymentVoter extends Voter
{
private $stripe_secret_key;
//the string options are managed by the utility
public function __construct(string $secretkey)
{
$this->stripe_secret_key = $secretkey;
}
protected function supports($attribute, $subject)
{
// if the attribute isn't one we support, return false
if($attribute!="canpay")
return false;
// only vote on `BFFestival` objects
if ($subject instanceof BFFestival) { // ||
return true;
}
return false;
}
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
{
if($subject->getStripeaccountid()==null)
$stripeaccountvalid= false;
else
{
$stripe = new StripeClient($this->stripe_secret_key);
$account = $stripe->accounts->retrieve($subject->getStripeaccountid(),
[]
);
return $account->charges_enabled;
}
return false;
}
}
?>