<commit_before># This class is the modal view.
# Shows the payment form and the result of
# the process, (e.g validation errors etc)
class PaymentModal extends KDModalView

  initialState   :
    planInterval : PaymentWorkflow.interval.MONTH
    scene        : 0

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

    options.width    = 534
    options.cssClass = KD.utils.curry 'payment-modal', options.cssClass
    options.overlay  = yes

    { state } = options

    @state = @utils.extend @initialState, state

    isUpgrade = PaymentWorkflow.isUpgrade @state.currentPlan, @state.planTitle

    if isUpgrade
      options.title    = 'Upgrade Your Plan'
      options.subtitle = ''
    else
      options.title    = 'Downgrade your plan'
      options.subtitle = ''

    super options, data

    @initViews()
    @initEvents()


  initViews: ->
    @addSubView @errors = new KDCustomHTMLView
      cssClass : 'errors hidden'

    @addSubView @form = new PaymentForm { @state }


  initEvents: ->

    @forwardEvent @form, 'PaymentSubmitted'
    @forwardEvent @form, 'PaymentWorkflowFinished'
    @form.forwardEvent this, 'PaymentProviderLoaded'

    @on 'StripeRequestValidationFailed', @bound 'handleStripeFail'
    @on 'PaymentFailed',                 @bound 'handleError'
    @on 'PaymentSucceeded',              @bound 'handleSuccess'



  handleStripeFail: (error) ->
    @form.submitButton.hideLoader()
    @form.showValidationErrorsOnInputs error


  handleError: (error) -> KD.showError error


  handleSuccess: ->

    { currentPlan, planTitle } = @state

    isUpgrade = PaymentWorkflow.isUpgrade currentPlan, planTitle

    if isUpgrade
      @setTitle 'Congratulations! Upgrade successful.'
      @setSubtitle 'Your account has been upgraded to the plan below.'
    else
      @setTitle 'Downgrade complete.'
      @setSubtitle ''

    @form.showSuccess isUpgrade

<commit_msg>payment: emit success event when you close congrats modal<commit_after># This class is the modal view.
# Shows the payment form and the result of
# the process, (e.g validation errors etc)
class PaymentModal extends KDModalView

  initialState   :
    planInterval : PaymentWorkflow.interval.MONTH
    scene        : 0

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

    options.width    = 534
    options.cssClass = KD.utils.curry 'payment-modal', options.cssClass
    options.overlay  = yes

    { state } = options

    @state = @utils.extend @initialState, state

    isUpgrade = PaymentWorkflow.isUpgrade @state.currentPlan, @state.planTitle

    if isUpgrade
      options.title    = 'Upgrade Your Plan'
      options.subtitle = ''
    else
      options.title    = 'Downgrade your plan'
      options.subtitle = ''

    super options, data

    @initViews()
    @initEvents()


  initViews: ->
    @addSubView @errors = new KDCustomHTMLView
      cssClass : 'errors hidden'

    @addSubView @form = new PaymentForm { @state }


  initEvents: ->

    @forwardEvent @form, 'PaymentSubmitted'
    @forwardEvent @form, 'PaymentWorkflowFinished'
    @form.forwardEvent this, 'PaymentProviderLoaded'

    @on 'StripeRequestValidationFailed', @bound 'handleStripeFail'
    @on 'PaymentFailed',                 @bound 'handleError'
    @on 'PaymentSucceeded',              @bound 'handleSuccess'



  handleStripeFail: (error) ->
    @form.submitButton.hideLoader()
    @form.showValidationErrorsOnInputs error


  handleError: (error) -> KD.showError error


  handleSuccess: ->

    { currentPlan, planTitle } = @state

    isUpgrade = PaymentWorkflow.isUpgrade currentPlan, planTitle

    if isUpgrade
      @setTitle 'Congratulations! Upgrade successful.'
      @setSubtitle 'Your account has been upgraded to the plan below.'
    else
      @setTitle 'Downgrade complete.'
      @setSubtitle ''

    @form.showSuccess isUpgrade

    @once 'KDModalViewDestroyed', =>
      @emit 'PaymentWorkflowFinished', @state


{'fraction_non_alphanumeric': 0.09455292908530319, 'fraction_numerical': 0.0020554984583761563, 'mean_word_length': 3.01340206185567, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, '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': '5086393', 'n_tokens_mistral': 1184, 'n_tokens_neox': 1105, 'n_words': 301}