Search code examples
javascripthtmlplaid

How to build and display Consent Pane PLAID with PHP


i want to integrate PLAID system on my project based Laravel framework. Currently i'm developing on step to display Consent Pane PLAID from this doc PLAID LINK DOC. I'm using the javascript code. but i still failed to integrate it. here is my code

<!DOCTYPE html>
<html lang="en">
 <head>
  <meta charset="UTF-8" /> 
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Plaid</title> 
  <script src="https://cdn.plaid.com/link/v2/stable/link-initialize.js"></script>

 </head>
 <body > 

    plaid
 </body>

 <script>
    const handler = Plaid.create({
        token: 'link-sandbox-xxx',
        onSuccess: (public_token, metadata) => { 
            console.debug("onSuccess"); 
            console.log('public_token: ' + public_token);
            console.log('account ID: ' + metadata.account_id);
        },
        onLoad: () => {
            console.debug("onLoad");
        },
        onExit: (err, metadata) => {
            console.debug("onExit");
            console.log('metadata ' + metadata);
        },
        onEvent: (eventName, metadata) => {
            console.debug("onEvent");
        },
        receivedRedirectUri: "https://domainname.com/plaid",
    });
    handler.open();
   
 </script>
  
</html>

Display error

POST https://sandbox.plaid.com/link/workflow/start 400 (Bad Request)
Error: oauth uri does not contain a valid oauth_state_id query parameter.

i already added new URL my API menu on PLAID Dashboard but still display this error.

Please help. How do i able to integrate that on my laravel?


Solution

  • The receivedRedirectUri should not be set when initializing Link for the first time. It is used when initializing Link for the second time, after returning from the OAuth redirect.