tang 0.2.2 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +3 -3
  3. data/app/controllers/tang/account/application_controller.rb +2 -4
  4. data/app/controllers/tang/account/cards_controller.rb +11 -8
  5. data/app/controllers/tang/account/coupons_controller.rb +1 -1
  6. data/app/controllers/tang/account/receipts_controller.rb +10 -4
  7. data/app/controllers/tang/account/subscriptions_controller.rb +11 -8
  8. data/app/controllers/tang/admin/application_controller.rb +4 -4
  9. data/app/controllers/tang/admin/coupons_controller.rb +18 -14
  10. data/app/controllers/tang/admin/customers_controller.rb +16 -16
  11. data/app/controllers/tang/admin/dashboard_controller.rb +1 -1
  12. data/app/controllers/tang/admin/invoices_controller.rb +6 -6
  13. data/app/controllers/tang/admin/payments_controller.rb +9 -9
  14. data/app/controllers/tang/admin/plans_controller.rb +21 -19
  15. data/app/controllers/tang/admin/search_controller.rb +15 -14
  16. data/app/controllers/tang/admin/subscriptions_controller.rb +16 -17
  17. data/app/controllers/tang/plans_controller.rb +1 -1
  18. data/app/helpers/tang/application_helper.rb +22 -28
  19. data/app/jobs/tang/import_charges_job.rb +4 -8
  20. data/app/jobs/tang/import_coupons_job.rb +3 -3
  21. data/app/jobs/tang/import_customers_job.rb +15 -13
  22. data/app/jobs/tang/import_invoices_job.rb +7 -7
  23. data/app/jobs/tang/import_plans_job.rb +4 -6
  24. data/app/jobs/tang/import_subscriptions_job.rb +4 -4
  25. data/app/mailers/application_mailer.rb +1 -1
  26. data/app/mailers/tang/stripe_mailer.rb +8 -9
  27. data/app/mailers/tang/subscription_mailer.rb +4 -1
  28. data/app/models/concerns/tang/customer.rb +32 -32
  29. data/app/models/tang/card.rb +7 -8
  30. data/app/models/tang/charge.rb +28 -50
  31. data/app/models/tang/coupon.rb +27 -25
  32. data/app/models/tang/invoice.rb +16 -17
  33. data/app/models/tang/invoice_item.rb +16 -18
  34. data/app/models/tang/plan.rb +31 -16
  35. data/app/models/tang/subscription.rb +34 -42
  36. data/app/services/tang/apply_customer_discount.rb +2 -2
  37. data/app/services/tang/apply_subscription_discount.rb +2 -2
  38. data/app/services/tang/cancel_subscription.rb +2 -2
  39. data/app/services/tang/change_subscription.rb +4 -4
  40. data/app/services/tang/create_coupon.rb +3 -5
  41. data/app/services/tang/create_invoice.rb +2 -2
  42. data/app/services/tang/create_plan.rb +9 -8
  43. data/app/services/tang/create_subscription.rb +18 -15
  44. data/app/services/tang/delete_card.rb +3 -3
  45. data/app/services/tang/delete_coupon.rb +3 -3
  46. data/app/services/tang/delete_customer.rb +2 -2
  47. data/app/services/tang/delete_plan.rb +2 -2
  48. data/app/services/tang/fail_invoice.rb +5 -6
  49. data/app/services/tang/pay_invoice.rb +2 -3
  50. data/app/services/tang/refresh_invoice_pdf.rb +9 -0
  51. data/app/services/tang/remove_customer_discount.rb +2 -2
  52. data/app/services/tang/remove_subscription_discount.rb +3 -3
  53. data/app/services/tang/save_card.rb +8 -9
  54. data/app/services/tang/update_coupon.rb +3 -5
  55. data/app/services/tang/update_customer.rb +4 -4
  56. data/app/services/tang/update_plan.rb +3 -5
  57. data/app/services/tang/update_subscription.rb +3 -5
  58. data/app/validators/future_validator.rb +4 -4
  59. data/app/views/tang/account/cards/show.html.erb +1 -1
  60. data/app/views/tang/account/receipts/_receipt.html.erb +1 -1
  61. data/app/views/tang/account/subscriptions/show.html.erb +14 -3
  62. data/app/views/tang/admin/coupons/show.html.erb +1 -1
  63. data/app/views/tang/admin/customers/show.html.erb +2 -2
  64. data/app/views/tang/admin/plans/show.html.erb +1 -1
  65. data/app/views/tang/admin/subscriptions/show.html.erb +2 -2
  66. data/app/views/tang/plans/index.html.erb +1 -1
  67. data/config/initializers/stripe.rb +2 -2
  68. data/config/initializers/stripe_event.rb +38 -33
  69. data/config/routes.rb +3 -1
  70. data/db/migrate/20160928154410_create_versions.rb +4 -4
  71. data/db/migrate/20160928161623_create_tang_stripe_webhooks.rb +1 -1
  72. data/db/migrate/20160928173328_create_tang_plans.rb +1 -1
  73. data/db/migrate/20160929152510_create_tang_coupons.rb +1 -1
  74. data/db/migrate/20160929152541_add_customer_fields.rb +1 -1
  75. data/db/migrate/20160929171640_create_tang_subscriptions.rb +2 -2
  76. data/db/migrate/20160929174251_create_tang_cards.rb +1 -1
  77. data/db/migrate/20161003035434_create_tang_invoices.rb +1 -1
  78. data/db/migrate/20161114181651_create_tang_invoice_items.rb +1 -1
  79. data/db/migrate/20161115201106_create_tang_charges.rb +1 -1
  80. data/db/migrate/20170523122759_add_group_to_plans.rb +1 -1
  81. data/db/migrate/20170701162853_add_stripe_indexes.rb +1 -1
  82. data/db/migrate/20170731010913_add_subscription_indexes.rb +1 -1
  83. data/db/migrate/20200827001523_add_invoice_pdf_to_invoices.rb +1 -1
  84. data/db/migrate/20230530172604_add_enable_customer_emails.rb +6 -0
  85. data/lib/generators/tang/install_generator.rb +1 -1
  86. data/lib/generators/templates/create_tang.rb +2 -2
  87. data/lib/tang/engine.rb +1 -1
  88. data/lib/tang/version.rb +1 -1
  89. data/lib/tang.rb +6 -6
  90. data/lib/tasks/cucumber.rake +50 -51
  91. data/lib/tasks/tang_tasks.rake +3 -3
  92. metadata +42 -30
@@ -1,9 +1,7 @@
1
1
  module Tang
2
2
  class UpdateCoupon
3
3
  def self.call(coupon)
4
- if !coupon.valid?
5
- return coupon
6
- end
4
+ return coupon unless coupon.valid?
7
5
 
8
6
  begin
9
7
  c = Stripe::Coupon.retrieve(coupon.stripe_id)
@@ -13,7 +11,7 @@ module Tang
13
11
  coupon.errors.add(:base, :invalid, message: e.message)
14
12
  end
15
13
 
16
- return coupon
14
+ coupon
17
15
  end
18
16
  end
19
- end
17
+ end
@@ -1,7 +1,7 @@
1
1
  module Tang
2
2
  class UpdateCustomer
3
3
  def self.call(customer)
4
- return customer if !customer.valid?
4
+ return customer unless customer.valid?
5
5
 
6
6
  if customer.stripe_id.present?
7
7
  begin
@@ -13,7 +13,7 @@ module Tang
13
13
  end
14
14
  end
15
15
 
16
- return customer
16
+ customer
17
17
  end
18
18
 
19
19
  def self.populate_customer(stripe_customer, customer)
@@ -22,7 +22,7 @@ module Tang
22
22
  stripe_customer.business_vat_id = customer.business_vat_id if customer.business_vat_id.present?
23
23
  stripe_customer.description = customer.description
24
24
  stripe_customer.coupon = customer.coupon.stripe_id if customer.coupon.present?
25
- return stripe_customer
25
+ stripe_customer
26
26
  end
27
27
  end
28
- end
28
+ end
@@ -1,9 +1,7 @@
1
1
  module Tang
2
2
  class UpdatePlan
3
3
  def self.call(plan)
4
- if !plan.valid?
5
- return plan
6
- end
4
+ return plan unless plan.valid?
7
5
 
8
6
  begin
9
7
  p = Stripe::Plan.retrieve(plan.stripe_id)
@@ -13,7 +11,7 @@ module Tang
13
11
  plan.errors.add(:base, :invalid, message: e.message)
14
12
  end
15
13
 
16
- return plan
14
+ plan
17
15
  end
18
16
  end
19
- end
17
+ end
@@ -1,9 +1,7 @@
1
1
  module Tang
2
2
  class UpdateSubscription
3
3
  def self.call(subscription)
4
- if !subscription.valid?
5
- return subscription
6
- end
4
+ return subscription unless subscription.valid?
7
5
 
8
6
  begin
9
7
  s = Stripe::Subscription.retrieve(subscription.stripe_id)
@@ -17,7 +15,7 @@ module Tang
17
15
  subscription.errors.add(:base, :invalid, message: e.message)
18
16
  end
19
17
 
20
- return subscription
18
+ subscription
21
19
  end
22
20
  end
23
- end
21
+ end
@@ -1,7 +1,7 @@
1
1
  class FutureValidator < ActiveModel::EachValidator
2
2
  def validate_each(record, attribute, _value)
3
- if record[attribute] < Time.now
4
- record.errors.add(attribute, :invalid, message: (options[:message] || "must be in the future."))
5
- end
3
+ return unless record[attribute] < Time.now
4
+
5
+ record.errors.add(attribute, :invalid, message: (options[:message] || 'must be in the future.'))
6
6
  end
7
- end
7
+ end
@@ -15,6 +15,6 @@
15
15
 
16
16
  <%= link_to 'Use a new card', new_account_card_path, class: 'btn btn-secondary' %>
17
17
  <% if @can_delete_card %>
18
- <%= link_to 'Remove card', account_card_path, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger' %>
18
+ <%= link_to 'Remove card', account_card_path, method: :delete, data: { confirm: 'Are you sure?', turbo_confirm: 'Are you sure?', turbo_method: :delete }, class: 'btn btn-danger' %>
19
19
  <% end %>
20
20
  <%= link_to 'Cancel', account_subscription_path, class: 'btn btn-secondary' %>
@@ -1,6 +1,6 @@
1
1
  <li class="list-group-item">
2
2
  <div class="float-xs-right">
3
- <%= link_to 'Download PDF', invoice.invoice_pdf, class: 'btn btn-secondary', target: '_blank' %>
3
+ <%= link_to 'Download PDF', download_account_receipt_path(invoice) %>
4
4
  </div>
5
5
  <h5 class="list-group-item-heading"><%= number_to_currency(invoice.total.to_f / 100.0) %></h5>
6
6
  <p class="list-group-item-text">Date <%= invoice.date.strftime('%b %d, %Y') %></p>
@@ -3,6 +3,17 @@
3
3
 
4
4
  <% if @subscription.present? %>
5
5
 
6
+ <% if @subscription.errors.any? %>
7
+ <div id="error_explanation" class="alert alert-danger">
8
+ <h4 class="alert-heading"><%= pluralize(@subscription.errors.count, "error") %> prohibited this subscription from being saved:</h4>
9
+ <ul class="mb-0">
10
+ <% @subscription.errors.full_messages.each do |message| %>
11
+ <li><%= message %></li>
12
+ <% end %>
13
+ </ul>
14
+ </div>
15
+ <% end %>
16
+
6
17
  <% if @next_plan.present? %>
7
18
  <div class="alert alert-info">
8
19
  <h4 class="alert-heading">Upgrade to the <%= @next_plan.name %> Plan</h4>
@@ -34,7 +45,7 @@
34
45
  <%= link_to 'Downgrade', account_subscription_path(plan: @previous_plan), method: :patch, class: 'btn btn-secondary' %>
35
46
  <% end %>
36
47
 
37
- <%= link_to 'Cancel Plan', account_subscription_path, method: :delete, data: { confirm: 'Are you sure you want to cancel your current plan?' }, class: 'btn btn-secondary' %>
48
+ <%= link_to 'Cancel Plan', account_subscription_path, method: :delete, data: { confirm: 'Are you sure you want to cancel your current plan?', turbo_confirm: 'Are you sure you want to cancel your current plan?', turbo_method: :delete }, class: 'btn btn-secondary' %>
38
49
  </div>
39
50
 
40
51
  <br>
@@ -95,7 +106,7 @@
95
106
  <% if current_customer.subscription.coupon.present? %>
96
107
  <h4>Discount</h4>
97
108
  <p><%= "#{current_customer.subscription.coupon.stripe_id} - #{coupon_off(current_customer.subscription.coupon)} #{current_customer.subscription.coupon.formatted_duration}" %></p>
98
- <%= link_to 'Remove discount', account_coupon_path, method: :delete, class: 'btn btn-danger' %>
109
+ <%= link_to 'Remove discount', account_coupon_path, data: { turbo_method: :delete }, method: :delete, class: 'btn btn-danger' %>
99
110
  <% else %>
100
111
  <h4>Redeem coupon</h4>
101
112
  <%= form_for current_customer.subscription.build_coupon, url: tang.account_coupon_path, html: { class: 'form-inline' } do |f| %>
@@ -110,7 +121,7 @@
110
121
  <% if current_customer.subscription_coupon.present? %>
111
122
  <h4>Discount</h4>
112
123
  <p><%= "#{current_customer.subscription_coupon.stripe_id} - #{coupon_off(current_customer.subscription_coupon)} #{current_customer.subscription_coupon.formatted_duration}" %></p>
113
- <%= link_to 'Remove discount', account_coupon_path, method: :delete, class: 'btn btn-danger' %>
124
+ <%= link_to 'Remove discount', account_coupon_path, data: { turbo_method: :delete }, method: :delete, class: 'btn btn-danger' %>
114
125
  <% else %>
115
126
  <h4>Redeem coupon</h4>
116
127
  <%= form_for current_customer.build_subscription_coupon, url: tang.account_coupon_path, html: { class: 'form-inline' } do |f| %>
@@ -60,6 +60,6 @@
60
60
  </div>
61
61
 
62
62
  <hr>
63
- <%= link_to 'Delete Coupon', tang.admin_coupon_path(@coupon), method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger float-md-right' %>
63
+ <%= link_to 'Delete Coupon', tang.admin_coupon_path(@coupon), method: :delete, data: { confirm: 'Are you sure?', turbo_confirm: 'Are you sure?', turbo_method: :delete }, class: 'btn btn-danger float-md-right' %>
64
64
 
65
65
  <%= render 'footer' %>
@@ -130,7 +130,7 @@
130
130
  <%= link_to 'Change Coupon', tang.admin_customer_coupon_path(@customer), class: 'nav-link' %>
131
131
  </li>
132
132
  <li class="nav-item">
133
- <%= link_to 'Remove Coupon', tang.admin_customer_coupon_path(@customer), method: :delete, data: { confirm: 'Are you sure?' }, class: 'nav-link' %>
133
+ <%= link_to 'Remove Coupon', tang.admin_customer_coupon_path(@customer), method: :delete, data: { confirm: 'Are you sure?', turbo_confirm: 'Are you sure?', turbo_method: :delete }, class: 'nav-link' %>
134
134
  </li>
135
135
  <% else %>
136
136
  <li class="nav-item">
@@ -152,6 +152,6 @@
152
152
 
153
153
  <hr>
154
154
 
155
- <p><%= link_to 'Delete Customer', tang.admin_customer_path(@customer), method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger float-md-right' %></p>
155
+ <p><%= link_to 'Delete Customer', tang.admin_customer_path(@customer), method: :delete, data: { confirm: 'Are you sure?', turbo_confirm: 'Are you sure?', turbo_method: :delete }, class: 'btn btn-danger float-md-right' %></p>
156
156
 
157
157
  <%= render 'footer' %>
@@ -58,6 +58,6 @@
58
58
  </div>
59
59
 
60
60
  <hr>
61
- <%= link_to 'Delete Plan', tang.admin_plan_path(@plan), method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger float-md-right' %>
61
+ <%= link_to 'Delete Plan', tang.admin_plan_path(@plan), method: :delete, data: { confirm: 'Are you sure?', turbo_confirm: 'Are you sure?', turbo_method: :delete }, class: 'btn btn-danger float-md-right' %>
62
62
 
63
63
  <%= render 'footer' %>
@@ -48,7 +48,7 @@
48
48
  <%= link_to 'Change Coupon', tang.admin_subscription_coupon_path(@subscription), class: 'nav-link' %>
49
49
  </li>
50
50
  <li class="nav-item">
51
- <%= link_to 'Remove Coupon', tang.admin_subscription_coupon_path(@subscription), method: :delete, data: { confirm: 'Are you sure?' }, class: 'nav-link' %>
51
+ <%= link_to 'Remove Coupon', tang.admin_subscription_coupon_path(@subscription), method: :delete, data: { confirm: 'Are you sure?', turbo_confirm: 'Are you sure?', turbo_method: :delete }, class: 'nav-link' %>
52
52
  </li>
53
53
  <% else %>
54
54
  <li class="nav-item">
@@ -69,6 +69,6 @@
69
69
  </div>
70
70
 
71
71
  <hr>
72
- <p><%= link_to 'Cancel Subscription', tang.admin_subscription_path(@subscription), method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger float-md-right' %></p>
72
+ <p><%= link_to 'Cancel Subscription', tang.admin_subscription_path(@subscription), method: :delete, data: { confirm: 'Are you sure?', turbo_confirm: 'Are you sure?', turbo_method: :delete }, class: 'btn btn-danger float-md-right' %></p>
73
73
 
74
74
  <%= render 'footer' %>
@@ -11,7 +11,7 @@
11
11
  <% if user_signed_in? %>
12
12
  <% if current_user.subscription.present? %>
13
13
  <% # downgrade to free %>
14
- <%= link_to 'Choose Plan', account_subscription_path, method: :delete, data: { confirm: 'Are you sure you want to cancel your current plan?' }, class: 'pricing__action' %>
14
+ <%= link_to 'Choose Plan', account_subscription_path, method: :delete, data: { confirm: 'Are you sure you want to cancel your current plan?', turbo_confirm: 'Are you sure you want to cancel your current plan?', turbo_method: :delete }, class: 'pricing__action' %>
15
15
  <% else %>
16
16
  <% # already on free plan %>
17
17
  <%= button_tag 'Selected', class: 'pricing__action', disabled: 'disabled' %>
@@ -1,2 +1,2 @@
1
- Stripe.api_key = ENV['STRIPE_SECRET_KEY']
2
- StripeEvent.signing_secret = ENV['STRIPE_SIGNING_SECRET']
1
+ Stripe.api_key = ENV.fetch('STRIPE_SECRET_KEY', nil)
2
+ StripeEvent.signing_secret = ENV.fetch('STRIPE_SIGNING_SECRET', nil)
@@ -1,14 +1,11 @@
1
1
  StripeEvent.event_filter = lambda do |params|
2
- # return nil if Rails.env.production? && !params[:livemode]
3
2
  return nil if Tang::StripeWebhook.exists?(stripe_id: params[:id])
3
+
4
4
  Tang::StripeWebhook.create!(stripe_id: params[:id])
5
5
  Stripe::Event.retrieve(params[:id])
6
6
  end
7
7
 
8
8
  StripeEvent.configure do |events|
9
- events.all do |event|
10
- end
11
-
12
9
  # Disputes
13
10
 
14
11
  events.subscribe 'charge.dispute.created' do |event|
@@ -22,36 +19,38 @@ StripeEvent.configure do |events|
22
19
  end
23
20
  end
24
21
 
25
- events.subscribe 'charge.dispute.updated' do |event|
26
- dispute = event.data.object
27
- end
22
+ # events.subscribe 'charge.dispute.updated' do |event|
23
+ # dispute = event.data.object
24
+ # end
28
25
 
29
- events.subscribe 'charge.dispute.closed' do |event|
30
- dispute = event.data.object
31
- end
26
+ # events.subscribe 'charge.dispute.closed' do |event|
27
+ # dispute = event.data.object
28
+ # end
32
29
 
33
30
  # Subscription lifecycle
34
31
 
35
32
  events.subscribe 'invoice.created' do |event|
36
- invoice = Tang::CreateInvoice.call(event)
33
+ Tang::CreateInvoice.call(event)
37
34
  end
38
35
 
39
- # events.subscribe 'charge.succeeded' do |event|
40
- # charge = event.data.object
41
- # StripeMailer.receipt(charge).deliver
42
- # StripeMailer.admin_charge_succeeded(charge).deliver
43
- # end
44
-
45
36
  events.subscribe('invoice.payment_succeeded') do |event|
46
37
  invoice = event.data.object
47
38
  charge = Tang::PayInvoice.call(invoice)
48
39
  if charge.present?
49
- if Tang.delayed_email
50
- Tang::StripeMailer.customer_payment_succeeded(charge).deliver_later
51
- Tang::StripeMailer.admin_payment_succeeded(charge).deliver_later
52
- else
53
- Tang::StripeMailer.customer_payment_succeeded(charge).deliver_now
54
- Tang::StripeMailer.admin_payment_succeeded(charge).deliver_now
40
+ if charge.customer.present? && charge.customer.customer_payment_success_emails_enabled
41
+ if Tang.delayed_email
42
+ Tang::StripeMailer.customer_payment_succeeded(charge).deliver_later
43
+ else
44
+ Tang::StripeMailer.customer_payment_succeeded(charge).deliver_now
45
+ end
46
+ end
47
+
48
+ if Tang.admin_payment_succeeded_enabled
49
+ if Tang.delayed_email
50
+ Tang::StripeMailer.admin_payment_succeeded(charge).deliver_later
51
+ else
52
+ Tang::StripeMailer.admin_payment_succeeded(charge).deliver_now
53
+ end
55
54
  end
56
55
  end
57
56
  end
@@ -62,12 +61,20 @@ StripeEvent.configure do |events|
62
61
  invoice = event.data.object
63
62
  charge = Tang::FailInvoice.call(invoice)
64
63
  if charge.present?
65
- if Tang.delayed_email
66
- Tang::StripeMailer.customer_payment_failed(charge).deliver_later
67
- Tang::StripeMailer.admin_payment_failed(charge).deliver_later
68
- else
69
- Tang::StripeMailer.customer_payment_failed(charge).deliver_now
70
- Tang::StripeMailer.admin_payment_failed(charge).deliver_now
64
+ if charge.customer.present? && charge.customer.customer_payment_failed_emails_enabled
65
+ if Tang.delayed_email
66
+ Tang::StripeMailer.customer_payment_failed(charge).deliver_later
67
+ else
68
+ Tang::StripeMailer.customer_payment_failed(charge).deliver_now
69
+ end
70
+ end
71
+
72
+ if Tang.admin_payment_failed_enabled
73
+ if Tang.delayed_email
74
+ Tang::StripeMailer.admin_payment_failed(charge).deliver_later
75
+ else
76
+ Tang::StripeMailer.admin_payment_failed(charge).deliver_now
77
+ end
71
78
  end
72
79
  end
73
80
  end
@@ -78,8 +85,6 @@ StripeEvent.configure do |events|
78
85
  events.subscribe('customer.subscription.deleted') do |event|
79
86
  stripe_subscription = event.data.object
80
87
  subscription = Tang::Subscription.find_by(stripe_id: stripe_subscription.id)
81
- if subscription.present?
82
- subscription.cancel! if !subscription.canceled?
83
- end
88
+ subscription.cancel! if subscription.present? && !subscription.canceled?
84
89
  end
85
- end
90
+ end
data/config/routes.rb CHANGED
@@ -26,7 +26,9 @@ Tang::Engine.routes.draw do
26
26
  resource :subscription
27
27
  resource :card, only: [:show, :new, :create, :update, :destroy]
28
28
  resource :coupon, only: [:create, :destroy]
29
- resources :receipts, only: [:index]
29
+ resources :receipts, only: [:index] do
30
+ get :download, on: :member
31
+ end
30
32
  end
31
33
 
32
34
  # get 'pricing', to: 'plans#index'
@@ -1,12 +1,12 @@
1
1
  # This migration creates the `versions` table, the only schema PT requires.
2
2
  # All other migrations PT provides are optional.
3
- class CreateVersions < ActiveRecord::Migration
3
+ class CreateVersions < ActiveRecord::Migration[4.2]
4
4
  # Class names of MySQL adapters.
5
5
  # - `MysqlAdapter` - Used by gems: `mysql`, `activerecord-jdbcmysql-adapter`.
6
6
  # - `Mysql2Adapter` - Used by `mysql2` gem.
7
7
  MYSQL_ADAPTERS = [
8
- "ActiveRecord::ConnectionAdapters::MysqlAdapter",
9
- "ActiveRecord::ConnectionAdapters::Mysql2Adapter"
8
+ 'ActiveRecord::ConnectionAdapters::MysqlAdapter',
9
+ 'ActiveRecord::ConnectionAdapters::Mysql2Adapter'
10
10
  ].freeze
11
11
 
12
12
  # The largest text column available in all supported RDBMS is
@@ -72,7 +72,7 @@ class CreateVersions < ActiveRecord::Migration
72
72
  #
73
73
  def versions_table_options
74
74
  if mysql?
75
- { options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci" }
75
+ { options: 'ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci' }
76
76
  else
77
77
  {}
78
78
  end
@@ -1,4 +1,4 @@
1
- class CreateTangStripeWebhooks < ActiveRecord::Migration
1
+ class CreateTangStripeWebhooks < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  create_table :tang_stripe_webhooks do |t|
4
4
  t.string :stripe_id
@@ -1,4 +1,4 @@
1
- class CreateTangPlans < ActiveRecord::Migration
1
+ class CreateTangPlans < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  create_table :tang_plans do |t|
4
4
  t.string :stripe_id
@@ -1,4 +1,4 @@
1
- class CreateTangCoupons < ActiveRecord::Migration
1
+ class CreateTangCoupons < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  create_table :tang_coupons do |t|
4
4
  t.string :stripe_id
@@ -1,4 +1,4 @@
1
- class AddCustomerFields < ActiveRecord::Migration
1
+ class AddCustomerFields < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  add_column Tang.customer_class.to_s.downcase.pluralize, :stripe_id, :string
4
4
  add_column Tang.customer_class.to_s.downcase.pluralize, :account_balance, :integer
@@ -1,4 +1,4 @@
1
- class CreateTangSubscriptions < ActiveRecord::Migration
1
+ class CreateTangSubscriptions < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  create_table :tang_subscriptions do |t|
4
4
  t.string :stripe_id
@@ -14,7 +14,7 @@ class CreateTangSubscriptions < ActiveRecord::Migration
14
14
  t.timestamp :coupon_start
15
15
 
16
16
  t.string :status
17
-
17
+
18
18
  t.timestamps null: false
19
19
  end
20
20
  end
@@ -1,4 +1,4 @@
1
- class CreateTangCards < ActiveRecord::Migration
1
+ class CreateTangCards < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  create_table :tang_cards do |t|
4
4
  t.integer :customer_id, index: true
@@ -1,4 +1,4 @@
1
- class CreateTangInvoices < ActiveRecord::Migration
1
+ class CreateTangInvoices < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  create_table :tang_invoices do |t|
4
4
  t.string :stripe_id
@@ -1,4 +1,4 @@
1
- class CreateTangInvoiceItems < ActiveRecord::Migration
1
+ class CreateTangInvoiceItems < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  create_table :tang_invoice_items do |t|
4
4
  t.string :stripe_id
@@ -1,4 +1,4 @@
1
- class CreateTangCharges < ActiveRecord::Migration
1
+ class CreateTangCharges < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  create_table :tang_charges do |t|
4
4
  t.string :stripe_id
@@ -1,4 +1,4 @@
1
- class AddGroupToPlans < ActiveRecord::Migration
1
+ class AddGroupToPlans < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  add_column :tang_plans, :group, :integer
4
4
  end
@@ -1,4 +1,4 @@
1
- class AddStripeIndexes < ActiveRecord::Migration
1
+ class AddStripeIndexes < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  add_index Tang.customer_class.to_s.downcase.pluralize, :stripe_id, unique: true
4
4
  add_index :tang_cards, :stripe_id, unique: true
@@ -1,4 +1,4 @@
1
- class AddSubscriptionIndexes < ActiveRecord::Migration
1
+ class AddSubscriptionIndexes < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  add_index :tang_subscriptions, [:customer_id, :created_at], where: "status != 'canceled'", name: 'index_tang_subscriptions_on_customer_and_created_at_and_status'
4
4
  end
@@ -1,4 +1,4 @@
1
- class AddInvoicePdfToInvoices < ActiveRecord::Migration
1
+ class AddInvoicePdfToInvoices < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  add_column :tang_invoices, :invoice_pdf, :string
4
4
  end
@@ -0,0 +1,6 @@
1
+ class AddEnableCustomerEmails < ActiveRecord::Migration[6.1]
2
+ def change
3
+ add_column Tang.customer_class.to_s.downcase.pluralize, :customer_payment_success_emails_enabled, :boolean, null: false, default: true
4
+ add_column Tang.customer_class.to_s.downcase.pluralize, :customer_payment_failed_emails_enabled, :boolean, null: false, default: true
5
+ end
6
+ end
@@ -19,4 +19,4 @@ module Tang
19
19
  end
20
20
  end
21
21
  end
22
- end
22
+ end
@@ -81,7 +81,7 @@ class CreateTang < ActiveRecord::Migration
81
81
  t.timestamp :coupon_start
82
82
 
83
83
  t.string :status
84
-
84
+
85
85
  t.timestamps null: false
86
86
  end
87
87
  end
@@ -192,4 +192,4 @@ class CreateTang < ActiveRecord::Migration
192
192
  t.timestamps null: false
193
193
  end
194
194
  end
195
- end
195
+ end
data/lib/tang/engine.rb CHANGED
@@ -13,7 +13,7 @@ module Tang
13
13
  end
14
14
 
15
15
  config.to_prepare do
16
- Rails.application.config.assets.precompile += %w( tang/pdf.css )
16
+ Rails.application.config.assets.precompile += %w[tang/pdf.css]
17
17
  end
18
18
  end
19
19
  end
data/lib/tang/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tang
2
- VERSION = "0.2.2"
2
+ VERSION = '0.2.4'.freeze
3
3
  end
data/lib/tang.rb CHANGED
@@ -1,9 +1,5 @@
1
- require "tang/engine"
2
- # require 'jquery-rails'
3
- # require 'bootstrap'
4
- # require 'rails-assets-tether'
1
+ require 'tang/engine'
5
2
  require 'will_paginate'
6
- # require 'paranoia'
7
3
 
8
4
  module Tang
9
5
  @@customer_class = 'User'
@@ -17,6 +13,8 @@ module Tang
17
13
  mattr_accessor :admin_layout
18
14
  mattr_accessor :pricing_layout
19
15
  mattr_accessor :delayed_email
16
+ mattr_accessor :admin_payment_succeeded_enabled
17
+ mattr_accessor :admin_payment_failed_enabled
20
18
 
21
19
  class << self
22
20
  Tang.default_currency = 'usd'
@@ -28,9 +26,11 @@ module Tang
28
26
  Tang.admin_layout = 'application'
29
27
  Tang.pricing_layout = 'application'
30
28
  Tang.delayed_email = false
29
+ Tang.admin_payment_succeeded_enabled = true
30
+ Tang.admin_payment_failed_enabled = true
31
31
  end
32
32
 
33
- def self.setup #(&block)
33
+ def self.setup
34
34
  yield self
35
35
  end
36
36