<commit_before>class PaymentWorkflow extends FormWorkflow

  constructor: (options = {}, data) ->
    unless options.confirmForm
      throw new Error "You must provide a confirmForm option!"

    super options, data

  preparePaymentMethods: (formData) ->

    paymentController = KD.getSingleton 'paymentController'

    paymentController.fetchPaymentMethods (err, paymentMethods) =>
      return if KD.showError err

      if paymentMethods.methods.length > 0
        (@getForm 'choice').setPaymentMethods paymentMethods
      else
        @clearData 'paymentMethod'

  createChoiceForm: (options, data) ->

    form = new PaymentChoiceForm options, data

    form.once 'Activated', =>
      @preparePaymentMethods()

    form.on 'PaymentMethodChosen', (paymentMethod) =>
      @collectData { paymentMethod }

    form.on 'PaymentMethodNotChosen', =>
      @clearData 'paymentMethod'

    return form

  createEntryForm: (options, data) ->

    form = new PaymentMethodEntryForm options, data

    payment = KD.getSingleton 'paymentController'

    payment.observePaymentSave form, (err, paymentMethod) =>
      return if KD.showError err

      @collectData { paymentMethod }

    return form

  prepareWorkflow: ->

    { all, any } = Junction

    @requireData [
      'productData'
      any 'createAccount', 'loggedIn'
      any 'paymentMethod', 'subscription'
      'userConfirmation'
    ]

    if KD.whoami().type is 'unregistered'
      existingAccountWorkflow = new ExistingAccountWorkflow
      existingAccountWorkflow.on 'DataCollected', @bound "collectData"
      @addForm 'createAccount', existingAccountWorkflow, ['createAccount', 'loggedIn']
    else
      # TODO: this is an awful hack for now C.T.
      @addForm 'existingAccount', (@skip createAccount: no, loggedIn: yes), ['createAccount', 'loggedIn']

    # - "product form" can be used for collecting some product-related data
    # before the payment method collection/selection process begins.  If you
    # use this feature, make sure to emit the "DataCollected" event with any
    # data that you want aggregated (that you want to be able to access from
    # the "PaymentConfirmed" listeners).
    # - "confirm form" is required.  This form should render a summary, and 
    # emit a "PaymentConfirmed" after user approval.
    { productForm, confirmForm } = @getOptions()

    if productForm?
      
      @addForm 'product', productForm, ['productData', 'subscription']

      productForm.on 'DataCollected', (productData) =>
        @collectData { productData }
        { subscription, oldSubscription } = productData
        @collectData { subscription }  if subscription
        @collectData { oldSubscription }  if oldSubscription
<commit_msg>payment: collect only loggedIn state for existing account workflow if user is already logged in<commit_after>class PaymentWorkflow extends FormWorkflow

  constructor: (options = {}, data) ->
    unless options.confirmForm
      throw new Error "You must provide a confirmForm option!"

    super options, data

  preparePaymentMethods: (formData) ->

    paymentController = KD.getSingleton 'paymentController'

    paymentController.fetchPaymentMethods (err, paymentMethods) =>
      return if KD.showError err

      if paymentMethods.methods.length > 0
        (@getForm 'choice').setPaymentMethods paymentMethods
      else
        @clearData 'paymentMethod'

  createChoiceForm: (options, data) ->

    form = new PaymentChoiceForm options, data

    form.once 'Activated', =>
      @preparePaymentMethods()

    form.on 'PaymentMethodChosen', (paymentMethod) =>
      @collectData { paymentMethod }

    form.on 'PaymentMethodNotChosen', =>
      @clearData 'paymentMethod'

    return form

  createEntryForm: (options, data) ->

    form = new PaymentMethodEntryForm options, data

    payment = KD.getSingleton 'paymentController'

    payment.observePaymentSave form, (err, paymentMethod) =>
      return if KD.showError err

      @collectData { paymentMethod }

    return form

  prepareWorkflow: ->

    { all, any } = Junction

    @requireData [
      'productData'
      any 'createAccount', 'loggedIn'
      any 'paymentMethod', 'subscription'
      'userConfirmation'
    ]

    if KD.whoami().type is 'unregistered'
      existingAccountWorkflow = new ExistingAccountWorkflow
      existingAccountWorkflow.on 'DataCollected', @bound "collectData"
      @addForm 'createAccount', existingAccountWorkflow, ['createAccount', 'loggedIn']
    else
      # TODO: this is an awful hack for now C.T.
      @addForm 'existingAccount', (@skip loggedIn: yes), ['createAccount', 'loggedIn']

    # - "product form" can be used for collecting some product-related data
    # before the payment method collection/selection process begins.  If you
    # use this feature, make sure to emit the "DataCollected" event with any
    # data that you want aggregated (that you want to be able to access from
    # the "PaymentConfirmed" listeners).
    # - "confirm form" is required.  This form should render a summary, and 
    # emit a "PaymentConfirmed" after user approval.
    { productForm, confirmForm } = @getOptions()

    if productForm?
      
      @addForm 'product', productForm, ['productData', 'subscription']

      productForm.on 'DataCollected', (productData) =>
        @collectData { productData }
        { subscription, oldSubscription } = productData
        @collectData { subscription }  if subscription
        @collectData { oldSubscription }  if oldSubscription

{'fraction_non_alphanumeric': 0.08929541749683029, 'fraction_numerical': 0.0003622532149972831, 'mean_word_length': 3.330980392156863, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '3736594', 'n_tokens_mistral': 1485, 'n_tokens_neox': 1427, 'n_words': 464}