Skip to content

Commit

Permalink
fix(modules): Ensure BR phone numbers formatted up to 11 digits on ch…
Browse files Browse the repository at this point in the history
…eckout

To handle masked info (partial login) edited on checkout
  • Loading branch information
leomp12 committed Sep 30, 2024
1 parent 481d366 commit 6ee6f4d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/apps/pagarme/src/pagarme-create-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,18 @@ export default async (modBody: AppModuleBody<'create_transaction'>) => {
external_id: buyer.customer_id,
type: buyer.registry_type === 'j' ? 'corporation' : 'individual',
country: (buyer.doc_country || 'BR').toLowerCase(),
phone_numbers: [`+${(buyer.phone.country_code || '55')}${buyer.phone.number}`],
documents: [{
type: buyer.registry_type === 'j' ? 'cnpj' : 'cpf',
number: buyer.doc_number,
}],
};
const birthDate = buyer.birth_date;
const { phone, birth_date: birthDate } = buyer;
if (phone?.number) {
pagarmeTransaction.customer.phone_numbers = [
`+${(phone.country_code || '55')}`
+ `${phone.number.substring(phone.number.length - 11)}`,
];
}
if (birthDate && birthDate.year && birthDate.day && birthDate.month) {
const yearDiff = date.getFullYear() - birthDate.year;
if (
Expand Down
7 changes: 7 additions & 0 deletions packages/modules/src/firebase/checkout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ export default async (req: Request, res: Response) => {
customer.phones = savedCustomer.phones;
}
}
customer.phones?.forEach((phone) => {
if (phone.country_code === 55 || !phone.country_code) {
// BR
if (phone.number.length <= 11) return;
phone.number = `${phone.number.substring(phone.number.length - 11)}`;
}
});
customer._id = customerId;
const fixMaskedAddr = (bodyAddr: typeof body.shipping.to) => {
if (bodyAddr.line_address?.includes('***') || bodyAddr.name?.includes('***')) {
Expand Down

0 comments on commit 6ee6f4d

Please sign in to comment.