Looking for something like Pay Pal that is more suited to Rails

33 views
Skip to first unread message

David Merrick

unread,
Jun 26, 2018, 1:01:14 AM6/26/18
to Ruby on Rails: Talk
Looking for something like Pay Pal that is more suited to Rails and is not too complicated to get up and running.

Cheers Dave

--
Dave Merrick

Daves Web Designs

Website http://www.daveswebdesigns.co.nz/

Email merri...@gmail.com

Ph   03 216 2053

Cell 027 3089 169

Mugurel Chirica

unread,
Jun 26, 2018, 4:24:28 AM6/26/18
to rubyonra...@googlegroups.com
Choosing a payment provider it's difficult and depends mostly on your needs.

If you are more interested to get up and running with payments with not so many issues, then I recommend you to use https://stripe.com.

Working with it is great in my opinion (compared with other payment providers), and l have heard other developers enjoy working with it as well.
The documentation is great, there are many tutorials, and getting started (without too much customisation) is very easy.
Also their taxes are not that bad either.

Hope that helps.

David Merrick

unread,
Jun 27, 2018, 1:44:15 AM6/27/18
to Ruby on Rails: Talk
Hi looking for an easy to integrate with Rails Payment Gateway that as part of the Registration Process once the user has made the payment they gain access to

restricted pages. No need for shopping carts.

Cheers Dave

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL37D8EHFS89U-%3Dzx8heVW0Nz%3D0cmSE5wGMnjXes_R261GvEXg%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

David Merrick

unread,
Aug 9, 2018, 1:29:04 AM8/9/18
to Ruby on Rails: Talk
Hi Mugurel Looking for help to integrate Stripe into my Website

Current users Controller is 

class UsersController < ApplicationController
  before_action :logged_in_user, only: [:index, :edit, :update, :destroy,
                                        :following, :followers]
  
  before_action :correct_user,   only: [:edit, :update]
  before_action :admin_user,     only: :destroy
  
  def index
    @users = User.where(activated: true).paginate(page: params[:page])
  end
  
  def show
    @user = User.find(params[:id])
    redirect_to root_url and return unless @user.activated?
  end

  def new
    @user = User.new
  end

  def create
    @user = User.new(user_params)
    if @user.save
      @user.send_activation_email
      flash[:info] = "Please check your email to activate your account."
      redirect_to root_url
    else
      render 'new'
    end
  end  

  def edit
    @user = User.find(params[:id])
  end

  def update
    @user = User.find(params[:id])
    if @user.update_attributes(user_params)
      flash[:success] = "Profile updated"
      redirect_to @user
    else
      render 'edit'
    end
  end
  
  def destroy
    User.find(params[:id]).destroy
    flash[:success] = "User deleted"
    redirect_to users_url
  end

  
  private

    def user_params
      params.require(:user).permit(:name, :email, :password,
                                   :password_confirmation)
    end
    
    # Confirms the correct user.
    def correct_user
      @user = User.find(params[:id])
      redirect_to(root_url) unless current_user?(@user)
    end
    
    # Confirms an admin user.
    def admin_user
      redirect_to(root_url) unless current_user.admin?
    end
    
end

Looking at changing users create method

to include the create method of Charges Controller

class ChargesController < ApplicationController
def new
end

def create
  # Amount in cents
  @amount = 2000

  customer = Stripe::Customer.create(
:email => params[:stripeEmail],
:source  => params[:stripeToken]
  )

  charge = Stripe::Charge.create(
:customer    => customer.id,
:amount      => @amount,
:description => 'Rails Stripe customer',
:currency    => 'usd'
  )

rescue Stripe::CardError => e
  flash[:error] = e.message
  redirect_to new_charge_path
end
end

Current form for a new user

<%= form_for(@user) do |f| %>
  <%= render 'shared/error_messages', object: f.object %>

  <%= f.label :name %>
  <%= f.text_field :name, class: 'form-control' %>

  <%= f.label :email %>
  <%= f.email_field :email, class: 'form-control' %>

  <%= f.label :password %>
  <%= f.password_field :password, class: 'form-control' %>

  <%= f.label :password_confirmation %>
  <%= f.password_field :password_confirmation, class: 'form-control' %>

  <%= f.submit yield(:button_text), class: "btn btn-primary" %>
<% end %>

Need to include part of new.html.erb below into the form above

<%= form_tag charges_path do %>
  <article>
    <% if flash[:error].present? %>
      <div id="error_explanation">
        <p><%= flash[:error] %></p>
      </div>
    <% end %>
    <label class="amount">
      <span>Amount: $20.00</span>
    </label>
  </article>

  <script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
          data-key="<%= Rails.configuration.stripe[:publishable_key] %>"
          data-description="Membership Subscription"
          data-amount="2000"
          data-locale="auto">
  </script>
<% end %>

The idea being that when new user signs up they will include their credit card details into the users form. 
If the card details are correct and the user is not already in the database they will be accepted as a new user.

The existing users model is shown below.

class User < ApplicationRecord                               
                                                                    
  attr_accessor :remember_token, :activation_token, :reset_token
  before_save   :downcase_email
  before_create :create_activation_digest
  
  validates :name,  presence: true, length: { maximum: 50 }
  VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
  validates :email, presence: true, length: { maximum: 255 },
                    format: { with: VALID_EMAIL_REGEX },
                    uniqueness: { case_sensitive: false }
  has_secure_password
  validates :password, presence: true, length: { minimum: 6 }, allow_nil: true

  # Returns the hash digest of the given string.
  def User.digest(string)
    cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST :
                                                  BCrypt::Engine.cost
    BCrypt::Password.create(string, cost: cost)
  end

  # Returns a random token.
  def User.new_token
    SecureRandom.urlsafe_base64
  end
  
  # Remembers a user in the database for use in persistent sessions.
  def remember
    self.remember_token = User.new_token
    update_attribute(:remember_digest, User.digest(remember_token))
  end
  
  # Returns true if the given token matches the digest.
  def authenticated?(attribute, token)
    digest = send("#{attribute}_digest")
    return false if digest.nil?
    BCrypt::Password.new(digest).is_password?(token)
  end

  # Forgets a user.
  def forget
    update_attribute(:remember_digest, nil)
  end
  
  
  # Activates an account.
  def activate
    update_columns(activated: true, activated_at: Time.zone.now)
  end

  # Sends activation email.
  def send_activation_email
    UserMailer.account_activation(self).deliver_now
  end
  
  # Sets the password reset attributes.
  def create_reset_digest
    self.reset_token = User.new_token
    update_attribute(:reset_digest,  User.digest(reset_token))
    update_attribute(:reset_sent_at, Time.zone.now)
  end

  # Sends password reset email.
  def send_password_reset_email
    UserMailer.password_reset(self).deliver_now
  end
  
  # Returns true if a password reset has expired.
  def password_reset_expired?
    reset_sent_at < 2.hours.ago
  end
  
  # Returns a user's status feed.
      
  private

    # Converts email to all lower-case.
    def downcase_email
      email.downcase!
      #self.email = email.downcase
    end

    # Creates and assigns the activation token and digest.
    def create_activation_digest
      self.activation_token  = User.new_token
      self.activation_digest = User.digest(activation_token)
    end
  
end
I f you have any ideas on how to achieve this can you let me know please.

Or is there another way doing it?

Cheers Dave



--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.


--
Dave Merrick

Daves Web Designs

Website http://www.daveswebdesigns.co.nz
Email merri...@gmail.com

Ph   03 216 2053

Cell 027 3089 169

Mugurel Chirica

unread,
Aug 10, 2018, 4:42:28 PM8/10/18
to rubyonra...@googlegroups.com
Hello David, thanks for asking for my help.

Based on the details you provided, you are asking quite a general task and I can't help you that much.

I don't know what's your experience you have with Ruby on Rails in general, but the best thing I can do is to give you general development suggestions.

Try and write down what you are trying to achieve and then break everything in small steps, and document that as an algorithm.
Usually when I have something that's too complex to wrap my head around I do something like this in the controller or whatever.

---
# Add stripe
# Create stripe account
# Get stripe credentials
# Add stripe gem
(...)
# Connect stripe account to existing user
---

After you have your initial list, you can break down everything and retry the steps.

This list is best to offer specific help, and answer specific questions that do not require too much set-up from us (some might be busy enough, and have small window of time to check the email, etc).

To get help for big problems the best thing would be to pair program with someone.
You can either pay someone for their time and they can pair with you (you can search on google, there are various sites), or try and ask for someone to pair with you on a different channel like on this mailing list, or an IRC channel.

Sorry I could not be of much help, but good luck with your task.
Don't give up, if things are hard, take smaller chunks to work on from the task.

Cheers

Reply all
Reply to author
Forward
0 new messages