feat(payments): automatic monthly charges with combined links per payer
- Teacher picks a day of the month in Settings; an hourly job creates the fees of all monthly groups on that day in the teacher's time zone (one run per teacher and month, partial unique index per attendee/period). - One Mercado Pago link per payer (PaymentCheckout): the adult in charge bundles their kids and their own fees; external_reference chk_<id>, dedicated webhook and reconciliation mark every fee PAID at once. - Person.payWithMercadoPago toggle (default on): off creates the fee without a link so the student pays by transfer. - A fee paid some other way supersedes its combined link and expires the preference; renewing rebuilds the combined link or a single one. - Optional WhatsApp delivery (PAYMENT_LINK kind, new Kapso template); weekly reminders now go once per combined link. - Web: auto charge settings card, per-student toggle, combined link label in Cobros and "Pay all" in the student app, in the four locales. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -93,6 +93,36 @@ function reengagement(provider: MessagingProvider) {
|
||||
}
|
||||
|
||||
describe('payment reminders', () => {
|
||||
it('reminds a combined link once, to whoever pays it, with the total', async () => {
|
||||
const checkout = {
|
||||
id: 'chk-1',
|
||||
status: 'OPEN',
|
||||
amount: { toString: () => '40000' },
|
||||
payer: { id: 'g-1', fullName: 'Laura Gómez', phone: '11 2345-6789' },
|
||||
payments: [
|
||||
{ group: { name: 'Yoga Martes' }, attendee: { person: { id: 'p-1', fullName: 'Juan Gómez' } } },
|
||||
{ group: { name: 'Yoga Martes' }, attendee: { person: { id: 'p-2', fullName: 'Ana Gómez' } } },
|
||||
],
|
||||
};
|
||||
db.payment.findMany.mockResolvedValue([
|
||||
payment('pay-1', { id: 'att-1', fullName: 'Juan Gómez' }, { checkout, checkoutUrl: 'https://mpago.la/chk' }),
|
||||
payment('pay-2', { id: 'att-2', fullName: 'Ana Gómez' }, { checkout, checkoutUrl: 'https://mpago.la/chk' }),
|
||||
]);
|
||||
const provider = fakeProvider();
|
||||
|
||||
const totals = await reminders(provider).execute();
|
||||
|
||||
expect(totals).toEqual({ sent: 1, skipped: 0, failed: 0 });
|
||||
const [, , message] = (provider.send as ReturnType<typeof mock>).mock.calls[0] ?? [];
|
||||
expect(message).toMatchObject({
|
||||
kind: 'PAYMENT_REMINDER',
|
||||
studentName: 'Laura Gómez',
|
||||
groupName: 'Yoga Martes (Juan) y Yoga Martes (Ana)',
|
||||
paymentLink: 'https://mpago.la/chk',
|
||||
});
|
||||
expect((message as { amount: string }).amount).toContain('40.000');
|
||||
});
|
||||
|
||||
it('only looks at groups with the automation on and an active account of this provider', async () => {
|
||||
await reminders(fakeProvider()).execute();
|
||||
|
||||
@@ -135,6 +165,7 @@ describe('payment reminders', () => {
|
||||
groupId: 'group-1',
|
||||
attendeeId: 'att-1',
|
||||
paymentId: 'pay-1',
|
||||
checkoutId: null,
|
||||
kind: 'PAYMENT_REMINDER',
|
||||
provider: 'OPENWA',
|
||||
periodKey: '2026-W43',
|
||||
|
||||
Reference in New Issue
Block a user