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.
- checksums.yaml +4 -4
- data/Rakefile +3 -3
- data/app/controllers/tang/account/application_controller.rb +2 -4
- data/app/controllers/tang/account/cards_controller.rb +11 -8
- data/app/controllers/tang/account/coupons_controller.rb +1 -1
- data/app/controllers/tang/account/receipts_controller.rb +10 -4
- data/app/controllers/tang/account/subscriptions_controller.rb +11 -8
- data/app/controllers/tang/admin/application_controller.rb +4 -4
- data/app/controllers/tang/admin/coupons_controller.rb +18 -14
- data/app/controllers/tang/admin/customers_controller.rb +16 -16
- data/app/controllers/tang/admin/dashboard_controller.rb +1 -1
- data/app/controllers/tang/admin/invoices_controller.rb +6 -6
- data/app/controllers/tang/admin/payments_controller.rb +9 -9
- data/app/controllers/tang/admin/plans_controller.rb +21 -19
- data/app/controllers/tang/admin/search_controller.rb +15 -14
- data/app/controllers/tang/admin/subscriptions_controller.rb +16 -17
- data/app/controllers/tang/plans_controller.rb +1 -1
- data/app/helpers/tang/application_helper.rb +22 -28
- data/app/jobs/tang/import_charges_job.rb +4 -8
- data/app/jobs/tang/import_coupons_job.rb +3 -3
- data/app/jobs/tang/import_customers_job.rb +15 -13
- data/app/jobs/tang/import_invoices_job.rb +7 -7
- data/app/jobs/tang/import_plans_job.rb +4 -6
- data/app/jobs/tang/import_subscriptions_job.rb +4 -4
- data/app/mailers/application_mailer.rb +1 -1
- data/app/mailers/tang/stripe_mailer.rb +8 -9
- data/app/mailers/tang/subscription_mailer.rb +4 -1
- data/app/models/concerns/tang/customer.rb +32 -32
- data/app/models/tang/card.rb +7 -8
- data/app/models/tang/charge.rb +28 -50
- data/app/models/tang/coupon.rb +27 -25
- data/app/models/tang/invoice.rb +16 -17
- data/app/models/tang/invoice_item.rb +16 -18
- data/app/models/tang/plan.rb +31 -16
- data/app/models/tang/subscription.rb +34 -42
- data/app/services/tang/apply_customer_discount.rb +2 -2
- data/app/services/tang/apply_subscription_discount.rb +2 -2
- data/app/services/tang/cancel_subscription.rb +2 -2
- data/app/services/tang/change_subscription.rb +4 -4
- data/app/services/tang/create_coupon.rb +3 -5
- data/app/services/tang/create_invoice.rb +2 -2
- data/app/services/tang/create_plan.rb +9 -8
- data/app/services/tang/create_subscription.rb +18 -15
- data/app/services/tang/delete_card.rb +3 -3
- data/app/services/tang/delete_coupon.rb +3 -3
- data/app/services/tang/delete_customer.rb +2 -2
- data/app/services/tang/delete_plan.rb +2 -2
- data/app/services/tang/fail_invoice.rb +5 -6
- data/app/services/tang/pay_invoice.rb +2 -3
- data/app/services/tang/refresh_invoice_pdf.rb +9 -0
- data/app/services/tang/remove_customer_discount.rb +2 -2
- data/app/services/tang/remove_subscription_discount.rb +3 -3
- data/app/services/tang/save_card.rb +8 -9
- data/app/services/tang/update_coupon.rb +3 -5
- data/app/services/tang/update_customer.rb +4 -4
- data/app/services/tang/update_plan.rb +3 -5
- data/app/services/tang/update_subscription.rb +3 -5
- data/app/validators/future_validator.rb +4 -4
- data/app/views/tang/account/cards/show.html.erb +1 -1
- data/app/views/tang/account/receipts/_receipt.html.erb +1 -1
- data/app/views/tang/account/subscriptions/show.html.erb +14 -3
- data/app/views/tang/admin/coupons/show.html.erb +1 -1
- data/app/views/tang/admin/customers/show.html.erb +2 -2
- data/app/views/tang/admin/plans/show.html.erb +1 -1
- data/app/views/tang/admin/subscriptions/show.html.erb +2 -2
- data/app/views/tang/plans/index.html.erb +1 -1
- data/config/initializers/stripe.rb +2 -2
- data/config/initializers/stripe_event.rb +38 -33
- data/config/routes.rb +3 -1
- data/db/migrate/20160928154410_create_versions.rb +4 -4
- data/db/migrate/20160928161623_create_tang_stripe_webhooks.rb +1 -1
- data/db/migrate/20160928173328_create_tang_plans.rb +1 -1
- data/db/migrate/20160929152510_create_tang_coupons.rb +1 -1
- data/db/migrate/20160929152541_add_customer_fields.rb +1 -1
- data/db/migrate/20160929171640_create_tang_subscriptions.rb +2 -2
- data/db/migrate/20160929174251_create_tang_cards.rb +1 -1
- data/db/migrate/20161003035434_create_tang_invoices.rb +1 -1
- data/db/migrate/20161114181651_create_tang_invoice_items.rb +1 -1
- data/db/migrate/20161115201106_create_tang_charges.rb +1 -1
- data/db/migrate/20170523122759_add_group_to_plans.rb +1 -1
- data/db/migrate/20170701162853_add_stripe_indexes.rb +1 -1
- data/db/migrate/20170731010913_add_subscription_indexes.rb +1 -1
- data/db/migrate/20200827001523_add_invoice_pdf_to_invoices.rb +1 -1
- data/db/migrate/20230530172604_add_enable_customer_emails.rb +6 -0
- data/lib/generators/tang/install_generator.rb +1 -1
- data/lib/generators/templates/create_tang.rb +2 -2
- data/lib/tang/engine.rb +1 -1
- data/lib/tang/version.rb +1 -1
- data/lib/tang.rb +6 -6
- data/lib/tasks/cucumber.rake +50 -51
- data/lib/tasks/tang_tasks.rake +3 -3
- metadata +42 -30
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
module Tang
|
|
2
2
|
class UpdateCoupon
|
|
3
3
|
def self.call(coupon)
|
|
4
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
|
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
|
|
2
|
-
StripeEvent.signing_secret = ENV
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
50
|
-
Tang
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
|
66
|
-
Tang
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
9
|
-
|
|
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:
|
|
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 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 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
|
|
@@ -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
|
|
@@ -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
data/lib/tang/version.rb
CHANGED
data/lib/tang.rb
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
require
|
|
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
|
|
33
|
+
def self.setup
|
|
34
34
|
yield self
|
|
35
35
|
end
|
|
36
36
|
|