Onttraders commited on
Commit
a12597f
·
verified ·
1 Parent(s): 50a712c

🐳 13/04 - 19:21 - Connect Super Fan system to real payments.1. PAYMENT MODALWhen user clicks “Become Super Fan”:Open payment flow:Subscription: $25/month recurringShow artist name + summaryButton:Con

Browse files
Files changed (1) hide show
  1. app.js +251 -44
app.js CHANGED
@@ -219,6 +219,15 @@ const BF = (() => {
219
  .bf-superfan-badge { background: linear-gradient(135deg, #f97316, #ef4444); color: white; font-size: 10px; font-weight: 600; padding: 3px 10px; border-radius: 9999px; display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
220
  .bf-superfan-btn { transition: all 0.2s ease; }
221
  .bf-superfan-btn:hover { transform: scale(1.02); }
 
 
 
 
 
 
 
 
 
222
  `;
223
  document.head.appendChild(style);
224
  };
@@ -558,8 +567,17 @@ const BF = (() => {
558
  };
559
 
560
  // ===== SUPER FAN UI =====
 
 
 
561
  const showSuperFanModal = (artistName, artistImage) => {
562
  if (document.getElementById('bfSuperFanModal')) return;
 
 
 
 
 
 
563
  const modal = document.createElement('div');
564
  modal.id = 'bfSuperFanModal';
565
  modal.innerHTML = `
@@ -570,44 +588,127 @@ const BF = (() => {
570
  <h3 class="text-xl font-bold text-white">Become a Super Fan</h3>
571
  <button onclick="BF.closeSuperFanModal()" class="text-gray-400 hover:text-white transition"><i data-lucide="x" class="w-6 h-6"></i></button>
572
  </div>
573
- <div class="flex items-center gap-4 mb-6">
574
- <div class="w-16 h-16 rounded-full overflow-hidden border-2 border-orange-500/50 flex-shrink-0">
575
- <img src="${artistImage}" class="w-full h-full object-cover">
 
 
 
 
 
 
 
 
576
  </div>
577
- <div class="min-w-0">
578
- <p class="font-semibold text-white text-lg truncate">${artistName}</p>
579
- <p class="text-sm text-gray-400">Support this artist and unlock exclusive content</p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
580
  </div>
 
 
 
 
 
581
  </div>
582
- <div class="p-4 rounded-xl bg-gradient-to-r from-orange-500/10 to-red-500/10 border border-orange-500/20 mb-6">
583
- <div class="flex items-center justify-between mb-4">
584
- <span class="text-sm text-gray-300">Monthly subscription</span>
585
- <span class="text-xl font-bold text-orange-400">$25<span class="text-sm text-gray-500 font-normal">/mo</span></span>
 
 
 
 
 
 
 
586
  </div>
587
- <div class="space-y-2.5">
588
- <div class="flex items-center gap-2 text-sm text-gray-300">
589
- <i data-lucide="unlock" class="w-4 h-4 text-orange-400 flex-shrink-0"></i>
590
- <span>Early access to new music</span>
591
  </div>
592
- <div class="flex items-center gap-2 text-sm text-gray-300">
593
- <i data-lucide="music" class="w-4 h-4 text-orange-400 flex-shrink-0"></i>
594
- <span>Exclusive tracks & content</span>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
595
  </div>
596
- <div class="flex items-center gap-2 text-sm text-gray-300">
597
- <i data-lucide="headphones" class="w-4 h-4 text-orange-400 flex-shrink-0"></i>
598
- <span>High-quality audio</span>
599
  </div>
600
- <div class="flex items-center gap-2 text-sm text-gray-300">
601
- <i data-lucide="heart" class="w-4 h-4 text-orange-400 flex-shrink-0"></i>
602
- <span>Direct support for the creator</span>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
603
  </div>
 
 
 
604
  </div>
605
  </div>
606
- <button onclick="BF.toggleSuperFanState('${artistName}', '${artistImage}')" class="w-full py-3 bg-gradient-to-r from-orange-500 to-red-500 hover:from-orange-400 hover:to-red-400 text-white font-semibold rounded-xl transition flex items-center justify-center gap-2 bf-superfan-btn" style="box-shadow: 0 0 20px rgba(249,115,22,0.3)">
607
- <i data-lucide="zap" class="w-5 h-5"></i>
608
- Continue
609
- </button>
610
- <p class="text-xs text-gray-600 text-center mt-3">Recurring monthly \u2022 Cancel anytime</p>
611
  </div>
612
  </div>
613
  `;
@@ -619,22 +720,128 @@ const BF = (() => {
619
  document.getElementById('bfSuperFanModal')?.remove();
620
  };
621
 
622
- const toggleSuperFanState = (artistName) => {
623
- const key = 'bf_superfan';
624
- let subs = [];
625
- try { subs = JSON.parse(localStorage.getItem(key) || '[]'); } catch { subs = []; }
626
- const slug = artistName.toLowerCase().replace(/\s+/g, '-');
627
- if (!subs.includes(slug)) {
628
- subs.push(slug);
629
- } else {
630
- subs = subs.filter(s => s !== slug);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
631
  }
632
- localStorage.setItem(key, JSON.stringify(subs));
633
- closeSuperFanModal();
634
- const isActive = subs.includes(slug);
635
- showToast(isActive ? 'You are now a Super Fan of ' + artistName + ' \ud83c\udfa7' : 'Super Fan deactivated for ' + artistName);
636
- updateSuperFanButtons();
637
- if (window.lucide) lucide.createIcons();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
638
  };
639
 
640
  const isSuperFanOf = (artistName) => {
@@ -701,7 +908,7 @@ const BF = (() => {
701
  init, showSignInModal, closeSignInModal, handleSignIn,
702
  showSignUpForm, showSignInForm, showChooseType, handleSignUp,
703
  adjustTopNav, showToast, syncPlayer, playTrack, togglePlay,
704
- showSuperFanModal, closeSuperFanModal, toggleSuperFanState, isSuperFanOf, updateSuperFanButtons,
705
  getSuperFanSubscriptions, cancelSuperFanSubscription
706
  };
707
  })();
 
219
  .bf-superfan-badge { background: linear-gradient(135deg, #f97316, #ef4444); color: white; font-size: 10px; font-weight: 600; padding: 3px 10px; border-radius: 9999px; display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
220
  .bf-superfan-btn { transition: all 0.2s ease; }
221
  .bf-superfan-btn:hover { transform: scale(1.02); }
222
+ .bf-payment-input {
223
+ width: 100%; background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1);
224
+ border-radius: 0.75rem; padding: 0.75rem 1rem; font-size: 0.875rem;
225
+ color: white; outline: none; transition: border-color 0.2s, background 0.2s;
226
+ }
227
+ .bf-payment-input:focus { border-color: rgba(249,115,22,0.5); background: rgba(255,255,255,0.07); }
228
+ .bf-payment-input::placeholder { color: #4b5563; }
229
+ .bf-payment-input.error { border-color: rgba(239,68,68,0.5); }
230
+ @keyframes bf-spin { to { transform: rotate(360deg); } }
231
  `;
232
  document.head.appendChild(style);
233
  };
 
567
  };
568
 
569
  // ===== SUPER FAN UI =====
570
+ let _sfArtistName = '';
571
+ let _sfArtistImage = '';
572
+
573
  const showSuperFanModal = (artistName, artistImage) => {
574
  if (document.getElementById('bfSuperFanModal')) return;
575
+ if (isSuperFanOf(artistName)) {
576
+ showToast('You are already a Super Fan of ' + artistName + ' \ud83c\udfa7');
577
+ return;
578
+ }
579
+ _sfArtistName = artistName;
580
+ _sfArtistImage = artistImage;
581
  const modal = document.createElement('div');
582
  modal.id = 'bfSuperFanModal';
583
  modal.innerHTML = `
 
588
  <h3 class="text-xl font-bold text-white">Become a Super Fan</h3>
589
  <button onclick="BF.closeSuperFanModal()" class="text-gray-400 hover:text-white transition"><i data-lucide="x" class="w-6 h-6"></i></button>
590
  </div>
591
+
592
+ <!-- Step 1: Summary -->
593
+ <div id="bfSfStep1">
594
+ <div class="flex items-center gap-4 mb-6">
595
+ <div class="w-16 h-16 rounded-full overflow-hidden border-2 border-orange-500/50 flex-shrink-0">
596
+ <img src="${artistImage}" class="w-full h-full object-cover">
597
+ </div>
598
+ <div class="min-w-0">
599
+ <p class="font-semibold text-white text-lg truncate">${artistName}</p>
600
+ <p class="text-sm text-gray-400">Support this artist and unlock exclusive content</p>
601
+ </div>
602
  </div>
603
+ <div class="p-4 rounded-xl bg-gradient-to-r from-orange-500/10 to-red-500/10 border border-orange-500/20 mb-6">
604
+ <div class="flex items-center justify-between mb-4">
605
+ <span class="text-sm text-gray-300">Monthly subscription</span>
606
+ <span class="text-xl font-bold text-orange-400">$25<span class="text-sm text-gray-500 font-normal">/mo</span></span>
607
+ </div>
608
+ <div class="space-y-2.5">
609
+ <div class="flex items-center gap-2 text-sm text-gray-300">
610
+ <i data-lucide="unlock" class="w-4 h-4 text-orange-400 flex-shrink-0"></i>
611
+ <span>Early access to new music</span>
612
+ </div>
613
+ <div class="flex items-center gap-2 text-sm text-gray-300">
614
+ <i data-lucide="music" class="w-4 h-4 text-orange-400 flex-shrink-0"></i>
615
+ <span>Exclusive tracks & content</span>
616
+ </div>
617
+ <div class="flex items-center gap-2 text-sm text-gray-300">
618
+ <i data-lucide="headphones" class="w-4 h-4 text-orange-400 flex-shrink-0"></i>
619
+ <span>High-quality audio</span>
620
+ </div>
621
+ <div class="flex items-center gap-2 text-sm text-gray-300">
622
+ <i data-lucide="heart" class="w-4 h-4 text-orange-400 flex-shrink-0"></i>
623
+ <span>Direct support for the creator</span>
624
+ </div>
625
+ </div>
626
  </div>
627
+ <button onclick="BF.showSuperFanPaymentStep()" class="w-full py-3 bg-gradient-to-r from-orange-500 to-red-500 hover:from-orange-400 hover:to-red-400 text-white font-semibold rounded-xl transition flex items-center justify-center gap-2" style="box-shadow: 0 0 20px rgba(249,115,22,0.3)">
628
+ <i data-lucide="credit-card" class="w-5 h-5"></i>
629
+ Continue to Payment
630
+ </button>
631
+ <p class="text-xs text-gray-600 text-center mt-3">Recurring monthly \u2022 Cancel anytime</p>
632
  </div>
633
+
634
+ <!-- Step 2: Payment Form -->
635
+ <div id="bfSfStep2" class="hidden">
636
+ <div class="flex items-center gap-3 mb-5 p-3 rounded-xl bg-white/5">
637
+ <div class="w-10 h-10 rounded-full overflow-hidden border border-orange-500/30 flex-shrink-0">
638
+ <img src="${artistImage}" class="w-full h-full object-cover">
639
+ </div>
640
+ <div class="flex-1 min-w-0">
641
+ <p class="text-sm font-semibold text-white truncate">${artistName}</p>
642
+ <p class="text-xs text-orange-400 font-medium">$25/mo</p>
643
+ </div>
644
  </div>
645
+ <div class="space-y-4">
646
+ <div>
647
+ <label class="block text-xs font-medium text-gray-500 uppercase tracking-wider mb-2">Name on card</label>
648
+ <input type="text" id="bfSfCardName" placeholder="John Doe" class="bf-payment-input">
649
  </div>
650
+ <div>
651
+ <label class="block text-xs font-medium text-gray-500 uppercase tracking-wider mb-2">Card number</label>
652
+ <div class="relative">
653
+ <input type="text" id="bfSfCardNumber" placeholder="4242 4242 4242 4242" class="bf-payment-input" style="padding-right:4.5rem" maxlength="19" oninput="BF.formatCardNumber(this)">
654
+ <div class="absolute right-3 top-1/2 -translate-y-1/2 flex items-center gap-1.5 text-gray-600">
655
+ <svg width="28" height="18" viewBox="0 0 28 18" fill="none"><rect width="28" height="18" rx="2" fill="#1A1F71"/><path d="M11 5.5L8.5 12.5h2l.5-1.5h2.5l.5 1.5h2L13 5.5h-2zm.8 4.5l1-3 1 3h-2z" fill="#fff"/></svg>
656
+ </div>
657
+ </div>
658
+ </div>
659
+ <div class="flex gap-3">
660
+ <div class="flex-1">
661
+ <label class="block text-xs font-medium text-gray-500 uppercase tracking-wider mb-2">Expiry</label>
662
+ <input type="text" id="bfSfCardExpiry" placeholder="MM/YY" class="bf-payment-input" maxlength="5" oninput="BF.formatCardExpiry(this)">
663
+ </div>
664
+ <div class="w-24">
665
+ <label class="block text-xs font-medium text-gray-500 uppercase tracking-wider mb-2">CVC</label>
666
+ <input type="text" id="bfSfCardCvc" placeholder="123" class="bf-payment-input" maxlength="4" oninput="this.value=this.value.replace(/[^0-9]/g,'')">
667
+ </div>
668
+ </div>
669
+ <div id="bfSfPaymentError" class="hidden text-red-400 text-sm"></div>
670
+ <button onclick="BF.confirmSuperFanPayment()" class="w-full py-3 bg-gradient-to-r from-orange-500 to-red-500 hover:from-orange-400 hover:to-red-400 text-white font-semibold rounded-xl transition flex items-center justify-center gap-2" style="box-shadow: 0 0 20px rgba(249,115,22,0.3)">
671
+ <i data-lucide="lock" class="w-5 h-5"></i>
672
+ Confirm Subscription \u2022 $25/mo
673
+ </button>
674
+ <button onclick="BF.showSuperFanSummaryStep()" class="w-full py-2 text-sm text-gray-500 hover:text-white transition">\u2190 Back</button>
675
+ </div>
676
+ <div class="flex items-center justify-center gap-4 mt-4 pt-4 border-t border-white/5">
677
+ <div class="flex items-center gap-1.5 text-xs text-gray-600">
678
+ <i data-lucide="shield-check" class="w-3.5 h-3.5"></i>
679
+ <span>Encrypted</span>
680
+ </div>
681
+ <div class="flex items-center gap-1.5 text-xs text-gray-600">
682
+ <i data-lucide="lock" class="w-3.5 h-3.5"></i>
683
+ <span>Secure</span>
684
  </div>
685
+ <div class="flex items-center gap-1.5 text-xs text-gray-600">
686
+ <i data-lucide="credit-card" class="w-3.5 h-3.5"></i>
687
+ <span>PCI Compliant</span>
688
  </div>
689
+ </div>
690
+ </div>
691
+
692
+ <!-- Step 3: Processing -->
693
+ <div id="bfSfStep3" class="hidden">
694
+ <div class="py-12 text-center">
695
+ <div class="w-16 h-16 rounded-full border-4 border-orange-500/20 border-t-orange-500 mx-auto mb-6" style="animation: bf-spin 1s linear infinite;"></div>
696
+ <h4 class="text-lg font-semibold text-white mb-2">Processing payment...</h4>
697
+ <p class="text-sm text-gray-500">Please wait while we confirm your subscription</p>
698
+ </div>
699
+ </div>
700
+
701
+ <!-- Step 4: Success -->
702
+ <div id="bfSfStep4" class="hidden">
703
+ <div class="py-8 text-center">
704
+ <div class="w-20 h-20 rounded-full bg-green-500/20 flex items-center justify-center mx-auto mb-6">
705
+ <i data-lucide="check-circle" class="w-10 h-10 text-green-400"></i>
706
  </div>
707
+ <h4 class="text-xl font-bold text-white mb-2">You are now a Super Fan \ud83c\udfa7</h4>
708
+ <p class="text-sm text-gray-400 mb-1">Subscription to <span class="text-orange-400 font-medium">${artistName}</span> is active</p>
709
+ <p class="text-xs text-gray-600">Exclusive content has been unlocked</p>
710
  </div>
711
  </div>
 
 
 
 
 
712
  </div>
713
  </div>
714
  `;
 
720
  document.getElementById('bfSuperFanModal')?.remove();
721
  };
722
 
723
+ const showSuperFanPaymentStep = () => {
724
+ const step1 = document.getElementById('bfSfStep1');
725
+ const step2 = document.getElementById('bfSfStep2');
726
+ if (step1) step1.classList.add('hidden');
727
+ if (step2) step2.classList.remove('hidden');
728
+ const nameInput = document.getElementById('bfSfCardName');
729
+ if (nameInput) nameInput.focus();
730
+ };
731
+
732
+ const showSuperFanSummaryStep = () => {
733
+ const step1 = document.getElementById('bfSfStep1');
734
+ const step2 = document.getElementById('bfSfStep2');
735
+ if (step2) step2.classList.add('hidden');
736
+ if (step1) step1.classList.remove('hidden');
737
+ };
738
+
739
+ const formatCardNumber = (input) => {
740
+ let v = input.value.replace(/\D/g, '').substring(0, 16);
741
+ let formatted = v.match(/.{1,4}/g);
742
+ input.value = formatted ? formatted.join(' ') : '';
743
+ };
744
+
745
+ const formatCardExpiry = (input) => {
746
+ let v = input.value.replace(/\D/g, '').substring(0, 4);
747
+ if (v.length >= 2) {
748
+ v = v.substring(0, 2) + '/' + v.substring(2);
749
  }
750
+ input.value = v;
751
+ };
752
+
753
+ const confirmSuperFanPayment = () => {
754
+ const name = document.getElementById('bfSfCardName')?.value.trim();
755
+ const number = document.getElementById('bfSfCardNumber')?.value.replace(/\s/g, '');
756
+ const expiry = document.getElementById('bfSfCardExpiry')?.value.trim();
757
+ const cvc = document.getElementById('bfSfCardCvc')?.value.trim();
758
+ const errEl = document.getElementById('bfSfPaymentError');
759
+
760
+ // Validate fields
761
+ if (!name) {
762
+ if (errEl) { errEl.textContent = 'Please enter the name on your card'; errEl.classList.remove('hidden'); }
763
+ document.getElementById('bfSfCardName')?.classList.add('error');
764
+ return;
765
+ }
766
+ document.getElementById('bfSfCardName')?.classList.remove('error');
767
+
768
+ if (!number || number.length < 13) {
769
+ if (errEl) { errEl.textContent = 'Please enter a valid card number'; errEl.classList.remove('hidden'); }
770
+ document.getElementById('bfSfCardNumber')?.classList.add('error');
771
+ return;
772
+ }
773
+ document.getElementById('bfSfCardNumber')?.classList.remove('error');
774
+
775
+ if (!expiry || !/^\d{2}\/\d{2}$/.test(expiry)) {
776
+ if (errEl) { errEl.textContent = 'Please enter a valid expiry date (MM/YY)'; errEl.classList.remove('hidden'); }
777
+ document.getElementById('bfSfCardExpiry')?.classList.add('error');
778
+ return;
779
+ }
780
+ document.getElementById('bfSfCardExpiry')?.classList.remove('error');
781
+
782
+ if (!cvc || cvc.length < 3) {
783
+ if (errEl) { errEl.textContent = 'Please enter a valid CVC'; errEl.classList.remove('hidden'); }
784
+ document.getElementById('bfSfCardCvc')?.classList.add('error');
785
+ return;
786
+ }
787
+ document.getElementById('bfSfCardCvc')?.classList.remove('error');
788
+
789
+ // Hide error, show processing
790
+ if (errEl) errEl.classList.add('hidden');
791
+ document.getElementById('bfSfStep2')?.classList.add('hidden');
792
+ document.getElementById('bfSfStep3')?.classList.remove('hidden');
793
+
794
+ // Simulate payment processing (2s delay)
795
+ const last4 = number.slice(-4);
796
+ setTimeout(() => {
797
+ // Activate subscription with rich data
798
+ const key = 'bf_superfan';
799
+ let subs = [];
800
+ try { subs = JSON.parse(localStorage.getItem(key) || '[]'); } catch { subs = []; }
801
+ migrateSuperFanData();
802
+ const slug = _sfArtistName.toLowerCase().replace(/\s+/g, '-');
803
+ const existing = subs.find(s => typeof s === 'string' ? s === slug : s.slug === slug);
804
+ if (!existing) {
805
+ subs.push({
806
+ slug: slug,
807
+ name: _sfArtistName,
808
+ image: _sfArtistImage,
809
+ date: new Date().toISOString(),
810
+ active: true,
811
+ payment: { last4: last4, amount: 25, currency: 'USD' }
812
+ });
813
+ localStorage.setItem(key, JSON.stringify(subs));
814
+ }
815
+
816
+ // Record transaction
817
+ try {
818
+ const transactions = JSON.parse(localStorage.getItem('transactions') || '[]');
819
+ transactions.push({
820
+ type: 'subscription',
821
+ amount: 25,
822
+ artist: _sfArtistName,
823
+ tier: 'Super Fan',
824
+ date: new Date().toISOString(),
825
+ fee: 3.75
826
+ });
827
+ localStorage.setItem('transactions', JSON.stringify(transactions));
828
+ } catch {}
829
+
830
+ // Show success step
831
+ document.getElementById('bfSfStep3')?.classList.add('hidden');
832
+ document.getElementById('bfSfStep4')?.classList.remove('hidden');
833
+ if (window.lucide) lucide.createIcons();
834
+
835
+ // Update all Super Fan buttons on page
836
+ updateSuperFanButtons();
837
+
838
+ // Auto-close modal after 2.5s and show toast
839
+ setTimeout(() => {
840
+ closeSuperFanModal();
841
+ showToast('You are now a Super Fan of ' + _sfArtistName + ' \ud83c\udfa7');
842
+ if (window.lucide) lucide.createIcons();
843
+ }, 2500);
844
+ }, 2000);
845
  };
846
 
847
  const isSuperFanOf = (artistName) => {
 
908
  init, showSignInModal, closeSignInModal, handleSignIn,
909
  showSignUpForm, showSignInForm, showChooseType, handleSignUp,
910
  adjustTopNav, showToast, syncPlayer, playTrack, togglePlay,
911
+ showSuperFanModal, closeSuperFanModal, confirmSuperFanPayment, showSuperFanPaymentStep, showSuperFanSummaryStep, formatCardNumber, formatCardExpiry, isSuperFanOf, updateSuperFanButtons,
912
  getSuperFanSubscriptions, cancelSuperFanSubscription
913
  };
914
  })();