Charles Smith


850 Experience
0 Lessons Completed
1 Question Solved


Posted in Passing name objects to Stripe

Hi Chris

A few months ago I purchased the Stripe master class - awsome - learned a lot!! I could ask this question on Stack Overflow, but since the methods are specific to the course, I thought it be best asked here.

In the user.rb file, there is the method listed below that creates a Stripe customer is one doesn't exist.

def stripe_customer
    if stripe_id?
      stripe_customer = Stripe::Customer.create(email: email)

Stripe has a customer name field, how can I pass the user_first and user_last along with the email when creating a new customer? I looked on the Stripe api and it doesn't make reference at all to a name object.

Thank you.

I cannot for the life of me figure out the best model association to choose and I've thought myself into a corner. I'm building a site for a client that offers party services for four(4) locations in Southern California.

For this, I have three(3) models - Locations, Categories, Products.

Here are some URL examples:

The products model will have 4 price columns and the price on the page will be determined by the /location-url/ and will be displayed with jQuery. Other than that all the models are shared with the only caveate is that a Product has to belong to a category and location, but I want to be able to share the Product and Category models with many locations so I don't have to create a duplicate for each location. I hope I am making some sense. Thank you.

Posted in assign_attributes not working

In my addFieldToForm function, I had hiddenInput.setAttribute('name', "user[card_" + field + "]"); but after changing it to hiddenInput.setAttribute('name', "card_" + field); it works as expected.

Posted in assign_attributes not working

I just signed up for Payments with Stripe and Rails Master Class and am loving it...can't walk away from it; learning a ton!

Having an issue though and was hoping someone could lend a hand. I am following the videos exactly and the only thing I can see that is different is the videos are using the Stripejs form example from whereas I am using Elements. There is an Elements section in the videos which is why I implemented it, but the videos continue without it. Either way, things seem to be working ok, well - until this snag. Oh, even with the attributes not being assigned, Stripe is still creating/updating users properly.

I am trying to assign_attributes if params[:card_last4] but the attributes are not saving so I am not able to display card_brand, card_last4 etc.. Below is my code, thank you.


def create
    customer = current_user.stripe_customer
      subscription = customer.subscriptions.create(
          source: params[:stripeToken],
          plan: params[:plan],

          card_brand: params[:card_brand],
          card_last4: params[:card_last4],
          card_exp_month: params[:card_exp_month],
          card_exp_year: params[:card_exp_year]
      ) if params[:card_last4]

      flash.notice = 'Thank you for subscribing'
      redirect_to root_path
    rescue Stripe::CardError => e
      flash.alert = e.message
      render action: :new


<%= form_tag subscription_path, id: 'payment-form' do |form| %>
  <div class="form-row">
    <label for="card-element">
      Credit or debit card
    <div id="card-element">
      <!-- a Stripe Element will be inserted here. -->
    <%= hidden_field_tag :plan, params[:plan] %>
    <!-- Used to display Element errors -->
    <div id="card-errors" role="alert"></div>

  <button>Submit Payment</button>

<% end %>

Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

© 2024 GoRails, LLC. All rights reserved.