I've been following this tutorial for Payola.
I've tested adding my own plans and they do appear on my dashboard and on my console. However, when I go to create a subscription, I get the following error:
undefined method `amount' for nil:NilClass
on the following line:
subscription = Payola::CreateSubscription.call(params, owner)
Here are my files for reference:
subscriptions/new.html.erb
<h1>New Subscription</h1>
<em><%= @plan.name %><em/><br><br>
<!-- this header can go in <head> or at the bottom of <body> -->
<%= render 'payola/transactions/stripe_header' %>
<%= form_tag('/subscriptions', class: 'payola-onestep-subscription-form', 'data-payola-base-path' => '/payola', 'data-payola-plan-type' => @plan.plan_class, 'data-payola-plan-id' => @plan.id) do |f| %>
<span class="payola-payment-error"></span>
<input name="stripeEmail" data-payola="email" type="hidden" value="<%= current_user.email %>"/>
Card Number<br>
<input type="text" data-stripe="number"></input><br><br>
Exp Month<br>
<input type="text" data-stripe="exp_month"></input><br><br>
Exp Year<br>
<input type="text" data-stripe="exp_year"></input><br><br>
CVC<br>
<input type="text" data-stripe="cvc"></input><br><br>
<input type="submit"></input>
<% end %>
subscriptions_controller.erb
class SubscriptionsController < ApplicationController
# bring in the `render_payola_status` helper.
include Payola::StatusBehavior
before_action :load_plans
def index
end
def new
@plan = EmojiPlan.find(params[:plan_id])
end
def create
# do any required setup here, including finding or creating the owner object
owner = current_user # this is just an example for Devise
# set your plan in the params hash
params[:plan] = EmojiPlan.find_by(id: params[:plan_id])
# call Payola::CreateSubscription
subscription = Payola::CreateSubscription.call(params, owner)
# Render the status json that Payola's javascript expects
render_payola_status(subscription)
end
protected
def load_plans
@plans = EmojiPlan.order('amount')
end
end
routes.rb
Rails.application.routes.draw do
resources :emoji_plans
resources :subscriptions
devise_for :admins
devise_for :users
mount Payola::Engine => '/payola', as: :payola
# For details on the DSL available within this file, see
http://guides.rubyonrails.org/routing.html
end
emoji_plan.rb
class EmojiPlan < ApplicationRecord
include Payola::Plan
def redirect_path(subscription)
# you can return any path here, possibly referencing the given subscription
'/'
end
end
create_emoji_plans.rb
class CreateEmojiPlans < ActiveRecord::Migration[5.1]
def change
create_table :emoji_plans do |t|
t.integer :amount
t.string :interval
t.string :stripe_id
t.string :name
t.timestamps
end
end
end
Don't make fun of my plan names - I'm making a 'fun' project. ;)