Skip to content
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

Merged
merged 1 commit into from
Apr 26, 2022

Conversation

shivamsinghchahar
Copy link
Contributor

@shivamsinghchahar shivamsinghchahar commented Apr 25, 2022

@github-actions
Copy link

github-actions bot commented Apr 25, 2022

Current Code Coverage Percent of this PR:

96.71 %

Files having coverage below 100%

Impacted Files Coverage
/app/controllers/invoices_controller.rb 63.64 %
/app/models/invoice.rb 95.83 %
/app/models/client.rb 92.31 %
/app/services/application_service.rb 66.67 %
/app/controllers/invoices/payments_controller.rb 61.11 %
/app/services/invoice_payment/checkout.rb 43.48 %

@shivamsinghchahar shivamsinghchahar force-pushed the 304-enable-stripe-for-invoice-payments branch from ca8b162 to 097a37f Compare April 25, 2022 12:22
Copy link
Contributor

@rohitjoshixyz rohitjoshixyz left a 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])
Copy link
Contributor

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

Suggested change
@invoice = Invoice.includes(client: :company).find(params[:invoice_id])
def invoice
@_invoice ||= Invoice.includes(client: :company).find(params[:invoice_id])
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why @_ ?

Copy link
Contributor

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 @_

Copy link
Contributor Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pass as locals

Copy link
Contributor Author

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?

Copy link
Contributor

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)
Copy link
Contributor

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

Copy link
Contributor

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
Copy link
Contributor

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

Comment on lines +15 to +16
ensure_client_registered!
checkout!
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Comment on lines +30 to +32
def description
"Invoice from #{company.name} for #{currency} #{invoice.amount} due on #{invoice.due_date}"
end
Copy link
Contributor

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

Copy link
Contributor

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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Comment on lines +3 to +9
require "rails_helper"

RSpec.describe "Invoices::Payments", type: :request do
describe "GET /index" do
pending "add some examples (or delete) #{__FILE__}"
end
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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 %>
Copy link
Contributor

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 $

Copy link
Contributor

@keshavbiswa keshavbiswa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments.

Comment on lines +18 to +24
def success
@invoice.paid!
end

def cancel
render
end
Copy link
Contributor

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.

@supriya3105
Copy link
Contributor

@apoorv1316 please test it and merge if all ok.

@vipulnsward vipulnsward merged commit 644dea8 into develop Apr 26, 2022
@vipulnsward vipulnsward deleted the 304-enable-stripe-for-invoice-payments branch April 26, 2022 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ability to pay for an invoice
5 participants