title: Stripe::InvalidRequestError (This customer has no attached payment source)
body: <p>There seems to be a problem with sending customer data and token back to Stripe's server. I'm currently using the test api to make dummy transactions. But, I cannot get past this point for no reason at all. I've tried everything to fix this error. I will post the code and error message below.</p>
  
  <p>Subscriptions_Controller.rb</p>
  
  <pre><code>class SubscriptionsController &lt; ApplicationController
    before_filter :authenticate_user!, except: [:new]
    before_action :redirect_to_signup, only: [:new]
  
    def show
  
    end
  
    def new
      @subscription = current_user.subscription
      if @subscription.active
        @stripe_customer = Stripe::Customer.retrieve(@subscription.stripe_user_id)
        @stripe_subscription = @stripe_customer.subscription.first
      end
    end
  
    def create
      token = params[:stripeToken]
      customer = Stripe::Customer.create(
          :source =&gt; token,
          :plan =&gt; "gbsubscriptionlevel1",
          :email =&gt; current_user.email
      )
  
    rescue Stripe::CardError =&gt; e
      flash[:error] = e.message
      redirect_to new_subscription_path
  
      current_user.subscription.stripe_user_id = customer.id
      current_user.subscription.active = true
      current_user.subscription.save
  
      redirect_to users_index_path
    end
  
    def cancel_subscription
      @stripe_customer = Stripe::Customer.retrieve(
          current_user.subscription.stripe_user_id
      )
      @stripe_subscription = @stripe_customer.subscription.first
    end
  
    private
    def redirect_to_signup
      if !user_signed_in?
        session["user_return_to"] = new_subscription_path
        redirect_to new_user_registration_path
      end
    end
  end
  </code></pre>
  
  <p>_stripe_form.html.erb</p>
  
  <pre><code>&lt;div class="container"&gt;
    &lt;%= form_tag subscription_path, id: 'payment-form' do %&gt;
  
    &lt;form action="/subscription" method="POST" id="payment-form"&gt;
      &lt;span class="payment-errors"&gt;&lt;/span&gt;
  
      &lt;div class="row"&gt;
        &lt;div class="col-xs-4"&gt;
          &lt;label&gt;
            &lt;span&gt;Card Number&lt;/span&gt;
            &lt;input value="4242 4242 4242 4242" class="form-control" type="text" size="20" data-stripe="number"/&gt;
          &lt;/label&gt;
        &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="row"&gt;
        &lt;div class="col-xs-1"&gt;
          &lt;label&gt;
            &lt;span&gt;CVC&lt;/span&gt;
            &lt;input value="123" class="form-control" type="text" size="4" data-stripe="cvc"/&gt;
          &lt;/label&gt;
        &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="row"&gt;
        &lt;div class="col-xs-1"&gt;
          &lt;label&gt;MM&lt;/label&gt;
          &lt;input value="12" class="form-control" type="text" size="2" data-stripe="exp-month" placeholder="01"/&gt;
        &lt;/div&gt;
        &lt;div class="col-xs-1"&gt;
          &lt;label&gt;YYYY&lt;/label&gt;
          &lt;input value="2019" class="form-control" type="text" size="3" data-stripe="exp-year" placeholder="2020"/&gt;
        &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="row"&gt;
        &lt;div class="col-xs-1"&gt;
          &lt;br/&gt;
          &lt;button class="btn btn-primary-outline" type="submit"&gt;Create Subscription&lt;/button&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/form&gt;
    &lt;% end %&gt;
    &lt;script type="text/javascript" src="https://js.stripe.com/v2/"&gt;&lt;/script&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>subscription.js</p>
  
  <pre><code>Stripe.setPublishableKey('pk_test_tmBNNUvHTmtWXLhSL1q647iH');
  
  function stripeResponseHandler(status, response) {
      var $form = $('#payment-form');
  
      if (response.error) {
          // Show the errors on the form
          $form.find('.payment-errors').text(response.error.message);
          $form.find('button').prop('disabled', false);
      } else {
          // response contains id and card, which contains additional card details
          var token = response.id;
          // Insert the token into the form so it gets submitted to the server
          $form.append($('&lt;input type="hidden" name="stripeToken" /&gt;').val(token));
          // and submit
          $form.get(0).submit();
      }
  }
  
  jQuery(function ($) {
      $('#payment-form').submit(function (event) {
          var $form = $(this);
  
          // Disable the submit button to prevent repeated clicks
          $form.find('button').prop('disabled', true);
  
          Stripe.card.createToken($form, stripeResponseHandler);
  
          // Prevent the form from submitting with the default action
          return false;
      });
  });
  </code></pre>
  
  <p>stripe.rb</p>
  
  <pre><code>Stripe.api_key = ENV["STRIPE_API_TEST_SECRET_KEY"]
  </code></pre>