Chris Oliver

Joined

293,020 Experience
93 Lessons Completed
295 Questions Solved

Activity

Hey Taylor,

One-off charges are basically the same as Subscriptions. You just create a Stripe::Charge object instead of a Stripe::Subscription. 

1. Add Stripe to the Gemfile
2. Add the Stripe JS and checkout form to the page
3. The form for a new job should POST to the create action, so in there you can process the payment. 
4. Handle the payment and job creation together in a transaction

def create
  @job = current_user.jobs.build(jobs_params)
  if @job.create_with_stripe(params[:stripeToken])
    redirect_to @job
  else
    render 'new'
  end
end

class Job < ApplicationRecord
  def create_with_stripe(token)
    if valid?
      # Charge the user's card:
      charge = Stripe::Charge.create(
        :amount => 999,
        :currency => "usd",
        :source => token,
      )
      update(charge_id: charge.id)
    else
      false
    end
  rescue Stripe::CardError, Stripe::InvalidRequestError => e
    errors.add :base, "Whoops! We were unable to process your card. #{e.message}"
    false
  end
end

This way your payment logic is nicely organized with your Job. You check if the job is valid first, then we can fail quickly if it isn't valid. Then if it is valid, we can create the charge, and then update the Job with the charge ID for refund / reporting purposes. And if Stripe's charge fails with an error, we catch that and add the error to the Job and return false. Then your controller is nice and simple and just has to check if the create with stripe method returns true or false.

Posted in RailsConf

I was really wanting to, but I don't think I'll make it this year.

Posted in How to update TailwindsCSS?

Pretty much you'd just update the version in your package.json and use yarn to install it. You'll want to check with the releases page and see if anything has been deprecated or removed and upgrade your code if so. Other than that, I don't think there's much else you'd have to do.

Posted in Tools

New section I'm rolling out soon! Accidentally published it too soon. :) I wanted a place to recommend gems (like which file uploading tool should you pick?)

Posted in Deploy Ubuntu 16.04 Xenial Xerus Discussion

Hey Juan, I would probably just SSH in and run those commands on the server in the app's current directory. You probably could run Capistrano tasks to do that, but SSH is probably easier.

Posted in Webpacker error from Vue.js Trello Clone Series

You can get that error if you made a typo because it can't compile the file. Try checking your code for errors.

Posted in New server failed provisioning

This also happens if you used the 512MB server size. It still lists as available even though it is not actually. You can use a 1GB server for the same price and it will work fine too.

Posted in Building A Hosting Platform in Ruby Discussion

Yep, exactly.
Rough outline of how I'd build this:

1. Create a unique referral token for each user
2. Add the link to the UI for the user (link to the homepage with the token) 
<%= link_to root_url(ref: current_user.referral_token), root_url(ref: current_user.referral_token) %>
3. Create a before action on ApplicationController to set the referrer
before_action :set_referrer 
def set_referrer
  # Just store this for later, we will check this out during checkout
  cookies[:ref] = {value: params[:ref], expiry: 30.days.from_now} if params[:ref] && !user_signed_in?
end
4. Then you can check for cookies[:ref] during checkout and apply the discount to the user accounts.

Probably the easiest solution for giving these coupons / discounts out is by simply updating each of the user accounts and applying a credit to each one. This way you don't have to deal with Stripe Coupons or roll your own subscription system.

Also, Stripe has a tutorial on using coupons that will be good to read through even though you may not use this: https://stripe.com/docs/recipes/coupons-for-charges

Posted in Building A Hosting Platform in Ruby Discussion

Yep, you'll just have to use the Custom VPS option and have your server created on Hetzner first.
Hey Allison,

It's still a work in progress, but let me upload it and share it for you. I know several other people have asked and I just never really felt it was ready enough to share, but then anyone can help fix bugs. :)

Posted in Condition if devise action view

I think it is:

<% if devise_controller? %>

Are each of these SSL certs in a separate file?

Are you restarting nginx with `nginx restart` or `nginx reload`?

I've never dealt with near that many SSL certs so that's certainly a new problem to me. I did find this blog which talks about handling 1022 sites and SSL certs with server configs: https://jeremyfelt.com/2016/01/16/managing-ssl-certificates-and-https-configuration-at-scale/ Seems like it has a couple tips that might help.
As far as Heroku goes, I had to add the nodejs buildpack to my Rails app so it would properly compile Webpacker with Ruby. You basically end up with both the Ruby and Node buildpacks and that gives all the Ruby and Node/Yarn versions required to get things going.

Posted in Building A Hosting Platform in Ruby Discussion

It's actually completely custom. I exported my Disqus comments and imported them into the forum. Then extended the forum to have nesting. There are still a few warts here and there because it's doing double duty for comments and the forum, but I'm going to try to clean those up tomorrow.

Posted in Rails & Vue.js Trello Clone - Part 2 Discussion

Make sure you're using rails-ujs and have it included in your asset pipeline. It was introduced in one of the newer versions of Rails to remove jQuery. If you're on an older version of Rails you can either upgrade or change the Rails.ajax to jQuery's version.
Hey Jacob,

Those files are from the new bootsnap gem. They're caching your application's require paths and things in a binary format so your app boots WAY faster. You don't need them stored in your git repo. 

Posted in Building A Hosting Platform in Ruby Discussion

Just thought I would share this in case anyone is interested how Hatchbox.io works. 👍

Posted in Rails & Vue.js Trello Clone - Part 1 Discussion

I literally just rebuilt the comment system (replacing Disqus) so there are some bugs. 🤓

You can think of that approach as similar to binding your events in jQuery. I worked on a nice little wrapper for that which I need to release. And once I get a chance to check out this other approach, I'll let you know. Might be a better way to structure things.