@@ -248,13 +248,12 @@ const handleWehook = async (req, res) => {
248248 }
249249
250250 if ( charge . order ) {
251- // payment update (order in pagarme)
252251 const { order : orderPagarme , status } = charge ;
253252 logger . info ( `Pagar.me charge ${ orderPagarme . id } ${ status } ` ) ;
254253 const order = await getOrderIntermediatorTransactionId ( orderPagarme . id ) ;
255254 if ( order ) {
256- if ( order . financial_status ?. current !== parserChangeStatusToEcom ( status ) ) {
257- // updadte status
255+ const newEcomStatus = parserChangeStatusToEcom ( status ) ;
256+ if ( order . financial_status ?. current !== newEcomStatus ) {
258257 let isUpdateTransaction = false ;
259258 let transactionBody ;
260259 const transaction = order . transactions . find (
@@ -270,12 +269,13 @@ const handleWehook = async (req, res) => {
270269 } else if ( transactionPagarme . transaction_type === 'boleto' ) {
271270 notificationCode += `${ transactionPagarme . gateway_id || '' } ;` ;
272271 } else if ( transactionPagarme . transaction_type === 'pix' ) {
273- let notes = transaction . notes ;
274- // pix_provider_tid"
275- notes = notes . replaceAll ( 'display:block' , 'display:none' ) ; // disable QR Code
276- notes = `${ notes } # PIX Aprovado` ;
277- transactionBody = { notes } ;
278- isUpdateTransaction = true ;
272+ if ( newEcomStatus === 'paid' ) {
273+ let notes = transaction . notes ;
274+ notes = notes . replaceAll ( 'display:block' , 'display:none' ) ;
275+ notes = `${ notes } # PIX Aprovado` ;
276+ transactionBody = { notes } ;
277+ isUpdateTransaction = true ;
278+ }
279279 }
280280 let statusDateTime ;
281281 if ( order . payments_history ?. some ( ( { flags } ) => flags ?. includes ( 'pagarme-expired' ) ) ) {
@@ -285,7 +285,7 @@ const handleWehook = async (req, res) => {
285285 }
286286 const bodyPaymentHistory = {
287287 date_time : statusDateTime ,
288- status : parserChangeStatusToEcom ( status ) ,
288+ status : newEcomStatus ,
289289 notification_code : notificationCode ,
290290 flags : [ 'PagarMe' ] ,
291291 } ;
@@ -297,7 +297,7 @@ const handleWehook = async (req, res) => {
297297 await updateTransaction ( order . _id , transactionBody , transaction . _id )
298298 . catch ( logger . error ) ;
299299 }
300- logger . info ( `${ order . _id } update to ${ parserChangeStatusToEcom ( status ) } ` ) ;
300+ logger . info ( `${ order . _id } update to ${ newEcomStatus } ` ) ;
301301 return res . sendStatus ( 201 ) ;
302302 }
303303 return res . sendStatus ( 200 ) ;
0 commit comments