-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add stripe checkout for invoices #325
Conversation
Current Code Coverage Percent of this PR:96.71 %Files having coverage below 100%
|
ca8b162
to
097a37f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Provided some feedback
private | ||
|
||
def load_invoice | ||
@invoice = Invoice.includes(client: :company).find(params[:invoice_id]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove the load_invoice
before action
@invoice = Invoice.includes(client: :company).find(params[:invoice_id]) | |
def invoice | |
@_invoice ||= Invoice.includes(client: :company).find(params[:invoice_id]) | |
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why @_
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We follow this convention in Miru for memorized variables. Global search for @_
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw how will the view templates access this instance variable since we are not loading this in before_action
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass as locals
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one last confusion, Why are we using instance variables if we want to pass them as locals? They should anyway be available to the views, right?
It feels like we are deliberately not taking advantage of the magic that Rails provides us.
Is there any specific reason we decided to move away from our own set standards in Miru?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think because, in this action, we are using the variable only to pass as locals, but for a complex action we might use the invoice
method at multiple places and so an instance variable will be accessible everywhere, for example a private method would not need an argument to be passed
# frozen_string_literal: true | ||
|
||
class ApplicationService | ||
def self.process(*args, &block) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to name the method perform
. Also @alkesh26 @keshavbiswa @akhilgkrishnan We were going to use an interactor pattern right? Or since this PR is urgent, we could go with service classes and then refactor later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes initially the plan was to add interactor classes rather than service classes, if the PR is urgent we can go with service classes too.
class Checkout < ApplicationService | ||
def initialize(params) | ||
@invoice = params[:invoice] | ||
@company = invoice.client.company |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add an association, or delegation so we could access like invoice.company
ensure_client_registered! | ||
checkout! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious why are we using bang methods everywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are not rescuing the exceptions, I added !
to indicate that we should expect these methods to raise exceptions.
def description | ||
"Invoice from #{company.name} for #{currency} #{invoice.amount} due on #{invoice.due_date}" | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's consider adding an invoice_presenter
cc @keshavbiswa @alkesh26
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Presenters are needed in many places, maybe we can start with this PR.
|
||
class AddStripeIdToClients < ActiveRecord::Migration[7.0] | ||
def change | ||
add_column :clients, :stripe_id, :string, default: nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@supriya3105 Do we have only one stripe account per client?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to sync customers and payments on stripe.
require "rails_helper" | ||
|
||
RSpec.describe "Invoices::Payments", type: :request do | ||
describe "GET /index" do | ||
pending "add some examples (or delete) #{__FILE__}" | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specs are pending, checkout https://github.com/stripe-ruby-mock/stripe-ruby-mock
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! This is awesome🚀
@@ -4,5 +4,7 @@ Hi, <%= @invoice.client_name %> | |||
You have an invoice - <%= @invoice.invoice_number %> with amount <%= @invoice.amount %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amount would be in cents, convert it to $
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments.
def success | ||
@invoice.paid! | ||
end | ||
|
||
def cancel | ||
render | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We prefer REST based controllers.
@apoorv1316 please test it and merge if all ok. |
Fixes #304
https://www.loom.com/share/a91974fb521e4e29afa830c50bd219ad