Skip to content

Commit

Permalink
fix(mercadopago): Properly parsing all MP payment status
Browse files Browse the repository at this point in the history
  • Loading branch information
leomp12 committed Jan 21, 2025
1 parent 61f56e7 commit 843f9c6
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/apps/mercadopago/src/mp-create-transaction.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {
Orders,
AppModuleBody,
CreateTransactionParams,
CreateTransactionResponse,
Expand All @@ -7,14 +8,27 @@ import { getFirestore } from 'firebase-admin/firestore';
import config, { logger } from '@cloudcommerce/firebase/lib/config';
import axios from 'axios';

const parsePaymentStatus = (status: string) => {
type TransactionStatusEnum = Exclude<
Exclude<Orders['transactions'], undefined>[number]['status'],
undefined
>['current'];

const parsePaymentStatus = (status: string): TransactionStatusEnum => {
switch (status) {
case 'authorized':
case 'pending':
case 'refunded':
return status;
case 'rejected':
return 'voided';
case 'in_process':
return 'under_analysis';
case 'approved':
return 'paid';
case 'charged_back':
return 'in_dispute';
case 'cancelled':
return 'unauthorized';
default:
return 'pending';
}
Expand Down

0 comments on commit 843f9c6

Please sign in to comment.