src/Controller/Api/MembershipController.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Api;
  3. use App\Entity\Membership;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use App\Helper\StripeHelper;
  8. use Symfony\Component\HttpFoundation\JsonResponse;
  9. use App\Entity\Customer;
  10. class MembershipController extends ApiController
  11. {
  12.     /**
  13.      * @param Request $request
  14.      * @return JsonResponse
  15.      *
  16.      * @Route("/membership/list", name="api_membership_list_get", methods={"POST"})
  17.      */
  18.     public function listMembership(Request $request)
  19.     {
  20.         $prefixFile $this->getParameter("app.path.membership_images");
  21.         $baseurl $request->getScheme() . '://' $request->getHttpHost() . $request->getBasePath();
  22.         /** @var Membership $membership */
  23.         $memberships = [];
  24.         foreach ($this->em->getRepository(Membership::class)->findAll() as $membership){
  25.             $memberships[] = $membership->__toArray($baseurl $prefixFile "/");
  26.         }
  27.         return $this->response($memberships);
  28.     }
  29.      /**
  30.      * @param Request $request
  31.      * @return JsonResponse
  32.      *
  33.      * @Route("/membership/create_checkout", name="api_membership_create_checkout", methods={"POST"})
  34.      */
  35.     public function createCheckout(Request $request)
  36.     {
  37.         $stripe = new StripeHelper();
  38.         $customer $this->getUser();
  39.         $result $stripe->createSessionMonthlyTest($customer);
  40.         return $this->json($result);
  41.     }
  42.       /**
  43.      * @param Request $request
  44.      * @return JsonResponse
  45.      *
  46.      * @Route("/membership/create_subscription", name="api_membership_create_subscription", methods={"POST"})
  47.      */
  48.     public function createSubscription(Request $request)
  49.     {
  50.         $stripe = new StripeHelper();
  51.         $customer $this->getUser();
  52.         $req $this->transformJsonBody($request);
  53.         $paymentId $req->get('payment_id');
  54.         $period $req->get('period');
  55.         $result = [];
  56.         if($period === 'monthly'){
  57.             $result $stripe->createMonthlySubscriptionTest($customer,$paymentId);
  58.         }else if($period === 'yearly'){
  59.             $result $stripe->createYearlySubscriptionTest($customer,$paymentId);
  60.         }
  61.         return $this->json($result);
  62.     }
  63.        /**
  64.      * @param Request $request
  65.      * @return JsonResponse
  66.      *
  67.      * @Route("/membership/create_subscription_intent", name="api_membership_create_subscription_intent", methods={"POST"})
  68.      */
  69.     public function createSubscriptionIntent(Request $request)
  70.     {
  71.         $stripe = new StripeHelper();
  72.         $customer $this->getUser();
  73.         $req $this->transformJsonBody($request);
  74.         $period $req->get('period');
  75.         $result = [];
  76.         if($period === 'monthly'){
  77.             $result $stripe->createMonthlySubscriptionIntentTest($customer);
  78.         }else if($period === 'yearly'){
  79.             $result $stripe->createYearlySubscriptionIntentTest($customer);
  80.         }
  81.         return $this->json($result);
  82.     }
  83. }