2017-11-03 88 views
0

我遵循this教程,以便从格子API获取交易/帐户详细信息。格式化快速入门指南用户ejs,以便使用onSuccess功能发送到服务器。我如何使用离子创建此令牌?格子:如何在前端创建公共令牌(Ionic/angular)并发送到服务器

格纹快速指南还表明,我们使用的代码的打击

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前端和节点后端创建此公共令牌?

这里的工作流程是什么?

在此先感谢

+0

有没有人创造了采用这种架构公共令牌? – Generaldeep

回答

0

在服务器端,您需要先初始化格纹节点客户端库。您还需要进行交换令牌调用,以便从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 
}); 

对于客户端在你的应用程序离子,你需要调用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> 
+0

嗨迈克尔,我遇到了HTML文件中使用JQuery和格式脚本,但是,我需要调用一个Angular组件内的Plaid.create,并将动态创建的令牌发送到服务器以获取访问令牌。我如何在Angular组件内部调用Plaid.create,实质上是一个类,以便单个用户可以将公共令牌交换为访问令牌。 – Generaldeep

+0

尝试https://github.com/pbernasconi/plaid-link-ionic-example查看完整的Ionic示例应用程序! –

相关问题