@@ -90,29 +90,19 @@ export const pagaleve = {
90
90
try {
91
91
const { data : order } = await api . get ( orderEndpoint ) ;
92
92
if ( order ?. transactions ) {
93
- const transactionIndex = order . transactions . findIndex ( ( { intermediator } ) => {
93
+ const transaction = order . transactions . find ( ( { intermediator } ) => {
94
94
return intermediator ?. transaction_id === id ;
95
95
} ) ;
96
- const transactionId = order . transactions [ transactionIndex ] ?. _id ;
97
- if ( ! transactionId ) {
96
+ if ( ! transaction ) {
98
97
res . sendStatus ( 404 ) ;
99
98
return ;
100
99
}
101
-
102
100
await api . post ( `${ orderEndpoint } /payments_history` , {
103
101
date_time : new Date ( ) . toISOString ( ) ,
104
102
status : parseStatusToEcom ( state ) ,
105
- transaction_id : transactionId ,
103
+ transaction_id : transaction . _id ,
106
104
flags : [ 'pagaleve' ] ,
107
105
} as Exclude < ( typeof order ) [ 'payments_history' ] , undefined > [ 0 ] ) ;
108
-
109
- await api . patch ( `${ orderEndpoint } /transactions/${ transactionId } ` , {
110
- intermediator : {
111
- transaction_id : id || '' ,
112
- transaction_code : id || '' ,
113
- } ,
114
- } as Partial < Exclude < ( typeof order ) [ 'transactions' ] , undefined > [ 0 ] > ) ;
115
-
116
106
if ( state . toLowerCase ( ) === 'authorized' ) {
117
107
const _pagaleve = new Pagaleve ( appData . username , appData . password , isSandbox ) ;
118
108
await _pagaleve . preparing ;
0 commit comments