File size: 1,729 Bytes
b0798af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { Injectable } from '@nestjs/common';

@Injectable()
export class SubscriptionService {
  getPlans() {
    return [
      {
        id: 'free',
        name: 'Free',
        price: '$0.00/mo',
        description: 'Shuffle-only playback with periodic ads.',
      },
      {
        id: 'premium_individual',
        name: 'Premium Individual',
        price: '$10.99/mo',
        description: 'On-demand, ad-free, 320kbps Hi-Fi audio.',
      },
      {
        id: 'premium_duo',
        name: 'Premium Duo',
        price: '$14.99/mo',
        description: '2 Premium accounts under one roof.',
      },
      {
        id: 'premium_family',
        name: 'Premium Family',
        price: '$16.99/mo',
        description: 'Up to 6 accounts with parental controls.',
      },
      {
        id: 'premium_student',
        name: 'Premium Student',
        price: '$5.99/mo',
        description: 'Discounted rate for eligible students.',
      },
    ];
  }

  getSubscription(userId: string) {
    return {
      user_id: userId,
      plan: 'free',
      status: 'active',
      stripe_customer_id: 'cus_xyz123',
      current_period_end: new Date(
        Date.now() + 30 * 24 * 60 * 60 * 1000,
      ).toISOString(),
    };
  }

  createCheckoutSession(userId: string, planId: string) {
    return {
      url: `https://checkout.stripe.com/c/pay/cs_test_${Date.now()}?plan=${planId}`,
      session_id: `cs_test_${Date.now()}`,
    };
  }

  cancelSubscription(userId: string) {
    return {
      success: true,
      message: 'Subscription set to cancel at current period end.',
    };
  }

  handleStripeWebhook(event: any) {
    return { received: true, type: event?.type || 'payment_intent.succeeded' };
  }
}