简体   繁体   English

Plaid:如何在前端(Ionic/angular)创建公共令牌并发送到服务器

[英]Plaid: how to create public token in the front end (Ionic/angular) and send to server

I am follow this tutorial in order to get a transactions/accounts detail from the plaid API.我按照教程从格子 API 获取交易/帐户详细信息。 Plaid'd quickstart guide user ejs in order to send to the server with the onSuccess function. Plaid'd 快速入门指南用户 ejs 以便使用 onSuccess 函数发送到服务器。 How do I create this token using ionic?如何使用 ionic 创建此令牌?

Plaid quick guide also suggests that we use code blow格子快速指南还建议我们使用代码吹

var linkHandler = Plaid.create({
  env: 'sandbox',
  clientName: 'Client Name',
  key: '<PUBLIC_KEY>',
  product: ['auth', 'transactions'],
  token: '<GENERATED_PUBLIC_TOKEN>',
  onSuccess: function(public_token, metadata) {
    // You do not need to repeat the /item/public_token/exchange
    // process when a user uses Link in update mode.
    // The Item's access_token has not changed.
  },

and also suggest to use this code并建议使用此代码

// Create a public_token for use with Plaid Link's update mode
client.createPublicToken(ACCESS_TOKEN, (err, result) => {
  // Handle err
  // Use the generated public_token to initialize Plaid Link in update
  // mode for a user's Item so that they can provide updated credentials
  // or MFA information
  const publicToken = result.public_token;
});

in order to create a public token and get the access token.为了创建一个公共令牌并获取访问令牌。 I can't use this function because I'm getting an error 'Plaid and/or client is not defined我无法使用此功能,因为我收到错误“格子图案和/或客户端未定义

How do I create this public token using Ionic front end and node back end?如何使用 Ionic 前端和节点后端创建此公共令牌?

What's the workflow here?这里的工作流程是什么?

Thanks in advance提前致谢

An Angular library was recently created: click here and here最近创建了一个 Angular 库:点击这里这里

I had some issues implementing Plaid successfully at first;起初我在成功实施 Plaid 时遇到了一些问题; these tips should help:这些提示应该会有所帮助:

  1. Implement the library as shown in the second link above.实现库,如上面第二个链接所示。 Make sure for step two you import in your app.module.ts file.确保在您的 app.module.ts 文件中导入第二步。 Don't use the jQuery provided in the documentation.不要使用文档中提供的 jQuery。
  2. Using this library, a button will be automatically created within the Angular element <mr-ngx-plaid-link-button> .使用这个库,将在 Angular 元素<mr-ngx-plaid-link-button>自动创建一个按钮。 This button will act as a submit button unless you use DOM or other methods to change it to type button on ngAfterViewInit()此按钮将充当提交按钮,除非您使用 DOM 或其他方法将其更改为ngAfterViewInit()上的类型按钮
  3. All five events in step three are listeners for various events.第三步中的所有五个事件都是各种事件的侦听器。 The onSuccess() callback will return the public token - only after you have (a) successfully submitted bank credentials (user_good / pass_good on Sandbox) and (b) clicked the Continue button to exit the Plaid Link onSuccess() 回调将返回公共令牌 - 只有在您 (a) 成功提交银行凭据(沙箱上的 user_good / pass_good)并且 (b) 单击“继续”按钮退出 Plaid 链接后

On the server side, you'll need to initialize the Plaid node client library first.在服务器端,您需要先初始化 Plaid 节点客户端库。 You will also want to make an exchange token call, to exchange the public_token from Link for an API access_token .您还需要进行交换令牌调用,将来自 Link 的public_token交换为 API access_token You'll then save the access_token and use it to retrieve transaction and account data:然后您将保存access_token并使用它来检索交易和帐户数据:

// Initialize the Plaid API client with your API keys (https://dashboard.plaid.com/account/keys)
// Use plaid.environments.production, plaid.environments.development, or plaid.environments.sandbox
const plaid = require('plaid');
const client = new plaid.Client(client_id, secret, public_key, plaid.environments.sandbox);
client.exchangePublicToken(PUBLIC_TOKEN, function(error, tokenResponse) {
  if (error != null) {
    var msg = 'Could not exchange public_token!';
    console.log(msg + '\n' + error);
  }
  const ACCESS_TOKEN = tokenResponse.access_token;
  const ITEM_ID = tokenResponse.item_id;
  console.log('Access Token: ' + ACCESS_TOKEN);
  console.log('Item ID: ' + ITEM_ID);
  // Now retrieve transactions or account information with the access_token
});

For the client-side in your Ionic app, you'll need to include the link-initialize.js script before calling Plaid.create .对于 Ionic 应用程序中的客户端,您需要在调用Plaid.create之前包含link-initialize.js脚本。 Specifically:具体来说:

<script src="https://cdn.plaid.com/link/v2/stable/link-initialize.js">
</script>

Here's a full client-side HTML example:这是一个完整的客户端 HTML 示例:

<button id="link-button">Link Account</button>

<script src="https://cdn.plaid.com/link/v2/stable/link-initialize.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script>
<script type="text/javascript">
var handler = Plaid.create({
  clientName: 'Plaid Walkthrough Demo',
  env: 'sandbox',
  key: '[PUBLIC_KEY]', // public_key is at https://dashboard.plaid.com/account/keys
  product: ['auth'],
  onLoad: function() {
    // Optional, called when Link loads
  },
  onSuccess: function(public_token, metadata) {
    // Send the public_token to your app server.
    // The metadata object contains info about the institution the
    // user selected and the account ID, if `selectAccount` is enabled.
    $.post('/get_access_token', {
      public_token: public_token,
    });
  },
  onExit: function(err, metadata) {
    // The user exited the Link flow.      
  }
});
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM