• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

GEWIS / sudosos-backend / 18712298456

22 Oct 2025 09:50AM UTC coverage: 88.8% (-1.1%) from 89.868%
18712298456

Pull #612

github

web-flow
Merge 43836e960 into 33c42eb30
Pull Request #612: Fix UserDebtNotification not triggered when first product in multi-item transaction does not cause debt

1346 of 1628 branches covered (82.68%)

Branch coverage included in aggregate %.

5 of 5 new or added lines in 1 file covered. (100.0%)

79 existing lines in 4 files now uncovered.

7130 of 7917 relevant lines covered (90.06%)

1108.62 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

37.93
/src/controller/stripe-controller.ts
1
/**
2
 *  SudoSOS back-end API service.
3
 *  Copyright (C) 2024  Study association GEWIS
4
 *
5
 *  This program is free software: you can redistribute it and/or modify
6
 *  it under the terms of the GNU Affero General Public License as published
7
 *  by the Free Software Foundation, either version 3 of the License, or
8
 *  (at your option) any later version.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU Affero General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU Affero General Public License
16
 *  along with this program.  If not, see <https://www.gnu.org/licenses/>.
17
 *
18
 *  @license
19
 */
20

21
/**
22
 * This is the module page of the stripe-controller.
23
 *
24
 * @module stripe
25
 */
26

27
import log4js, { Logger } from 'log4js';
2✔
28
import { Response } from 'express';
29
import Dinero from 'dinero.js';
2✔
30
import BaseController, { BaseControllerOptions } from './base-controller';
2✔
31
import Policy from './policy';
32
import { RequestWithToken } from '../middleware/token-middleware';
33
import StripeService from '../service/stripe-service';
2✔
34
import { StripeRequest } from './request/stripe-request';
35
import BalanceService from '../service/balance-service';
2✔
36

37
export default class StripeController extends BaseController {
2✔
38
  private logger: Logger = log4js.getLogger('StripeController');
1✔
39

40
  private stripeService: StripeService;
41

42
  /**
43
   * Create a new stripe controller instance
44
   * @param options
45
   */
46
  public constructor(options: BaseControllerOptions) {
47
    super(options);
1✔
48
    this.logger.level = process.env.LOG_LEVEL;
1✔
49
    this.stripeService = new StripeService();
1✔
50
  }
51

52
  /**
53
   * @inheritDoc
54
   */
55
  public getPolicy(): Policy {
56
    return {
1✔
57
      '/deposit': {
58
        POST: {
UNCOV
59
          policy: async (req) => this.roleManager.can(
×
60
            req.token.roles, 'create', 'all', 'StripeDeposit', ['*'],
61
          ),
62
          handler: this.createStripeDeposit.bind(this),
63
          body: { modelName: 'StripeRequest' },
64
        },
65
      },
66
    };
67
  }
68

69
  /**
70
   * POST /stripe/deposit
71
   * @summary Start the stripe deposit flow
72
   * @operationId deposit
73
   * @tags stripe - Operations of the stripe controller
74
   * @param {StripeRequest} request.body.required - The deposit that should be created
75
   * @return {StripePaymentIntentResponse} 200 - Payment Intent information
76
   * @return {string} 500 - Internal server error
77
   * @security JWT
78
   */
79
  public async createStripeDeposit(req: RequestWithToken, res: Response): Promise<void> {
UNCOV
80
    this.logger.trace('Create a new stripe deposit by user', req.token.user);
×
UNCOV
81
    const request = req.body as StripeRequest;
×
82

UNCOV
83
    try {
×
UNCOV
84
      const amount = Dinero(request.amount);
×
UNCOV
85
      const balance = await new BalanceService().getBalance(req.token.user.id);
×
86

87
      // Check if top-up satisfies minimum in accordance with TOS.
UNCOV
88
      if (!StripeService.validateStripeRequestMinimumAmount(balance, request)) {
×
UNCOV
89
        res.status(422).json({ error: 'Top-up amount is too low' });
×
UNCOV
90
        return;
×
91
      }
92

93
      // Check if top-up satisfies maximum in accordance with TOS.
UNCOV
94
      if (!StripeService.validateStripeRequestMaximumAmount(balance, request)) {
×
UNCOV
95
        res.status(422).json({ error: 'Top-up amount is too high' });
×
UNCOV
96
        return;
×
97
      }
98

UNCOV
99
      const result = await this.stripeService.createStripePaymentIntent(req.token.user, amount);
×
UNCOV
100
      res.status(200).json(result);
×
101
    } catch (error) {
102
      this.logger.error('Could not create Stripe payment intent:', error);
×
103
      res.status(500).send('Internal server error.');
×
104
    }
105
  }
106
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc