title: Stripe "This API call cannot be made with a publishable API key. " What gives?
body: <p>I'm getting this error during my stripe and rails integration and I can't figure out why. </p>
  
  <p>My charges controller:</p>
  
  <pre><code>class ChargesController &lt; ApplicationController
  
  before_action :check_if_user_already_subscribed, only: [:new]
  
      def new 
  
      end
  
  
      def create
      # Amount in cents
      @amount = 100
  
  
  
      # Create the charge on Stripe's servers - this will charge the user's card
      begin
          # Get the credit card details submitted by the form
      customer = Stripe::Customer.create(
          :email =&gt; params[:email],
          :source  =&gt; params[:stripeToken]
      )
  
        Stripe::Charge.create(
            :amount =&gt; @amount,
            :currency =&gt; 'usd',
            :customer =&gt; customer.id,
            :description =&gt; 'Example charge custom form'
        )
  
        current_user.subscribed = true
        current_user.stripe_id = customer.id
        current_user.expiry_date = Date.today + 90.days
        current_user.save
  
  
        flash[:success] = "Thank you for subscribing. Your account has been unlocked."
        redirect_to root_path
  
        rescue Stripe::CardError =&gt; e
        flash[:danger] = e.message
        redirect_to root_path
      end
  
  
  end
  
      private
  
      def check_if_user_already_subscribed
  
          if current_user.subscribed
          flash[:danger] = "You have already subscribed. Please wait until your subscription runs out to resubscribe."
          redirect_to root_path
          end
  
  
      end 
  
  end
  </code></pre>
  
  <p>my initializer 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>I'm using figaro, so configuration.yml (I've replaced the actual key values): </p>
  
  <pre><code>PUBLISHABLE_KEY: "sk_test_key"
  SECRET_KEY: "pk_test_key"
  </code></pre>
  
  <p>My view:</p>
  
  <pre><code>&lt;script type="text/javascript" src="https://js.stripe.com/v2/"&gt;&lt;/script&gt;
  
  &lt;script type="text/javascript"&gt;
    Stripe.setPublishableKey("pk_test_N9K3OPekS1Wi5zyyWtgcVLEe");
  &lt;/script&gt;
  
  &lt;div id= 'charges-new-promo'&gt;
  &lt;div class = 'container-fluid'&gt;
  
    &lt;div class = 'index-header'&gt;
      &lt;h2 class ='text-center charge-title'&gt;Upgrade Now.&lt;/h2&gt;
     &lt;p class = ' text-center charge-sub-title'&gt;Instantly unlock the entire site for 90 days.&lt;/p&gt;
     &lt;p class = ' text center charge-stripe-title'&gt;&lt;%= image_tag("stripe.png", :class =&gt; "stripe-img" ) %&gt;&lt;/p&gt;
    &lt;/div&gt;
  
  
  &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;div class = 'container'&gt;
  &lt;div class = 'row'&gt;
  &lt;div class = 'col-md-5 col-sm-12'&gt;
  &lt;%= form_tag charges_path, id: 'payment-form' do %&gt;
  
  
  &lt;div class = 'charge-form'&gt;
    &lt;span class="payment-errors"&gt;&lt;/span&gt;
  
    &lt;div class="form-group"&gt;
      &lt;label&gt;
        &lt;input value="&lt;%= current_user.email if current_user %&gt;" type="hidden" data-stripe="email" &gt;
      &lt;/label&gt;
    &lt;/div&gt;
  
       &lt;div class="form-group"&gt;
      &lt;label&gt;
        &lt;span&gt;Full name&lt;/span&gt;&lt;span class = 'small-text'&gt; (e.g. John Smith)&lt;/span&gt;
        &lt;input type="text" size="5" data-stripe="name"  class = 'form-field'&gt;
      &lt;/label&gt;
    &lt;/div&gt;
  
     &lt;div class="form-group"&gt;
      &lt;label&gt;
        &lt;span&gt;Country&lt;/span&gt;&lt;span class = 'small-text'&gt; (e.g. United States)&lt;/span&gt;
        &lt;input type="text" size="10" data-stripe="address_country" class = 'form-field'&gt;
      &lt;/label&gt;
    &lt;/div&gt;
  
     &lt;div class="form-group"&gt;
      &lt;label&gt;
        &lt;span&gt;Address&lt;/span&gt;
        &lt;input type="text" size="10" data-stripe="address_line1" class = 'form-field'&gt;
      &lt;/label&gt;
    &lt;/div&gt;
  
    &lt;div class="form-group"&gt;
      &lt;label&gt;
        &lt;span&gt;Postal Code / Zip Code&lt;/span&gt;
        &lt;input type="text" size="4" data-stripe="address_zip" class = 'form-field'&gt;
      &lt;/label&gt;
    &lt;/div&gt;
  
    &lt;div class="form-group"&gt;
      &lt;label&gt;
        &lt;span&gt;Card Number&lt;/span&gt;
        &lt;input type="text" size="20" data-stripe="number" class = 'form-field'&gt;
      &lt;/label&gt;
    &lt;/div&gt;
  
    &lt;div class="form-group"&gt;
      &lt;label&gt;
        &lt;span&gt;Expiration (MM/YY)&lt;/span&gt;
        &lt;input type="text" size="2" data-stripe="exp_month" class ='form-field-expiry'&gt;
        &lt;span&gt; / &lt;/span&gt;
      &lt;input type="text" size="2" data-stripe="exp_year" class ='form-field-expiry'&gt;
      &lt;/label&gt;
  
    &lt;/div&gt;
  
    &lt;div class="form-group"&gt;
      &lt;label&gt;
        &lt;span&gt;CVC&lt;/span&gt;
        &lt;input type="text" size="3" data-stripe="cvc" class = 'form-field'&gt;
      &lt;/label&gt;
    &lt;/div&gt;
  
  
  
    &lt;input type="submit" class="c-btn-submit-charge" value="Submit Payment"&gt;
  
    &lt;/div&gt;
  &lt;% end %&gt;
  
  &lt;/div&gt;
  
  &lt;div class ='col-md-4 col-sm-12'&gt;
    &lt;div class = 'payment-box'&gt;
    &lt;p&gt; Information about your order:&lt;/p&gt;
    &lt;ul&gt;
      &lt;li&gt;You are subscribing to the full membership.&lt;/li&gt;
      &lt;li&gt;This subscription lasts for 3 months (90 days).&lt;/li&gt;
      &lt;li&gt;Do not subscribe again if you are already subscribed and your expiry date has not been passed.&lt;/li&gt;
      &lt;li&gt;Subscribing grants you access to every test and practice material on this website.&lt;/li&gt;
      &lt;li&gt;At the moment, this consists of 19 online DAT reading comprehension tests along with answer explanations.&lt;/li&gt;
      &lt;li&gt;Any additional premium material added (such as more tests or more DAT sections) after you subscribe will be automatically available to you with
      no extra charge.&lt;/li&gt;
  
  
    &lt;/ul&gt;
  
    &lt;div class = 'inner-box'&gt;
      &lt;p class = 'text-center'&gt; Total cost: $20 &lt;/p&gt;
  
  
    &lt;/div&gt;
  
    &lt;div class ='inner-box-payment'&gt;
  
  
    &lt;/div&gt;
  
  
  
  &lt;/div&gt;
  
  
  
  &lt;/div&gt;
  
  &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;script&gt;
    $(function() {
      var $form = $('#payment-form');
      $form.submit(function(event) {
        // Disable the submit button to prevent repeated clicks:
        $form.find('.submit').prop('disabled', true);
        // Request a token from Stripe:
        Stripe.card.createToken($form, stripeResponseHandler);
        // Prevent the form from being submitted:
        return false;
      });
    });
    function stripeResponseHandler(status, response) {
      // Grab the form:
      var $form = $('#payment-form');
      if (response.error) { // Problem!
        // Show the errors on the form:
        $form.find('.payment-errors').text(response.error.message);
        $form.find('.submit').prop('disabled', false); // Re-enable submission
      } else { // Token was created!
        // Get the token ID:
        var token = response.id;
        // Insert the token ID into the form so it gets submitted to the server:
        $form.append($('&lt;input type="hidden" name="stripeToken"&gt;').val(token));
        // Submit the form:
        $form.get(0).submit();
      }
    };
  &lt;/script&gt;
  </code></pre>
  
  <p>And that's it. I'm completely lost right now. What went wrong?</p>