feat: add payment options on student portal

This commit is contained in:
Jose Selesan
2026-10-28 16:34:28 -03:00
parent bc5f676cea
commit 9e4d34b5d8
8 changed files with 40 additions and 15 deletions

View File

@@ -19,6 +19,7 @@ import { logger } from '@/logger';
import { PlanGuard } from '@/modules/billing/lib/entitlements';
import { getMpAccessToken } from '@/modules/mp';
import { createCheckoutPreference, getWebOrigin, MpApiError } from '@/modules/mp/lib';
import { CHECKOUT_BACK_PATH } from '../../lib';
type BatchDeps = {
db?: Pick<PrismaClient, 'group' | 'attendee' | 'payment' | 'user'>;
@@ -95,7 +96,7 @@ export class CreatePaymentBatch {
return token;
}
const backUrl = `${this.deps.webOrigin ?? getWebOrigin()}/payments`;
const backUrl = `${this.deps.webOrigin ?? getWebOrigin()}${CHECKOUT_BACK_PATH}`;
const dueDate = new Date(input.dueDate);
const title = input.description?.trim() || group.name;
const createPreference = this.deps.createPreference ?? createCheckoutPreference;

View File

@@ -12,7 +12,7 @@ import { logger } from '@/logger';
import { PlanGuard } from '@/modules/billing/lib/entitlements';
import { getMpAccessToken } from '@/modules/mp';
import { createCheckoutPreference, getWebOrigin } from '@/modules/mp/lib';
import { type PaymentRecord, toPaymentDto } from '../../lib';
import { CHECKOUT_BACK_PATH, type PaymentRecord, toPaymentDto } from '../../lib';
type RenewDeps = {
db?: Pick<PrismaClient, 'payment' | 'user'>;
@@ -83,7 +83,7 @@ export class RenewPaymentLink {
return token;
}
const backUrl = `${this.deps.webOrigin ?? getWebOrigin()}/payments`;
const backUrl = `${this.deps.webOrigin ?? getWebOrigin()}${CHECKOUT_BACK_PATH}`;
const createPreference = this.deps.createPreference ?? createCheckoutPreference;
let preference: { initPoint: string; id: string };

View File

@@ -1,5 +1,9 @@
import type { PaymentDto } from '@gruperly/shared';
/* Where Mercado Pago sends whoever paid a Checkout Pro link: the student app
(without a student session it falls through to /access). */
export const CHECKOUT_BACK_PATH = '/student/payments';
export type PaymentRecord = {
id: string;
groupId: string;

View File

@@ -1 +1 @@
export { type PaymentRecord, toPaymentDto } from './helpers';
export { CHECKOUT_BACK_PATH, type PaymentRecord, toPaymentDto } from './helpers';

View File

@@ -142,7 +142,7 @@ describe('create payments batch', () => {
unitPrice: 120,
currencyId: 'ARS',
externalReference: 'pay-1',
backUrl: `${webOrigin}/payments`,
backUrl: `${webOrigin}/student/payments`,
});
});

View File

@@ -101,7 +101,7 @@ describe('renew payment link', () => {
unitPrice: 120,
currencyId: 'ARS',
externalReference: 'pay-1',
backUrl: `${webOrigin}/payments`,
backUrl: `${webOrigin}/student/payments`,
});
expect(prisma.payment.update).toHaveBeenCalledWith({
where: { id: 'pay-1' },