Quantcast
Channel: Active questions tagged paypal - Stack Overflow
Viewing all articles
Browse latest Browse all 516

calling axios multiple times

$
0
0

I am trying to make a fetch function where upon fetching the transaction data, it will run a payout function to pay the person, and then it will update the transaction data value 'go' to false so that next time it fetches it wont pay that person again. Code:

app.get('/solana-transactions', async (req, res) => {  try {    const transactions = await program.fetchAllPaypalTransactions();    const transactionDetails = transactions.map(transaction => ({      id: transaction.id,      amount: transaction.amount / 100.00,      receiverEmail: transaction.sender    }));    if (transactionDetails.length > 0) {      const payoutPromises = transactionDetails.map(details =>        axios.post('http://localhost:3000/send-money', {          amount: details.amount,          receiverEmail: details.receiverEmail        })        .then(async response => {          console.log('Payout posted successfully:', response.data);          try {            const updateResponse = await axios.post('http://localhost:3000/edit-transaction', {              id: details.id,              go: false            });            console.log('Transaction updated successfully:', updateResponse.data);          } catch (updateError) {            console.error('Error updating transaction:', updateError);          }        })        .catch(error => {          console.error('Error paying out transaction or updating transaction:', error);        })      );    }    res.json(transactions);  } catch (err) {    console.error('Error fetching Solana transactions:', err);    res.status(500).send('Error fetching Solana transactions');  }});

app.post("/send-money", async (req, res) => {    const request = new paypal2.payouts.PayoutsPostRequest();    const { receiverEmail, amount} = req.body;    request.requestBody({        sender_batch_header: {            sender_batch_id: `batch-${Math.random()}`,            email_subject: 'You have a payment',            email_message: 'You have received a payment! Thanks for using our service.'        },        items: [{            recipient_type: 'EMAIL',            amount: {                value: amount,                currency: 'USD'            },            receiver: receiverEmail,            note: 'Thank you for your service!',            sender_item_id: `item-${Math.random()}`        }]    });    try {        console.log("hallo");        const response = await paypalClient.execute(request);        console.log(`Payout created with ID: ${response.result.batch_header.payout_batch_id}`);    } catch (err) {        console.error(`Error creating payout: ${err.message}`);    }})app.post('/edit-transaction', async (req, res) => {  const { id, go} = req.body;  try {    console.log("as")    await program.updatePaypalTransaction(id, go);    res.status(200).send({ message: 'Transaction updated successfully' });  } catch (err) {    console.error('Error updating transaction:', err);    res.status(500).send('Internal Server Error');  }});

Everything works but I cant seem to get the update function to be called, I have tested the update function individually multiple times. Any help would be appreciated, thank you


Viewing all articles
Browse latest Browse all 516

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>