Edie W.
Edie W.

Reputation: 867

Plaid link not opening w/ rails ENV

After following the Plaid integration tutorial on the Stripe website, I am unable to get the plaid link to work.

I have tried to replace the "env" and "key" variables with environment keys as follows:

<button id='linkButton'>Open Plaid Link</button>
<script src="https://cdn.plaid.com/link/v2/stable/link-initialize.js">
</script>
<script>
var linkHandler = Plaid.create({
  env: ENV['PLAID_ENV'],
  clientName: 'Divco',
  key: ENV['PLAID_PUBLIC_KEY'],
  product: ['auth'],
  selectAccount: true,
  onSuccess: function(public_token, metadata) {
    // Send the public_token and account ID to your app server.
    console.log('public_token: ' + public_token);
    console.log('account ID: ' + metadata.account_id);
  },
  onExit: function(err, metadata) {
    // The user exited the Link flow.
    if (err != null) {
      // The user encountered a Plaid API error prior to exiting.
    }
  },
});

// Trigger the Link UI
document.getElementById('linkButton').onclick = function() {
  linkHandler.open();
};

When I step back away from having "fancy" environment variables, inserting my keys directly, I don't have an issue. I feel like I have mistyped something... but for my life, I can't find it.

Upvotes: 0

Views: 734

Answers (1)

beauraF
beauraF

Reputation: 100

In fact, ENV is a Ruby call. You need to use <%= ENV[*] %> in your javascript and add the .erb extension to your javascript file.

You can use gem like Figaro to easily deal with ENV variables.

Upvotes: 2

Related Questions