public/subscribe.html.erb
<html>
<head>
<title>S'Up for Slack Teams: Subscribe</title>
<%= partial 'public/partials/_head.html.erb' %>
<script src='https://checkout.stripe.com/checkout.js'></script>
<link rel='stylesheet' href='https://checkout.stripe.com/v3/checkout/button.css'></link>
<%= partial 'public/partials/_scripts.html' %>
</head>
<body style='text-align: center'>
<p style='margin: 50px;'>
<a href='/'><img src='img/icon.png' width='120px'></a>
</p>
<p>
<h3>S'Up for Slack Teams: Subscribe</h3>
</p>
<p id='messages' />
<p id='subscribe'>
<button id='subscribeButton' class='stripe-button-el'>
<span style='display: block; min-height: 30px;'>Pay $39.99 with Card</span>
</button>
<p>
<img src='/img/stripe.png' width='119' height='26'></img>
</p>
<script>
$(document).ready(function() {
<% team = Team.where(team_id: request.params['team_id']).first %>
var team = {
id: "<%= team&.team_id %>",
name: <%= JSON::generate(ERB::Util.html_escape(team&.name)) %>,
subscribed: <%= !!(team&.subscribed) %>
}
if (team.subscribed) {
SlackSup.message('Team <b>' + team.name + '</b> is already subscribed, thank you for your support.');
$('#subscribeButton').remove();
} else if (team.id && team.name) {
SlackSup.message('Subscribe team <b>' + team.name + '</b> for $39.99/yr.');
} else {
$('#subscribeButton').remove();
SlackSup.errorMessage('Missing or invalid team ID.');
}
var handler = StripeCheckout.configure({
key: '<%= ENV['STRIPE_API_PUBLISHABLE_KEY'] %>',
image: '/img/icon.png',
locale: 'auto',
token: function(token) {
$.ajax({
type: 'POST',
url: '/api/subscriptions',
data: {
stripe_email: token.email,
stripe_token: token.id,
stripe_token_type: token.type,
team_id: team.id
},
success: function(data) {
SlackSup.message('Team <b>' + team.name + '</b> successfully subscribed.<br><br>Thank you for your support!');
$('#subscribeButton').remove();
},
error: SlackSup.error
});
}
});
$('#subscribeButton').on('click', function(e) {
var amount = 3999;
handler.open({
name: 'Slack Sup',
description: 'Yearly Subscription',
amount: amount
});
e.preventDefault();
});
$(window).on('popstate', function() {
handler.close();
});
});
</script>
</p>
</body>
</html>