All I’m getting is an error from plaid
Something went wrong, Interal error occurred.
I do not know what to do and or how to fix it.
Here is the what I have tried on the front end with javascript.
<button id="link-button">Link Bank Account</button>
<script type="text/javascript" src="https://cdn.plaid.com/link/v2/stable/link-initialize.js"></script>
<script type="text/javascript">
var linkHandler = Plaid.create({
clientName: '<?php echo $case->name; ?>',
env: '<?php echo getenv("PLAID_ENVIRONMENT"); ?>', // or 'development' or 'production' based on your environment
key: '<?php echo getenv("PLAID_CLIENT_ID"); ?>', // Replace with your Plaid public key
product: ['balance'], // or other products like 'transactions', 'balance', etc.
onSuccess: function(public_token, metadata) {
console.log('Plaid Link success!');
console.log(public_token);
console.log(metadata);
// This is where you handle the success
// Send the public_token to your backend to exchange it for an access_token
fetch('/admin/api/plaid.php', {
method: 'POST',
body: JSON.stringify({
public_token: public_token
}),
headers: {
'Content-Type': 'application/json'
}
})
.then(response => response.json())
.then(data => {
console.log('Access token received:', data.access_token);
});
},
onExit: function(err, metadata) {
console.log('Plaid Link exited');
console.log(err, metadata);
}
});
document.getElementById('link-button').onclick = function() {
console.log('Button clicked, opening Plaid Link...');
linkHandler.open();
};
</script>
Here is the file that is tryng to fetch plaid.php
I am not sure if this has anything to do with the error or not.
I wasn’t able to find much documatation for plaid and PHP.
When I called plaid they were very not helpful.
require 'vendor/autoload.php';
use TomorrowIdeasPlaidPlaid;
$plaid = new Plaid(
getenv("PLAID_CLIENT_ID"),
getenv("PLAID_CLIENT_SECRET"),
getenv("PLAID_ENVIRONMENT")
);
// Get the public_token from the request body
$data = json_decode(file_get_contents('php://input'), true);
$public_token = $data['public_token'];
try {
$response = $plaid->items->get("access_token");
print_r($response);
} catch (TomorrowIdeasPlaidPlaidRequestException $e) {
echo "Error: " . $e->getMessage() . "n";
var_dump($e); // Inspect the exception object for available properties
}
$item = $plaid->items->get("itm_1234");
exit();