fix: handle PAYMENT_DELETED webhook event properly and add DELETED/CANCELED statuses to Payment type
Build and Deploy (Gitea) / build-and-deploy (push) Successful in 43s
Details
Build and Deploy (Gitea) / build-and-deploy (push) Successful in 43s
Details
This commit is contained in:
parent
6df27544a6
commit
5be0eda2a2
|
|
@ -1035,13 +1035,14 @@ app.post('/api/webhooks/asaas', (req: Request, res: Response) => {
|
||||||
if (userPaymentIdx >= 0) {
|
if (userPaymentIdx >= 0) {
|
||||||
db.payments[userPaymentIdx].status =
|
db.payments[userPaymentIdx].status =
|
||||||
event === 'PAYMENT_RECEIVED' || event === 'PAYMENT_CONFIRMED' ? 'CONFIRMED' :
|
event === 'PAYMENT_RECEIVED' || event === 'PAYMENT_CONFIRMED' ? 'CONFIRMED' :
|
||||||
event === 'PAYMENT_OVERDUE' ? 'OVERDUE' : db.payments[userPaymentIdx].status;
|
event === 'PAYMENT_OVERDUE' ? 'OVERDUE' :
|
||||||
|
event === 'PAYMENT_DELETED' ? 'DELETED' : db.payments[userPaymentIdx].status;
|
||||||
|
|
||||||
if (event === 'PAYMENT_RECEIVED' || event === 'PAYMENT_CONFIRMED') {
|
if (event === 'PAYMENT_RECEIVED' || event === 'PAYMENT_CONFIRMED') {
|
||||||
db.payments[userPaymentIdx].paidAt = new Date().toISOString();
|
db.payments[userPaymentIdx].paidAt = new Date().toISOString();
|
||||||
}
|
}
|
||||||
} else {
|
} else if (event !== 'PAYMENT_DELETED') {
|
||||||
// Register a new payment log
|
// Register a new payment log (unless it's a deletion of an unknown payment)
|
||||||
db.payments.push({
|
db.payments.push({
|
||||||
id: payment.id || `pay_wh_${Math.random().toString(36).substring(2, 9)}`,
|
id: payment.id || `pay_wh_${Math.random().toString(36).substring(2, 9)}`,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,7 @@ export interface SubscriptionPayment {
|
||||||
id: string;
|
id: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
value: number;
|
value: number;
|
||||||
status: 'PENDING' | 'RECEIVED' | 'CONFIRMED' | 'OVERDUE' | 'REFUNDED';
|
status: 'PENDING' | 'RECEIVED' | 'CONFIRMED' | 'OVERDUE' | 'REFUNDED' | 'DELETED' | 'CANCELED';
|
||||||
billingType: 'PIX' | 'CREDIT_CARD' | 'BOLETO';
|
billingType: 'PIX' | 'CREDIT_CARD' | 'BOLETO';
|
||||||
invoiceUrl: string;
|
invoiceUrl: string;
|
||||||
dueDate: string;
|
dueDate: string;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue