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

Update business_vat_id on customer and tax_percent on Subscription #190

Open
wants to merge 11 commits into
base: bullet-train
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ pkg/*
*.sqlite3
*.log
/.idea
*.iml
*.iml
.DS_Store
15 changes: 13 additions & 2 deletions app/concerns/koudoku/subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ def processing!
prepare_for_upgrade if upgrading?

# update the package level with stripe.
customer.update_subscription(:plan => self.plan.stripe_id, :prorate => Koudoku.prorate)
if self.team.tax_number.present? && self.team.tax_percent.present?
Stripe::Customer.update(self.stripe_id, { business_vat_id: "#{self.team.country_code}#{self.team.tax_number}" })
customer.update_subscription(:plan => self.plan.stripe_id, :prorate => Koudoku.prorate, :tax_percent => self.team.tax_percent)
else
customer.update_subscription(:plan => self.plan.stripe_id, :prorate => Koudoku.prorate)
end

finalize_downgrade! if downgrading?
finalize_upgrade! if upgrading?
Expand Down Expand Up @@ -68,6 +73,7 @@ def processing!
begin
raise Koudoku::NilCardToken, "No card token received. Check for JavaScript errors breaking Stripe.js on the previous page." unless credit_card_token.present?
customer_attributes = {
business_vat_id: "#{self.team.country_code}#{self.team.tax_number}",
description: subscription_owner_description,
email: subscription_owner_email,
card: credit_card_token # obtained with Stripe.js
Expand All @@ -86,7 +92,12 @@ def processing!
customer = Stripe::Customer.create(customer_attributes)

finalize_new_customer!(customer.id, plan.price)
customer.update_subscription(:plan => self.plan.stripe_id, :prorate => Koudoku.prorate)

if self.team.tax_percent.present?
customer.update_subscription(:plan => self.plan.stripe_id, :prorate => Koudoku.prorate, :tax_percent => self.team.tax_percent)
else
customer.update_subscription(:plan => self.plan.stripe_id, :prorate => Koudoku.prorate)
end

rescue Stripe::CardError => card_error
errors[:base] << card_error.message
Expand Down
2 changes: 1 addition & 1 deletion koudoku.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Gem::Specification.new do |s|

s.add_dependency "rails"
s.add_dependency "stripe"
s.add_dependency "stripe_event"
s.add_dependency "stripe_event", ">= 2.2.0"
s.add_dependency "bluecloth"

s.add_development_dependency "jquery-rails"
Expand Down
2 changes: 1 addition & 1 deletion lib/koudoku/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Koudoku
VERSION = "1.3.0"
VERSION = "2.0.3"
end