Darren Booker

Joined

130 Experience
0 Lessons Completed
0 Questions Solved

Activity

Perfect.

JWPLAYER is exactly what I was looking for. Chris one more question. Rails uses the standard video_tag to actually render the video. Is there a way to count views like youtube. I know jwplayer might have the feature but if I wanted to do it from scratch, how would you go about implmenting this feature?

Thanks!

Hi Chris,

I am pretty sure they have a complex system implmented but at the basics of it, how could you go about implementing an autoplay advertise video before the actual video itself starts to play just like youtube? Never seen it done in a rails application. I created a clone youtube application for the fun of it and want to take it up a knotch a bit.

Is there third party service for advertisement you can implement?

Posted in Braintree cancel subscription

Hi,

So, I implemented the braintree payment processing and everything works perfect. Now the only issue I am having is if I user cancels their subscription through my web application everything works fine, but if I cancel the subscription or braintree cancels their subscription through my braintree dashboard it does not update my users cancellation through my web application. I figure this is a problem because if a user does not pay their monthly bill be default braintree cancels their subscription due to failure of payment and users will continue to use my service for free.

class SubscriptionsController < ApplicationController
    before_action :authenticate_user!, except: [:new]
    before_action :redirect_to_signup, only: [:new]

  def show

  end

  def new

  end

  def create
    if current_user.braintree_id?
      customer = Braintree::Customer.find(current_user.braintree_id)
    else
      result = Braintree::Customer.create(
        email: current_user.email,
        payment_method_nonce: params[:payment_method_nonce]
      )
      customer = result.customer
      current_user.update(braintree_id: customer.id)
    end

    result = Braintree::Subscription.create(
      payment_method_token: customer.payment_methods.find{ |pm| pm.default? }.token,
      plan_id: '25pm'
    )
    current_user.update(braintree_subscription_id: result.subscription.id)

    redirect_to root_path, notice: "You have been subscribed"
  end

  def destroy
    customer = Braintree::Customer.find(current_user.braintree_id)
    Braintree::Subscription.cancel(current_user.braintree_subscription_id)
    current_user.update(braintree_subscription_id: nil)

    redirect_to root_path, notice: "Your Subscription has been canceled"
  end

  private

  def redirect_to_signup
    if !user_signed_in?
        session["user_return_to"] = new_subscription_path
        redirect_to new_user_registration_path
    end
  end

end

Posted in Integrating Braintree (and PayPal) Discussion

Chris,

This is my first time implementing braintree and just curious, if a customer is coming up on their second billing cycle and their credit card on file declines will that customer account being inactive or as I should say would the user braintree_subscription_id delete from the system?

Posted in Subscriptions with Stripe Discussion

For some reason my Stripe data is not being saved to my user? Below is screenshots.
I tried to permit the stripe attributes from my user table but no luck. When I go into my stripe dashboard all the data from the user is there but the data is not saved to database.

Also when I ran the code below. When the user paid for their subscription and redirects me. For some reason I still get the results of "My BAD". I do not have any attr_accessor anywhere as well.

<% if current_user_subscribed? %>
  OUR SECRET VIDEO
  <% else %>
  MY BAD
  <% end %>


    subscriptions_controller.rb

    class SubscriptionsController < ApplicationController
    before_action :authenticate_user!, except: [:new]
    before_action :redirect_to_signup, only: [:new]

  def show

  end

  def new

  end

  def create
     Stripe.api_key = Rails.application.secrets.stripe_secret_key
      token = params[:stripeToken]

      customer = if current_user.stripe_id?
                 Stripe::Customer.retrieve(current_user.stripe_id)
               else
                 Stripe::Customer.create(email: current_user.email, :source => "tok_amex")
               end

      subscription = customer.subscriptions.create(
      plan: "plan_DgFuhaPFeIbeT3"
      )

      current_user.update(
      card_last4: params[:card_last4],
      card_exp_month: params[:card_exp_month],
      card_exp_year: params[:card_exp_year],
      card_type: params[:card_brand]
    )

      redirect_to root_path, notice: "You already a premium member!"
  end

  def destroy

  end

  private

  def redirect_to_signup
    if !user_signed_in?
        session["user_return_to"] = new_subscription_path
        redirect_to new_user_registration_path
    end
  end

end


RAILS CONSOLE

User Load (0.5ms)  SELECT  "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT $1  [["LIMIT", 1]]
 => #<User id: 7, email: "ddd@gmail.com", first_name: nil, last_name: nil, country: nil, state: nil, city: nil, ph
one: nil, created_at: "2018-09-27 20:20:49", updated_at: "2018-09-27 20:20:49", subscribed: nil, stripe_id: nil, s
tripe_subscription_id: nil, card_last4: nil, card_exp_month: nil, card_exp_year: nil, card_type: nil>
2.4.1 :002 >

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.