【问题标题】:Braintree onReady not firing within Angular applicationBraintree onReady 未在 Angular 应用程序中触发
【发布时间】:2015-06-10 22:28:36
【问题描述】:

我在我的 Angular 应用程序中使用 Braintree Hosted Fields。当应用程序加载时,braintree.setup('TOKEN', 'customer', {}) 按预期工作。 onReady 正确触发。

这是我的控制器:

angular.module('braintree')
  .controller('BraintreeCtrl', [
    function() {

      var self = this;

      self.setup = function() {
        console.log('setup braintree');

        braintree.setup('myBTtoken', 'custom', {
          id: 'braintreeForm',
          onReady: function() {
            console.log('on ready');
          },
          hostedFields: {
            styles: {},
            number: {
              selector: '#card-number',
              placeholder: 'Card number'
            },
            cvv: {
              selector: '#card-cvv',
              placeholder: 'CVV'
            },
            expirationMonth: {
              selector: '#card-expiration-month',
              placeholder: 'MM'
            },
            expirationYear: {
              selector: '#card-expiration-year',
              placeholder: 'YY'
            },
            postalCode: {
              selector: '#card-postal',
              placeholder: 'Postal code'
            }
          }
        });
      }     
    }
  ]);

查看(玉石):

  form(name='braintreeForm', id='braintreeForm', novalidate, ng-init='ctrl.setup()')
    .form-group
      label Card Number
      #card-number

    .form-group
      label CVV
      #card-cvv

    .form-group
      label Expires
      #card-expiration-month

    .form-group
      #card-expiration-year

    .form-group
      label Zip Code
      #card-postal

    button(type='submit') Submit

但是,当我离开此页面时,然后返回到 BraintreeCtrl 触发的状态,onReady 永远不会触发并且我无法输入任何数据。

当我使用 Braintree 表单返回状态时,如何重新设置 Braintree??

【问题讨论】:

    标签: angularjs braintree


    【解决方案1】:

    我在 Braintree 的 JavaScript SDK 工作

    目前还没有官方支持的机制。这是我们知道的一个问题,我们将在未来的版本中提供解决方案。很遗憾,我无法提供这项工作的时间表。

    同时,我建议联系我们的支持团队 (support@braintreepayments.com) 并密切关注我们 Github 上的相关主题。同样,虽然没有官方支持的解决方案,但人们已经找到了一些 interesting workarounds

    很抱歉我没有更好的消息,但我们感谢您提出这个问题。

    【讨论】:

      【解决方案2】:

      过去,braintree.setup() 只能被调用一次而不会被窃听。

      他们现在已经实现了teardown() 函数,可以让你再次调用braintree.setup()

      简而言之,当您想销毁会话时调用teardown() - 可能在离开页面时。

      https://developers.braintreepayments.com/guides/client-sdk/javascript/v2#teardown https://github.com/braintree/braintree-web/issues/29

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-04-08
        • 2018-04-18
        • 1970-01-01
        • 2017-05-21
        • 2013-05-31
        • 1970-01-01
        • 2013-02-20
        相关资源
        最近更新 更多