简体   繁体   English

BrainTree.js与AngularJS和customVariables

[英]BrainTree.js with AngularJS and customVariables

I am using the BrainTree.js for PCI compliance, and the tutorial I am using here: 我使用BrainTree.js进行PCI合规,我在这里使用的教程:

https://www.braintreepayments.com/docs/javascript https://www.braintreepayments.com/docs/javascript

There recommendation is to call the form by the ID like so: 建议通过ID调用表单,如下所示:

var braintree = Braintree.create("YourClientSideEncryptionKey");
braintree.onSubmitEncryptForm('braintree-payment-form');

I'm using AngularJS with the form being inside a controller. 我正在使用AngularJS,其形式位于控制器内部。 So inputs such as name, card, etc are tied to a scope using ng-model: 因此,使用ng-model将名称,卡等输入绑定到范围:

<div class="form-group">
  <label>Card Number</label>
  <input type="text" class="form-control" name="number" ng-model="card.number" />
</div>

My question is how can I submit a form using AngularJS and BrainTree.js in a manner that uses the data collected using ng-model? 我的问题是如何使用AngularJS和BrainTree.js以使用ng-model收集的数据的方式提交表单?

Example: 例:

braintree.onSubmitEncryptForm({name: $scope.card.name, card: $scope.card.number});

In Braintree, the braintree.onSubmitEncryptForm function wraps a small amount of functionality. 在Braintree中, braintree.onSubmitEncryptForm函数包含少量功能。 Basically it just grabs the jQuery form representing the input data, transforms the form fields, and then scrubs them from the DOM, before allowing the request to be submitted to the server. 基本上它只是抓取表示输入数据的jQuery表单,转换表单字段,然后在允许将请求提交给服务器之前从DOM中擦除它们。

Since angular includes jQuery, you could call the braintree.encryptForm($('#braintree-payment-form')); 由于angular包含jQuery,你可以调用braintree.encryptForm($('#braintree-payment-form')); which would return the encrypted data in the DOM. 这将返回DOM中的加密数据。 You should be able to access the 'ccv' and 'number' input elements like normal (the expire doesn't need to be encrypted). 您应该能够像正常一样访问'ccv'和'number'输入元素(过期不需要加密)。

month=55&year=5555&number=%24bt4%7Cjavascript_1_3_10%24ne0ib
vLjzzck52xzNiY2C8grXaZgpwfVpGrsR9TbHLPaW983e3y7R6tClw8YxYe5w
MA9%2BNHLjPBb%2FEsJQBSiCARJK7Wlxu53GO6mHMr0QMglQEiy9%2B9Dla8
DkY0XBpyfomqniwsDEuudiX7l%2FIb%2FsS4BRFu1BS8MpNpYWSghdj%2FTR
28jhRxlBNZVLjlG9cJd%2FNwDIRUv80qX4Di38bjrvywZR3nP%2BsEcUDSZj
DYQb08LDtN6Vhg5%2FTt1ketZqQH83XheDAFeTuGnb6iE1n8cZbePio8%2FC
m071d2zDZiSc57m%2BEnMJERc%2F2NYrWERl32o4L6DlltB9veZH30mKsPkB
Q%3D%3D%24qpTMCwpQQ5aEk3QO60yu8dQ1SBh3ezit564s1gK604tyIHh%2F
XqipKWgPCli2ZtFW%24AUph2EeuSMh2e8CxNRGVfsIRLvegNAulBDdDY3kwl
GA%3D&cvv=%24bt4%7Cjavascript_1_3_10%24e%2FWsFiRYkHsV%2B6RD5
j26KwII3ErBklZjXB2o1SKGtg1GvemW9J5cSQNBu3K%2BAy0uymAu5awICVR
pIB7%2FiIPBkC8vHBhX57oJabKkCyqkm6YWKio5Pce%2BasD1q4RzGFT1y1Q
iqw%2Fmt12ovQz6G%2B6yZbqQ0wUtFPt4vMSnmQIBogNtgiXeHbirSDHrY9N
V7hoBIaQ%2FV4up87AXs%2FL36FKuBF1rtTyhh%2BEEDgvqkKuRfr6Sim2zc
JNEvcsi7mJp4y6F1%2BNUiLao3w8RfTKt%2BUJUU1XHz3sWLeb2A1chamnFY
UjdVyEgrRFpGH9%2BLdrNYghpmibM6xRsO9p%2Bi1a8yYOMsg%3D%3D%24sd
IGDgI6Jo3zru4YEXtvYI37Oesw09HBISdpcCh6dho%3D%24s8SaRheCM6kWV
OQQ3Ae%2FJjVQQpw6Hht0BWrVIGpV1u4%3D

And then POST to your create_transaction method (if you're running from the tutorial). 然后POST到你的create_transaction方法(如果你从教程中运行)。

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

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