{% extends '@Admin/base.html.twig' %}
{% block title %}Index | Project Radar{% endblock %}
{% block javascripts %}
<script src="https://accounts.google.com/gsi/client" async defer></script>
<script src="https://js.stripe.com/v3/"></script>
{{ parent() }}
{% endblock %}
{% block body %}
<div class="container-fluid">
<div class="row mb-5">
<div class="d-flex align-items-center justify-content-center mt-5">
<img src="{{ asset('build/images/logo.svg') }}" alt="Logo" style="height: 5vw;" class="pr-2">
<h1 style="font-size: 5vw">Project Radar</h1>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="d-flex justify-content-center">
<a href="{{ path('admin.login')}}" class="btn btn-primary mr-2">Admin Panel</a>
<a href="{{ path('api-docs.elements')}}" class="btn btn-success mr-2">Elements API Docs</a>
<a href="{{ path('api-docs.swagger')}}" class="btn btn-success"><strike>Swagger API Docs</strike></a>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="d-flex justify-content-center" style="margin: 50px 0;">
<!-- Display a payment form for create subscription -->
<form id="payment-form-subscribe" style="width: 450px;">
<div id="card-element-subscribe">
<!-- Elements will create input elements here -->
</div>
<!-- We'll put the error messages in this element -->
<div id="card-element-subscribe-errors" role="alert"></div>
<!-- Actions -->
<div style="margin: 10px 0">
<button id="submit-subscribe-btn" type="submit">Subscribe</button>
</div>
<div style="margin: 10px 0">
<button id="submit-create-payment-method-btn" type="submit">Create PaymentMethod</button>
</div>
<div style="margin: 10px 0">
<button id="submit-update-subscription-btn" type="submit">Update subscription</button>
</div>
</form>
</div>
</div>
<script>
const clientSecret = 'pi_3LmGC7BC7Ka4fg6F0jlydDoc_secret_mqcLCOh2euFek3tsISRd4fC4r';
const paymentMethod = 'pm_1LmGBpBC7Ka4fg6FGd26tjEx';
let stripe = Stripe('pk_test_51Lb16XBC7Ka4fg6FezLjw95YlgU2dkHpefXRyzW2MZ1X4QS6rdtngAxDk8EaLM1OLnyq0DbB2Au8rC3Ee3ObtN8Y008vR1rhij');
let elements = stripe.elements();
const style = {
base: {
color: "#32325d",
fontFamily: 'Arial, sans-serif',
fontSmoothing: "antialiased",
fontSize: "16px",
"::placeholder": {
color: "#32325d"
}
},
invalid: {
fontFamily: 'Arial, sans-serif',
color: "#fa755a",
iconColor: "#fa755a"
}
};
let cardElement = elements.create('card', { style: style });
cardElement.mount('#card-element-subscribe');
const btnSubscribe = document.querySelector('#submit-subscribe-btn');
btnSubscribe.addEventListener('click', async (e) => {
e.preventDefault();
// Create payment method and confirm payment intent.
stripe.confirmCardPayment(clientSecret, {
payment_method: {
card: cardElement,
billing_details: {
name: 'Test Test',
},
}
}).then((result) => {
if(result.error) {
console.log('error Payment', result);
alert(result.error.message);
} else {
console.log('confirmCardPayment', result);
}
});
});
const btnCreatePayment = document.querySelector('#submit-create-payment-method-btn');
btnCreatePayment.addEventListener('click', async (e) => {
e.preventDefault();
// TODO: For upgrade subscription
stripe.createPaymentMethod({
type: 'card',
card: cardElement,
billing_details: {
name: 'Jenny Rosen',
},
}).then(function(result) {
// Handle result.error or result.paymentMethod
if (result.error) {
console.log('ERROR', result.error.message);
} else {
console.log('paymentMethod', result.paymentMethod);
}
});
});
const btnUpdateSubscription = document.querySelector('#submit-update-subscription-btn');
btnUpdateSubscription.addEventListener('click', async (e) => {
e.preventDefault();
// for pay invoice
stripe.confirmCardPayment(clientSecret, {
payment_method: paymentMethod,
}).then((result) => {
if(result.error) {
console.log('error Payment', result);
alert(result.error.message);
} else {
console.log('confirmCardPayment', result);
}
});
});
</script>
<div class="row">
<div class="d-flex justify-content-center">
<script>
// OpenID Flow
function handleCredentialResponse(response) {
console.info('Google ID Token:', response.credential);
fetch('/api/v1/openid/login', {
'method': 'POST',
'body': JSON.stringify({
provider: 'google',
token: response.credential,
}),
}).then(async function(result) {
console.info('Radar Response:', await result.json());
});
}
window.onload = function () {
google.accounts.id.initialize({
state_cookie_domain: 'localhost',
client_id: "{{ google_app_id }}",
callback: handleCredentialResponse,
});
google.accounts.id.renderButton(
document.getElementById("buttonDiv"),
{ theme: "outline", size: "large" } // customization attributes
);
google.accounts.id.prompt(); // also display the One Tap dialog
}
// oAuth2 Redirect Flow
function googleLogin(){
let popup = window.open('/api/v1/social/google', "socialPopupWindow", "width=600,height=600,scrollbars=yes,resizable=no");
let messageCallback = function(message){
if(message.source === popup){
console.info('Radar Post Message:', message.data);
popup.close();
}
};
window.addEventListener("message", messageCallback, false);
}
// LinkedIn oAuth2 with Redirect Flow
function linkedinLogin() {
const popupLinkedIn = window.open('/api/v1/social/linkedin', "socialPopupWindow", "width=600,height=600,scrollbars=yes,resizable=no");
let messageCallback = function(message){
if(message.source === popupLinkedIn){
console.info('Radar Post Message LinkedIn Login:', message.data);
popupLinkedIn.close();
}
};
window.addEventListener("message", messageCallback, false);
}
</script>
<div id="buttonDiv"></div>
<br>
<button onclick="googleLogin()">Login With Google (Redirect Flow)</button>
<button onclick="linkedinLogin()">Login With LinkedIn (Redirect Flow)</button>
</div>
</div>
</div>
{% endblock %}