dblock/slack-sup

View on GitHub
public/update_cc.html.erb

Summary

Maintainability
Test Coverage
<html>
  <head>
    <title>S'Up for Slack Teams: Update Credit Card Info</title>
    <%= partial 'public/partials/_head.html' %>
    <%= partial 'public/partials/_scripts.html' %>
    <%
      team = Team.where(team_id: request.params['team_id']).first
      stripe_token = request.params['stripeToken']
      stripe_token_type = request.params['stripeTokenType']
      stripe_email = request.params['stripeEmail']
    %>
  </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: Update Credit Card Info</h3>
    </p>
    <p id='messages' />
    <p id='update_cc'>
      <form action="" method="POST">
        <script
          src="https://checkout.stripe.com/checkout.js" class="stripe-button"
          data-key="<%= ENV['STRIPE_API_PUBLISHABLE_KEY'] %>"
          data-image='/img/icon.png'
          data-name='Slack Sup'
          data-panel-label="Update Credit Card"
          data-label="Update Credit Card"
          data-allow-remember-me=false
          data-locale="auto">
        </script>
      </form>
    </p>
    <p>
      <img src='/img/stripe.png' width='119' height='26'></img>
      <div class='small'>
        Questions? Contact dblock[at]dblock[dot]org or DM <a href='https://twitter.com/playplayio'>@playplayio</a>.
      </div>
    </p>
    <script>
      $(document).ready(function() {
        var data = {
          stripe_token: "<%=h stripe_token %>",
          stripe_token_type: "<%=h stripe_token_type %>",
          stripe_email: "<%=h stripe_email %>",
          team_id: "<%= team&.id %>"
        };

        var team = {
          id: "<%= team&.id %>",
          name: <%= JSON::generate(ERB::Util.html_escape(team&.name)) %>
        };

        SlackSup.message('Update credit card for team <b>' + team.name + '</b>.');

        if (data.stripe_token && data.stripe_token.length > 0) {
          $.ajax({
            type: 'POST',
            url: '/api/credit_cards',
            data: data,
            success: function(data) {
              SlackSup.message('Successfully updated team <b>' + team.name + '</b> credit card.<br><br>Thank you for your support!');
              $('form').remove();
              $('#update_cc').hide();
            },
            error: SlackSup.error
          });

        } else if (!data.team_id || data.team_id.length == 0) {
          SlackSup.errorMessage("Team not found.")
          $('form').remove();
          $('#update_cc').hide();
        }
      });
    </script>
  </body>
</html>