koudoku
koudoku copied to clipboard
Koudoku plan subscription creation on user sign up
I'm using koudoku to accept payment .i have listing and users .Setup koudoku gem as instructed by the guides . How i can make every user on the app enroll in a plan on sign up(i'm using devise) and send the info to stripe in the same process , the goal is to have everybody on the free plan and themselves can upgrade in their dashboard?
so far this is what i have or think it should look like and i stuck. (
- create a function "create_subscription" in the subscription model that take parameters from the subscription params hash
class Subscription < ActiveRecord::Base
include Koudoku::Subscription
belongs_to :user
belongs_to :coupon
def create_subscription
subscription = subscription.new
plan_id = subscription.plan.first.id
subscription.subscription_owner = @owner_id
subscription.save
subscription
end
end
2)call the function in the devise registrations controller
class Users::RegistrationsController < Devise::RegistrationsController
include ApplicationHelper
def create
super
@user.create_subscription()
# Sends email to user when user is created.
TimarcheMailer.welcome_email(@user).deliver
end
end
in the logs after user creation only one parameter(user_id) was saved in the subscriptions tables
SQL (16.0ms) INSERT INTO "subscriptions" ("created_at", "updated_at", "user_id") VALUES (?, ?, ?) [["created_at", "2015-05-29 07:26:24.993908"], [
"updated_at", "2015-05-29 07:26:24.993908"], ["user_id", 55]]
so far none of the users created have an associated enrollment . any pointers will be helpful.
PS.it's not really a gem issue it's implementation , always posted in stackoverflow. i'm trying to get the answers