src/Bundles/AdminBundle/Resources/views/index/index.html.twig line 1

Open in your IDE?
  1. {% extends '@Admin/base.html.twig' %}
  2. {% block title %}Index | Project Radar{% endblock %}
  3. {% block javascripts %}
  4.     <script src="https://accounts.google.com/gsi/client" async defer></script>
  5.     <script src="https://js.stripe.com/v3/"></script>
  6.     {{ parent() }}
  7. {% endblock %}
  8. {% block body %}
  9.     <div class="container-fluid">
  10.         <div class="row mb-5">
  11.             <div class="d-flex align-items-center justify-content-center mt-5">
  12.                 <img src="{{ asset('build/images/logo.svg') }}" alt="Logo" style="height: 5vw;" class="pr-2">
  13.                 <h1 style="font-size: 5vw">Project Radar</h1>
  14.             </div>
  15.         </div>
  16.     </div>
  17.     <div class="container">
  18.         <div class="row">
  19.             <div class="d-flex justify-content-center">
  20.                 <a href="{{ path('admin.login')}}" class="btn btn-primary mr-2">Admin Panel</a>
  21.                 <a href="{{ path('api-docs.elements')}}" class="btn btn-success mr-2">Elements API Docs</a>
  22.                 <a href="{{ path('api-docs.swagger')}}" class="btn btn-success"><strike>Swagger API Docs</strike></a>
  23.             </div>
  24.         </div>
  25.     </div>
  26.     <div class="container">
  27.         <div class="row">
  28.             <div class="d-flex justify-content-center" style="margin: 50px 0;">
  29.                 <!-- Display a payment form for create subscription -->
  30.                 <form id="payment-form-subscribe" style="width: 450px;">
  31.                     <div id="card-element-subscribe">
  32.                         <!-- Elements will create input elements here -->
  33.                     </div>
  34.                     <!-- We'll put the error messages in this element -->
  35.                     <div id="card-element-subscribe-errors" role="alert"></div>
  36.                     <!-- Actions -->
  37.                     <div style="margin: 10px 0">
  38.                         <button id="submit-subscribe-btn" type="submit">Subscribe</button>
  39.                     </div>
  40.                     <div style="margin: 10px 0">
  41.                         <button id="submit-create-payment-method-btn" type="submit">Create PaymentMethod</button>
  42.                     </div>
  43.                     <div style="margin: 10px 0">
  44.                         <button id="submit-update-subscription-btn" type="submit">Update subscription</button>
  45.                     </div>
  46.                 </form>
  47.             </div>
  48.         </div>
  49.         <script>
  50.             const clientSecret = 'pi_3LmGC7BC7Ka4fg6F0jlydDoc_secret_mqcLCOh2euFek3tsISRd4fC4r';
  51.             const paymentMethod = 'pm_1LmGBpBC7Ka4fg6FGd26tjEx';
  52.             let stripe = Stripe('pk_test_51Lb16XBC7Ka4fg6FezLjw95YlgU2dkHpefXRyzW2MZ1X4QS6rdtngAxDk8EaLM1OLnyq0DbB2Au8rC3Ee3ObtN8Y008vR1rhij');
  53.             let elements = stripe.elements();
  54.             const style = {
  55.                 base: {
  56.                     color: "#32325d",
  57.                     fontFamily: 'Arial, sans-serif',
  58.                     fontSmoothing: "antialiased",
  59.                     fontSize: "16px",
  60.                     "::placeholder": {
  61.                         color: "#32325d"
  62.                     }
  63.                 },
  64.                 invalid: {
  65.                     fontFamily: 'Arial, sans-serif',
  66.                     color: "#fa755a",
  67.                     iconColor: "#fa755a"
  68.                 }
  69.             };
  70.             let cardElement = elements.create('card', { style: style });
  71.             cardElement.mount('#card-element-subscribe');
  72.             const btnSubscribe = document.querySelector('#submit-subscribe-btn');
  73.             btnSubscribe.addEventListener('click', async (e) => {
  74.                 e.preventDefault();
  75.                 // Create payment method and confirm payment intent.
  76.                 stripe.confirmCardPayment(clientSecret, {
  77.                     payment_method: {
  78.                         card: cardElement,
  79.                         billing_details: {
  80.                             name: 'Test Test',
  81.                         },
  82.                     }
  83.                 }).then((result) => {
  84.                     if(result.error) {
  85.                         console.log('error Payment', result);
  86.                         alert(result.error.message);
  87.                     } else {
  88.                         console.log('confirmCardPayment', result);
  89.                     }
  90.                 });
  91.             });
  92.             const btnCreatePayment = document.querySelector('#submit-create-payment-method-btn');
  93.             btnCreatePayment.addEventListener('click', async (e) => {
  94.                 e.preventDefault();
  95.                 // TODO: For upgrade subscription
  96.                 stripe.createPaymentMethod({
  97.                     type: 'card',
  98.                     card: cardElement,
  99.                     billing_details: {
  100.                         name: 'Jenny Rosen',
  101.                     },
  102.                 }).then(function(result) {
  103.                     // Handle result.error or result.paymentMethod
  104.                     if (result.error) {
  105.                         console.log('ERROR', result.error.message);
  106.                     } else {
  107.                         console.log('paymentMethod', result.paymentMethod);
  108.                     }
  109.                 });
  110.             });
  111.             const btnUpdateSubscription = document.querySelector('#submit-update-subscription-btn');
  112.             btnUpdateSubscription.addEventListener('click', async (e) => {
  113.                 e.preventDefault();
  114.                 // for pay invoice
  115.                 stripe.confirmCardPayment(clientSecret, {
  116.                     payment_method: paymentMethod,
  117.                 }).then((result) => {
  118.                     if(result.error) {
  119.                         console.log('error Payment', result);
  120.                         alert(result.error.message);
  121.                     } else {
  122.                         console.log('confirmCardPayment', result);
  123.                     }
  124.                 });
  125.             });
  126.         </script>
  127.         <div class="row">
  128.             <div class="d-flex justify-content-center">
  129.                 <script>
  130.                     // OpenID Flow
  131.                     function handleCredentialResponse(response) {
  132.                         console.info('Google ID Token:', response.credential);
  133.                         fetch('/api/v1/openid/login', {
  134.                             'method': 'POST',
  135.                             'body':   JSON.stringify({
  136.                                 provider: 'google',
  137.                                 token:    response.credential,
  138.                             }),
  139.                         }).then(async function(result) {
  140.                             console.info('Radar Response:', await result.json());
  141.                         });
  142.                     }
  143.                     window.onload = function () {
  144.                         google.accounts.id.initialize({
  145.                             state_cookie_domain: 'localhost',
  146.                             client_id: "{{ google_app_id }}",
  147.                             callback: handleCredentialResponse,
  148.                         });
  149.                         google.accounts.id.renderButton(
  150.                             document.getElementById("buttonDiv"),
  151.                             { theme: "outline", size: "large" }  // customization attributes
  152.                         );
  153.                         google.accounts.id.prompt(); // also display the One Tap dialog
  154.                     }
  155.                     // oAuth2 Redirect Flow
  156.                     function googleLogin(){
  157.                         let popup = window.open('/api/v1/social/google', "socialPopupWindow", "width=600,height=600,scrollbars=yes,resizable=no");
  158.                         let messageCallback = function(message){
  159.                             if(message.source === popup){
  160.                                 console.info('Radar Post Message:', message.data);
  161.                                 popup.close();
  162.                             }
  163.                         };
  164.                         window.addEventListener("message", messageCallback, false);
  165.                     }
  166.                     // LinkedIn oAuth2 with Redirect Flow
  167.                     function linkedinLogin() {
  168.                         const popupLinkedIn = window.open('/api/v1/social/linkedin', "socialPopupWindow", "width=600,height=600,scrollbars=yes,resizable=no");
  169.                         let messageCallback = function(message){
  170.                             if(message.source === popupLinkedIn){
  171.                                 console.info('Radar Post Message LinkedIn Login:', message.data);
  172.                                 popupLinkedIn.close();
  173.                             }
  174.                         };
  175.                         window.addEventListener("message", messageCallback, false);
  176.                     }
  177.                 </script>
  178.                 <div id="buttonDiv"></div>
  179.                 <br>
  180.                 <button onclick="googleLogin()">Login With Google (Redirect Flow)</button>
  181.                 <button onclick="linkedinLogin()">Login With LinkedIn (Redirect Flow)</button>
  182.             </div>
  183.         </div>
  184.     </div>
  185. {% endblock %}