feat(payments): log Helcim charge on free-to-paid upgrade
In the Case 1 (free→paid) branch of update-contribution, after the subscription is created and the member row is updated, fetch the newest paid Helcim transaction and upsert a Payment with paymentType=cadence and sendConfirmation=true. Paid→paid (Case 3) is intentionally NOT wired — no new transaction occurs at amount change; the next recurring charge is captured by the reconciliation script.
This commit is contained in:
parent
49cfb47fff
commit
fc09760a41
2 changed files with 38 additions and 0 deletions
|
|
@ -12,7 +12,9 @@ import {
|
|||
updateHelcimSubscription,
|
||||
cancelHelcimSubscription,
|
||||
generateIdempotencyKey,
|
||||
listHelcimCustomerTransactions,
|
||||
} from "../../utils/helcim.js";
|
||||
import { upsertPaymentFromHelcim } from "../../utils/payments.js";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
try {
|
||||
|
|
@ -118,6 +120,27 @@ export default defineEventHandler(async (event) => {
|
|||
{ runValidators: false }
|
||||
);
|
||||
|
||||
try {
|
||||
const txs = await listHelcimCustomerTransactions(customerCode);
|
||||
const latestPaid = txs.find((t) => t.status === 'paid');
|
||||
if (latestPaid) {
|
||||
await upsertPaymentFromHelcim(
|
||||
{
|
||||
_id: member._id,
|
||||
email: member.email,
|
||||
name: member.name,
|
||||
helcimCustomerId: member.helcimCustomerId,
|
||||
helcimSubscriptionId: subscription.id,
|
||||
billingCadence: cadence,
|
||||
},
|
||||
latestPaid,
|
||||
{ paymentType: cadence, sendConfirmation: true }
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('[payments] free→paid charge log failed, will be picked up by reconciliation:', err?.message || err);
|
||||
}
|
||||
|
||||
logContributionChange();
|
||||
|
||||
return {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue