0
votes

So I am using google functions to write a script to auto pay my workers! In my back end i have stored the public token and account id.. I am trying to use plaid to turn into a stripe token then use stripe to do the transfer! The stripe thing is working but the plaid functions wont return the new stripe bank account number.. any ideas?

plaidClient.exchangePublicToken("public-sandbox-6be57fb5-3286-4bc8-a770-54a16ea39283", 
res => { 
var accessToken = res.access_token; 
// debugging = exchangedata.access_token; 
//debugging = err.message; 
// Generate a bank account token 
plaidClient.createStripeToken(accessToken, snapshot.val().plaid_account_id, 
res => { 
bankAccountToken = res.stripe_bank_account_token; 
stripe.transfers.create({ 
amount: (Number(appointmentchildSnapshot.val().price)/3).toString(), 
currency: "usd", 
destination:bankAccountToken, 
transfer_group: "ORDER_95" 
},(_err, transfer)=> { 
// asynchronously called 
}); 
});
1

1 Answers

0
votes

Make you use double " " when declaring your client secret and stuff!

In order to test for errors use res.json(Error:responsetowhatfunction you are using)

-- Some bank tokens do not work with Plaid unfortunately in sandbox and they also expire pretty quickly so if its not working create a new token and try again

---With the error log stuff you can keep track of when this happens

   await plaidClient.exchangePublicToken(snapshot.val().plaid_token, 
      async (error,response1) => {
        if (error !== null) {
          res.json({error:snapshot.val().plaid_token});
        } else {

        var accessToken = response1.access_token;
        //res.json(accessToken);
       // debugging = exchangedata.access_token;
        //debugging = err.message;
        // Generate a bank account token
       debugging = await plaidClient.createStripeToken(accessToken, snapshot.val().plaid_account_id, 
        async (error2,response2) => {

          if(error2!==null){
            res.json({error:snapshot.val().plaid_account_id});

          }else{
          //res.json({error:response2});
         // bankAccountToken = response2.stripe_bank_account_token;
          stripe.transfers.create({
            amount: (Number(appointmentchildSnapshot.val().price)/3).toString(),
            currency: "usd",
            destination:response2.stripe_bank_account_token,
            transfer_group: "ORDER_95"
          },(_err, transfer)=> {
            // asynchronously called
          });
        }