title: Error TypeError: can't dup NilClass - Stripe
body: <p>I am getting an error <code>ERROR TypeError: can't dup NilClass</code> when processing a Strip charge. I have followed the rails stripe integration documentation.</p>
  
  <p>The error from the terminal is:</p>
  
  <pre><code>    Started POST "/charges" for ::1 at 2016-05-27 12:35:48 +0100
  Processing by ChargesController#create as HTML
    Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"URydkbi6DghMZnzVqbf79KU+YRy/T+9g3UQ8tO8HTXG4uqvEMzdm6V/EjseNiZiIPS3ziOJJTpJ1K+gGMipksg==", "stripeToken"=&gt;"tok_18FjA2JxArkI2Z35Q4MB3sCE", "stripeTokenType"=&gt;"card", "stripeEmail"=&gt;"fergusmorton@live.com"}
  [2016-05-27 12:35:48] ERROR TypeError: can't dup NilClass
          C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httprequest.rb:392:in `dup'
          C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httprequest.rb:392:in `meta_vars'
          C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/handler/webrick.rb:59:in `service'
          C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
          C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
          C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
  Completed 500 Internal Server Error in 55ms (ActiveRecord: 0.0ms)
  
  Net::HTTPFatalError (500 "Internal Server Error "):
    app/controllers/charges_controller.rb:9:in `create'
  
  
  
  Net::HTTPFatalError: 500 "Internal Server Error "
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/net/http/response.rb:119:in `error!'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/net/http/response.rb:128:in `value'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/net/http.rb:915:in `connect'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/net/http.rb:863:in `do_start'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/net/http.rb:852:in `start'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rest-client-1.8.0-x86-mingw32/lib/restclient/request.rb:413:in `transmit'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rest-client-1.8.0-x86-mingw32/lib/restclient/request.rb:176:in `execute'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rest-client-1.8.0-x86-mingw32/lib/restclient/request.rb:41:in `execute'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/stripe-1.43.0/lib/stripe.rb:298:in `execute_request'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/stripe-1.43.0/lib/stripe.rb:196:in `execute_request_with_rescues'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/stripe-1.43.0/lib/stripe.rb:148:in `request'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/stripe-1.43.0/lib/stripe/api_operations/request.rb:15:in `request'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/stripe-1.43.0/lib/stripe/api_operations/create.rb:5:in `create'
          from C:/Users/Fergus/best-ever-me-v-1.1/app/controllers/charges_controller.rb:9:in `create'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/abstract_controller/base.rb:198:in `process_action'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_controller/metal/rendering.rb:10:in `process_action'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:117:in `call'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:117:in `call'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:555:in `block (2 levels) in compile'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:505:in `call'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:505:in `call'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:92:in `__run_callbacks__'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:778:in `_run_process_action_callbacks'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:81:in `run_callbacks'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/abstract_controller/callbacks.rb:19:in `process_action'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_controller/metal/rescue.rb:29:in `process_action'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/notifications.rb:164:in `block in instrument'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/notifications.rb:164:in `instrument'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/abstract_controller/base.rb:137:in `process'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionview-4.2.5/lib/action_view/rendering.rb:30:in `process'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_controller/metal.rb:196:in `dispatch'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_controller/metal.rb:237:in `block in action'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/routing/route_set.rb:76:in `call'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/routing/route_set.rb:76:in `dispatch'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/routing/route_set.rb:45:in `serve'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/journey/router.rb:43:in `block in serve'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/journey/router.rb:30:in `each'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/journey/router.rb:30:in `serve'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/routing/route_set.rb:817:in `call'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/etag.rb:24:in `call'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/conditionalget.rb:38:in `call'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/head.rb:13:in `call'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/params_parser.rb:27:in `call'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/flash.rb:260:in `call'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/session/abstract/id.rb:225:in `context'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/session/abstract/id.rb:220:in `call'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/cookies.rb:560:in `call'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/query_cache.rb:36:in `call'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in `call'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:377:in `call'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:88:in `__run_callbacks__'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:778:in `_run_call_callbacks'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:81:in `run_callbacks'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/reloader.rb:73:in `call'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/web-console-2.3.0/lib/web_console/middleware.rb:28:in `block in call'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/web-console-2.3.0/lib/web_console/middleware.rb:18:in `catch'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/web-console-2.3.0/lib/web_console/middleware.rb:18:in `call'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/rack/logger.rb:38:in `call_app'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/rack/logger.rb:20:in `block in call'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/tagged_logging.rb:68:in `block in tagged'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/tagged_logging.rb:26:in `tagged'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/tagged_logging.rb:68:in `tagged'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/rack/logger.rb:20:in `call'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/request_id.rb:21:in `call'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/methodoverride.rb:22:in `call'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/runtime.rb:18:in `call'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/lock.rb:17:in `call'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/static.rb:116:in `call'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/sendfile.rb:113:in `call'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/engine.rb:518:in `call'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/application.rb:165:in `call'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/lock.rb:17:in `call'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/content_length.rb:15:in `call'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/handler/webrick.rb:88:in `service'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
          from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
  </code></pre>
  
  <p>charges_controller.rb</p>
  
  <pre><code>    class ChargesController &lt; ApplicationController
      def new
  end
  
  def create
    # Amount in cents
    @amount = 500
  
    customer = Stripe::Customer.create(
      :email =&gt; params[:stripeEmail],
      :source  =&gt; params[:stripeToken]
    )
  
    charge = Stripe::Charge.create(
      :customer    =&gt; customer.id,
      :amount      =&gt; @amount,
      :description =&gt; 'Rails Stripe customer',
      :currency    =&gt; 'usd'
    )
  
  rescue Stripe::CardError =&gt; e
    flash[:error] = e.message
    redirect_to new_charge_path
  end
  end
  </code></pre>
  
  <p>initiliazers/stripe.rb</p>
  
  <pre><code>    Rails.configuration.stripe = {
    :publishable_key =&gt; ENV['PUBLISHABLE_KEY'],
    :secret_key      =&gt; ENV['SECRET_KEY']
  }
  
  Stripe.api_key = Rails.configuration.stripe[:secret_key]
  </code></pre>
  
  <p>cart/show.html.erb</p>
  
  <pre><code>    &lt;div class="shopping-cart" style="margin-top:160px;"&gt;
    &lt;%= render "shopping_cart" %&gt;
    &lt;%= form_tag charges_path do %&gt;
    &lt;article&gt;
      &lt;% if flash[:error].present? %&gt;
        &lt;div id="error_explanation"&gt;
          &lt;p&gt;&lt;%= flash[:error] %&gt;&lt;/p&gt;
        &lt;/div&gt;
      &lt;% end %&gt;
      &lt;label class="amount"&gt;
        &lt;span&gt;Amount: €&lt;%= current_order.subtotal %&gt; &lt;/span&gt;
      &lt;/label&gt;
    &lt;/article&gt;
  
    &lt;script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
            data-key="&lt;%= Rails.configuration.stripe[:publishable_key] %&gt;"
            data-description="Cart Total"
            data-amount="&lt;%= current_order.subtotal %&gt;"
            data-locale="auto"&gt;&lt;/script&gt;
  &lt;% end %&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>Updated log Following Michael's Suggestions.</strong></p>
  
  <pre><code> Started POST "/charges" for ::1 at 2016-05-31 11:45:45 +0100
  Processing by ChargesController#create as HTML
    Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"qXPL5OhG1UA+Ui4uyB7+80/UGDGXFPnOevOf/kmZhitA1f2xY8u9oS3w3DzsIJ2P18eKpcoSWDzSnEtMlLSv6A==", "stripeToken"=&gt;"tok_18HANXJxArkI2Z35encjc3uW", "stripeTokenType"=&gt;"card", "stripeEmail"=&gt;"fergusmorton@live.com"}
  Unpermitted parameters: utf8, authenticity_token, stripeTokenType
  Completed 500 Internal Server Error in 6ms (ActiveRecord: 0.0ms)
  
  NoMethodError (undefined method `stripe_customer_id' for nil:NilClass):
    app/controllers/charges_controller.rb:15:in `create'
  
  
  
  NoMethodError: undefined method `stripe_customer_id' for nil:NilClass
  </code></pre>