src/Security/PaymentVoter.php line 43

Open in your IDE?
  1. <?php
  2. namespace App\Security;
  3. use App\Entity\BFFestival;
  4. use App\Entity\BFEdition;
  5. use App\Entity\BFChallenge;
  6. use App\Entity\BFChallengeEdition;
  7. use App\Entity\BFOption;
  8. use App\Utilities\OptionUtilities;
  9. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  10. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  11. use Symfony\Component\Security\Core\Security;
  12. use Stripe\Stripe;
  13. use Stripe\StripeClient;
  14. use Stripe\StripeAccount;
  15. class PaymentVoter extends Voter
  16. {
  17.     private $stripe_secret_key;
  18.     //the string options are managed by the utility
  19.     
  20.     public function __construct(string $secretkey)
  21.     {
  22.         $this->stripe_secret_key $secretkey;
  23.     }
  24.     protected function supports($attribute$subject)
  25.     {
  26.         
  27.         // if the attribute isn't one we support, return false
  28.         if($attribute!="canpay")
  29.             return false;
  30.         
  31.         // only vote on `BFFestival` objects
  32.         if ($subject instanceof BFFestival) { // ||
  33.             return true;
  34.         }
  35.         return false;
  36.     }
  37.     protected function voteOnAttribute($attribute$subjectTokenInterface $token)
  38.     {   
  39.         if($subject->getStripeaccountid()==null)
  40.             $stripeaccountvalidfalse;
  41.         else
  42.         {
  43.             $stripe = new StripeClient($this->stripe_secret_key);
  44.             $account $stripe->accounts->retrieve($subject->getStripeaccountid(),
  45.                        []
  46.                        );
  47.             return $account->charges_enabled;
  48.         }
  49.         
  50.         return false;
  51.     }
  52. }
  53. ?>