Monday, January 16, 2017

Credit card declined : This customer has no attached payment source.

I was getting this error when using Stripe to subscribe a customer. Solution:

def allowed_params
  params.permit(:plan_name, :email, :password, :stripeToken, :authenticity_token)

customer = Stripe::Customer.create(email: email, plan: plan_id, source: stripe_token)

<%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => false %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => false %>

Best thing to do is to fail early and loudly, this will prevent the invalid request being submitted to Stripe. You must have:

raise 'Missing stripe token. Cannot process payment.' if params[:stripeToken].blank?