<commit_before>_ = require 'lodash'
kd = require 'kd'
JView = require '../../core/jview'
MainHeaderView = require '../../core/mainheaderview'
StripePaymentTabForm = require '../forms/stripepaymenttabform'
utils = require '../../core/utils'

module.exports = class StripePaymentTab extends kd.TabPaneView

  JView.mixin @prototype

  constructor: (options = {}, data) ->

    super options, data

    name = @getOption 'name'

    @header = new MainHeaderView
      cssClass : 'team'
      navItems : []

    @form = new StripePaymentTabForm
      callback: @bound 'onSubmit'

    utils.loadStripe().then =>
      if kd.config.environment is 'development'
        @submitWithDummyCard()


  submitWithDummyCard: ->
    @form.makeDisabled()
    @form.setValues utils.getDummyCard()
    @form.submit()


  onSubmit: (formData) ->

    if utils.getPayment()
      return @onSubmitSuccess()

    utils.authorizeCreditCard(formData)
      .then @bound 'onSubmitSuccess'
      .catch @bound 'onSubmitError'


  onSubmitError: (error) ->

    @form.emit 'FormSubmitFailed'

    if error.param and view = @form[error.param]
      input = view.input
    else
      try
        error = JSON.parse error.description
        if error.code is 'card_declined'
          input = @form['number'].input
      catch
        error = { message: 'There is a problem. Please try again!' }

    input?.parent.setClass 'validation-error'
    new kd.NotificationView { title: error.message }


  onSubmitSuccess: ->

    @form.button.hideLoader()
    kd.singletons.router.handleRoute '/Team/Username'


  pistachio: ->

    '''
    {{> @header }}
    <div class="TeamsModal TeamsModal--groupCreation">
      <h4>Billing Information</h4>
      <h5>We <strong>never charge you</strong> without asking first.</h5>
      {{> @form}}
    </div>
    '''

track = (action, properties = {}) ->

  properties.category = 'TeamSignup'
  properties.label    = 'PaymentTab'
  utils.analytics.track action, properties


<commit_msg>landing: check if environment isn't production<commit_after>_ = require 'lodash'
kd = require 'kd'
JView = require '../../core/jview'
MainHeaderView = require '../../core/mainheaderview'
StripePaymentTabForm = require '../forms/stripepaymenttabform'
utils = require '../../core/utils'

module.exports = class StripePaymentTab extends kd.TabPaneView

  JView.mixin @prototype

  constructor: (options = {}, data) ->

    super options, data

    name = @getOption 'name'

    @header = new MainHeaderView
      cssClass : 'team'
      navItems : []

    @form = new StripePaymentTabForm
      callback: @bound 'onSubmit'

    utils.loadStripe().then =>
      if kd.config.environment isnt 'production'
        @submitWithDummyCard()


  submitWithDummyCard: ->
    @form.makeDisabled()
    @form.setValues utils.getDummyCard()
    @form.submit()


  onSubmit: (formData) ->

    if utils.getPayment()
      return @onSubmitSuccess()

    utils.authorizeCreditCard(formData)
      .then @bound 'onSubmitSuccess'
      .catch @bound 'onSubmitError'


  onSubmitError: (error) ->

    @form.emit 'FormSubmitFailed'

    if error.param and view = @form[error.param]
      input = view.input
    else
      try
        error = JSON.parse error.description
        if error.code is 'card_declined'
          input = @form['number'].input
      catch
        error = { message: 'There is a problem. Please try again!' }

    input?.parent.setClass 'validation-error'
    new kd.NotificationView { title: error.message }


  onSubmitSuccess: ->

    @form.button.hideLoader()
    kd.singletons.router.handleRoute '/Team/Username'


  pistachio: ->

    '''
    {{> @header }}
    <div class="TeamsModal TeamsModal--groupCreation">
      <h4>Billing Information</h4>
      <h5>We <strong>never charge you</strong> without asking first.</h5>
      {{> @form}}
    </div>
    '''

track = (action, properties = {}) ->

  properties.category = 'TeamSignup'
  properties.label    = 'PaymentTab'
  utils.analytics.track action, properties



{'fraction_non_alphanumeric': 0.13041314086610253, 'fraction_numerical': 0.001991040318566451, 'mean_word_length': 2.849616858237548, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '982371', 'n_tokens_mistral': 1276, 'n_tokens_neox': 1222, 'n_words': 281}