plaid / pattern

An example end-to-end Plaid integration to create items and fetch transaction data
MIT License
435 stars 217 forks source link

Clarification - ngrok - database transaction / item fetching / populating #193

Closed johndpope closed 2 years ago

johndpope commented 2 years ago

I have an external webpage that is a scaled down / quarantined version of this repo with major restrictions. It has user session management implemented - https://gist.github.com/johndpope/d63a9111ce4388699c9eb6142858e465 I'm reusing some client code from this library sparingly - the server backend is the same.

The architecture is

This thin-cient signup form / page is just a form to let the user click add bank account. End user doesn't need to see any more than that / and don't need to see trasanctions - just a simple success confirmation - but....I have an admin control where original client code is still surfaced behind login wall / where I want the transactions to show.

I have 2 properties - they're sharing same server code using nginx to proxy stuff.

  1. www.covershot.app / has this code running - create username / add bank account / transactions sync correctly / show up.
  2. signup.covershot.app - transactions don't sync / are never fetched.

concretely this returns no results when client calls / inspecting db - there's no transactions... export const getTransactionsByUser = (userId: number) => api.get(/users/${userId}/transactions);

the identical server code is running same ngrok in both instances. (though a different subdomain)

again I can click Add bank account / login to chase account in sandbox - and see meta data. - that's all fine. what triggers the transactions to download and insert.... I have some understanding that this transaction syncing is all dependent on the link-event / link-token and associated itemId. These calls succeed - though maybe they're missing the itemId. where can I get this? the items when I hit api - just come back empty..

I'm not using socket updates on this thin-client ( I don't need updates to user telling me transactions were updated / though I can put these back....). Could this be the problem?

Is the transaction fetching / inserting into database all done via server code? what triggers this...?

From what I gather - it's kicked off by the itemid - I tried adding to thin-client but no joy. var event = { userId: pUserId, itemId: null }; const response = await api.post(/link-token, event); // N.B.

if it is as simple as passing the itemid to the backend to kick off the transaction syncing...how do I get the itemid....or is this supposed to populate automagically too....

UPDATE - digging deeper - so it seems I need the plaidItemId ??? - ngrok is running fine for 1.


/**
 * Handles all transaction webhook events. The transaction webhook notifies
 * you that a single item has new transactions available.
 *
 * @param {Object} requestBody the request body of an incoming webhook event
 * @param {Object} io a socket.io server instance.
 */
const handleTransactionsWebhook = async (requestBody, io) => {
  const {
    webhook_code: webhookCode,
    item_id: plaidItemId,
    new_transactions: newTransactions,
    removed_transactions: removedTransactions,
  } = requestBody;

  const serverLogAndEmitSocket = (additionalInfo, itemId) => {
    console.log(
      `WEBHOOK: TRANSACTIONS: ${webhookCode}: Plaid_item_id ${plaidItemId}: ${additionalInfo}`
    );
    // use websocket to notify the client that a webhook has been received and handled
    if (webhookCode) io.emit(webhookCode, { itemId });
  };

  switch (webhookCode) {
    case 'INITIAL_UPDATE': {
      // Fired when an Item's initial transaction pull is completed.
      // Note: The default pull is 30 days.
      const startDate = moment().subtract(30, 'days').format('YYYY-MM-DD');
      const endDate = moment().format('YYYY-MM-DD');
      await handleTransactionsUpdate(plaidItemId, startDate, endDate);
      const { id: itemId } = await retrieveItemByPlaidItemId(plaidItemId);
      serverLogAndEmitSocket(`${newTransactions} transactions to add.`, itemId);
      break;
    }

UPDATE from support ticket - case id 351354 https://dashboard.plaid.com/support/case/351354

it was claimed "Plaid Pattern requires the use of ngrok​ , specifically for webhooks - we are unable to offer any supplemental workarounds or troubleshoot errors resulting from its omission in your application." - that was by Steve.

But subsequently reading through the readme - it's apparent that that is not needed!!!!. I eroneously spent $99 / year subscription to overcome this limitation. Please tell Steve that.

_Do NOT use ngrok in production! It's only included here as a convenience for local development and is not meant to be a production-quality solution.

Don’t want to use ngrok? As long as you serve the app with an endpoint that is publicly exposed, all the Plaid webhooks will work. ._

I still have some confusion as there's parts of ngrok still intertwined with codebase - I'm totally ok with either way - I'm agnostic - one part is saying don't use it in production - ok - I won't. The other part is saying - you must use ngrok... does the sockets.jsx code depend on this?

I'm fine to keep ngrok running - but I need a solution where I get transaction hooks ongoingly - like weeks / months later. Maybe it's better to resort to storing session token - and running a sync process. I had this sort of working with golang.

johndpope commented 2 years ago

I’d skipped doing exchange token and now got the item Id. Things are clearer now.

Tarious1 commented 2 years ago

Thanks again.  So will you keep me up to date

Sent from Yahoo Mail on Android

On Tue, Nov 23, 2021 at 6:08 PM, John D. @.***> wrote:

I’d skipped doing exchange token and now got the item Id. Things are clearer now.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.