繁体   English   中英

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

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

我按照教程从格子 API 获取交易/帐户详细信息。 Plaid'd 快速入门指南用户 ejs 以便使用 onSuccess 函数发送到服务器。 如何使用 ionic 创建此令牌?

格子快速指南还建议我们使用代码吹

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.
  },

并建议使用此代码

// 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;
});

为了创建一个公共令牌并获取访问令牌。 我无法使用此功能,因为我收到错误“格子图案和/或客户端未定义

如何使用 Ionic 前端和节点后端创建此公共令牌?

这里的工作流程是什么?

提前致谢

最近创建了一个 Angular 库:点击这里这里

起初我在成功实施 Plaid 时遇到了一些问题; 这些提示应该会有所帮助:

  1. 实现库,如上面第二个链接所示。 确保在您的 app.module.ts 文件中导入第二步。 不要使用文档中提供的 jQuery。
  2. 使用这个库,将在 Angular 元素<mr-ngx-plaid-link-button>自动创建一个按钮。 此按钮将充当提交按钮,除非您使用 DOM 或其他方法将其更改为ngAfterViewInit()上的类型按钮
  3. 第三步中的所有五个事件都是各种事件的侦听器。 onSuccess() 回调将返回公共令牌 - 只有在您 (a) 成功提交银行凭据(沙箱上的 user_good / pass_good)并且 (b) 单击“继续”按钮退出 Plaid 链接后

在服务器端,您需要先初始化 Plaid 节点客户端库。 您还需要进行交换令牌调用,将来自 Link 的public_token交换为 API access_token 然后您将保存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
});

对于 Ionic 应用程序中的客户端,您需要在调用Plaid.create之前包含link-initialize.js脚本。 具体来说:

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

这是一个完整的客户端 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