Sha256: dfbddb3733ec427461e03237ffa8bd3f69e16c93813360cea681b5c00923c92d

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

module ArgyleHelper
  def plaid_link(options)
    raise Argyle::Error, "Public key must be set in Argyle configuration" unless Argyle.configuration.key
    raise Argyle::Error, "options[:name] is required for Plaid Link" unless options[:name]
    raise Argyle::Error, "options[:action] is required for Plaid Link" unless options[:action]

    id = options[:form_id] || 'plaidForm'
    product = options[:product] || Argyle.configuration.product
    env = options[:env] || Argyle.configuration.env

    plaid_link_form(id, options[:action]) + plaid_link_script(id, options[:name], product, env, options)
  end

  def plaid_link_form(id, action)
    form_tag action, method: 'POST', id: id
  end

  def plaid_link_script(id, name, product, env, options)
    data = {
      'client-name' => name,
      'form-id' => id,
      'key' => Argyle.configuration.key,
      'product' => product,
      'env' => env
    }
    data['webhook'] = options[:webhook] if options[:webhook]
    data['token'] = options[:token] if options[:token]

    javascript_tag '', src: Argyle.configuration.plaid_src, data: data
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
argyle-0.1.0 app/helpers/argyle_helper.rb