Skip to content

Commit fb7422f

Browse files
committed
fix: replicating full address on payer info for boleto
1 parent f983e57 commit fb7422f

1 file changed

Lines changed: 22 additions & 10 deletions

File tree

functions/routes/ecom/modules/create-transaction.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ exports.post = ({ appSdk, admin }, req, res) => {
2424
} catch (e) {
2525
paymentMethodId = params.credit_card.company || 'visa'
2626
}
27+
} else if (isPix) {
28+
paymentMethodId = 'pix'
2729
} else if (params.payment_method.code === 'banking_billet') {
2830
paymentMethodId = 'bolbradesco'
2931
} else if (params.payment_method.code === 'account_deposit') {
@@ -53,21 +55,26 @@ exports.post = ({ appSdk, admin }, req, res) => {
5355
}
5456
}
5557

58+
const parseAddress = (addr, { isFullAddress = false } = {}) => {
59+
const mpAddress = {
60+
zip_code: addr.zip,
61+
street_name: addr.street,
62+
street_number: addr.number || 'S/N'
63+
}
64+
if (isFullAddress) {
65+
if (addr.borough) mpAddress.neighborhood = addr.borough
66+
if (addr.city) mpAddress.city = addr.city
67+
if (addr.province_code) mpAddress.federal_unit = addr.province_code
68+
}
69+
return mpAddress
70+
}
5671
if (params.to && params.to.street) {
5772
additionalInfo.shipments = {
58-
receiver_address: {
59-
zip_code: params.to.zip,
60-
street_name: params.to.street,
61-
street_number: params.to.number || 0
62-
}
73+
receiver_address: parseAddress(params.to)
6374
}
6475
}
6576
if (params.billing_address && params.billing_address.street) {
66-
additionalInfo.payer.address = {
67-
zip_code: params.billing_address.zip,
68-
street_name: params.billing_address.street,
69-
street_number: params.billing_address.number || 0
70-
}
77+
additionalInfo.payer.address = parseAddress(params.billing_address)
7178
} else if (additionalInfo.shipments) {
7279
additionalInfo.payer.address = additionalInfo.shipments.receiver_address
7380
}
@@ -119,6 +126,11 @@ exports.post = ({ appSdk, admin }, req, res) => {
119126
ecom_order_id: orderId
120127
}
121128
}
129+
if (isPix || paymentMethodId.startsWith('bol')) {
130+
if (params.to) {
131+
payment.payer.address = parseAddress(params.to, { isFullAddress: true })
132+
}
133+
}
122134
if (isPix && config.account_deposit?.exp_minutes) {
123135
const d = new Date()
124136
d.setMinutes(d.getMinutes() + config.account_deposit.exp_minutes)

0 commit comments

Comments
 (0)