Skip to main content

max / makenotwork

941 B · 27 lines History Blame Raw
1 var checkbox = document.getElementById('accept-terms');
2 var button = document.getElementById('continue-btn');
3
4 checkbox.addEventListener('change', function() {
5 button.disabled = !this.checked;
6 });
7
8 function proceedToStripe() {
9 button.disabled = true;
10 button.textContent = 'Connecting...';
11 fetch('/stripe/connect/proceed', {
12 method: 'POST',
13 headers: {
14 'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').content
15 }
16 }).then(function(res) {
17 if (!res.ok) throw new Error('Failed to connect');
18 return res.json();
19 }).then(function(data) {
20 window.location.href = data.url;
21 }).catch(function() {
22 button.disabled = false;
23 button.textContent = 'Continue to Stripe';
24 showToast('Something went wrong. Please try again.');
25 });
26 }
27