当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript hostedFields.create方法代码示例

本文整理汇总了TypeScript中braintree-web.hostedFields.create方法的典型用法代码示例。如果您正苦于以下问题:TypeScript hostedFields.create方法的具体用法?TypeScript hostedFields.create怎么用?TypeScript hostedFields.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在braintree-web.hostedFields的用法示例。


在下文中一共展示了hostedFields.create方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: function

}, function (error: braintree.BraintreeError, clientInstance: any) {

  var form: HTMLFormElement = document.getElementById('my-form-id') as HTMLFormElement;
  var data: { creditCard: braintree.CreditCardInfo } = {
    creditCard: {
      number: form['cc-number'].value,
      cvv: form['cc-cvv'].value,
      expirationDate: form['cc-date'].value,
      billingAddress: {
        postalCode: form['cc-postal'].value
      }
    }
  };

  clientInstance.request({
    endpoint: 'payment_methods/credit_cards',
    method: 'post',
    data: data
  }, function (requestErr: braintree.BraintreeError, response: { creditCards: any[]; }) {
    if (requestErr) { throw new Error(requestErr.message); }

    console.log('Got nonce:', response.creditCards[0].nonce);
  });

  braintree.hostedFields.create({
    client: clientInstance,
    styles: {
      'input': {
        'font-size': '16pt',
        'color': '#3A3A3A'
      },

      '.number': {
        'font-family': 'monospace'
      },
      '.valid': {
        'color': 'green'
      }
    },
    fields: {
      number: {
        selector: '#card-number'
      },
      cvv: {
        selector: '#cvv',
        type: 'password'
      },
      expirationMonth: {
        selector: '#expiration-month',
        select: {
          options: ["01 - Jan", "02 - Feb", "03 - Mar", "04 - Apr", "05 - May", "06 - Jun", "07 - Jul", "08 - Aug", "09 - Sep", "10 - Oct", "11 - Nov", "12 - Dec"]
        }
      },
      expirationYear: {
        selector: '#expiration-year',
        select: true
      }
    }
  }, function (hostedFieldsErr?: braintree.BraintreeError, hostedFieldsInstance?: any) {

    if (hostedFieldsErr) {
      // Handle error in Hosted Fields creation
      console.log(`Error Code: ${error.code}, Type: ${error.type}, Message: ${error.message}, Details: ${error.details}`);
      return;
    }

    let form = new HTMLFormElement();

    form.addEventListener('submit', function (event: Event) {
      event.preventDefault();

      hostedFieldsInstance.tokenize(function (tokenizeErr: braintree.BraintreeError, payload: braintree.HostedFieldsTokenizePayload) {
        if (tokenizeErr) {
          // Handle error in Hosted Fields tokenization
          switch (tokenizeErr.code) {
            case 'HOSTED_FIELDS_FIELDS_EMPTY':
              console.error('All fields are empty! Please fill out the form.');
              break;
            case 'HOSTED_FIELDS_FIELDS_INVALID':
              console.error('Some fields are invalid:', tokenizeErr.details.invalidFieldKeys);
              break;
            case 'HOSTED_FIELDS_FAILED_TOKENIZATION':
              console.error('Tokenization failed server side. Is the card valid?');
              break;
            case 'HOSTED_FIELDS_TOKENIZATION_NETWORK_ERROR':
              console.error('Network error occurred when tokenizing.');
              break;
            default:
              console.error('Something bad happened!', tokenizeErr);
          }
          return;
        }

        // Put `payload.nonce` into the `payment-method-nonce` input, and then
        // submit the form. Alternatively, you could send the nonce to your server
        // with AJAX.
        (document.querySelector('input[name="payment-method-nonce"]') as HTMLInputElement).value = payload.nonce;
        form.submit();
      });
    }, false);
//.........这里部分代码省略.........
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:101,代码来源:node.ts


注:本文中的braintree-web.hostedFields.create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。