1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-19 05:09:38 +02:00
Maybe/app/javascript/controllers/plaid_controller.js
Josh Pigford 4bf72506d5
Initial pass at Plaid EU (#1555)
* Initial pass at Plaid EU

* Add EU support to Plaid Items

* Lint

* Temp fix for rubocop isseus

* Merge cleanup

* Pass in region and get tests passing

* Use absolute path for translation

---------

Signed-off-by: Josh Pigford <josh@joshpigford.com>
2025-01-31 12:13:58 -06:00

56 lines
1.2 KiB
JavaScript

import { Controller } from "@hotwired/stimulus";
// Connects to data-controller="plaid"
export default class extends Controller {
static values = {
linkToken: String,
region: { type: String, default: "us" }
};
open() {
const handler = Plaid.create({
token: this.linkTokenValue,
onSuccess: this.handleSuccess,
onLoad: this.handleLoad,
onExit: this.handleExit,
onEvent: this.handleEvent,
});
handler.open();
}
handleSuccess(public_token, metadata) {
window.location.href = "/accounts";
fetch("/plaid_items", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-CSRF-Token": document.querySelector('[name="csrf-token"]').content,
},
body: JSON.stringify({
plaid_item: {
public_token: public_token,
metadata: metadata,
region: this.regionValue
},
}),
}).then((response) => {
if (response.redirected) {
window.location.href = response.url;
}
});
}
handleExit(err, metadata) {
// no-op
}
handleEvent(eventName, metadata) {
// no-op
}
handleLoad() {
// no-op
}
}