-
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'stripe-prices-refactor' into develop
- Loading branch information
Showing
34 changed files
with
724 additions
and
418 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 0 additions & 17 deletions
17
app/controllers/concerns/alaveteli_pro/stripe_namespace.rb
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,7 @@ | ||
module AlaveteliPro::AccountHelper | ||
def billing_frequency(billing_unit) | ||
case billing_unit | ||
when 'day' | ||
_('Billed: Daily') | ||
when 'week' | ||
_('Billed: Weekly') | ||
when 'month' | ||
_('Billed: Monthly') | ||
when 'year' | ||
_('Billed: Annually') | ||
end | ||
end | ||
|
||
def card_expiry_message(month, year) | ||
if month == Date.today.month && year == Date.today.year | ||
content_tag(:p, _('Expires soon'), class: 'card__expiring') | ||
end | ||
end | ||
|
||
def subscription_amount(subscription) | ||
AlaveteliPro::WithTax.new(subscription).amount_with_tax | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
## | ||
# Helper methods for formatting and displaying billing and plan information | ||
# in the Alaveteli Pro interface | ||
# | ||
module AlaveteliPro::PlanHelper | ||
def billing_frequency(plan) | ||
if interval(plan) == 'day' && interval_count(plan) == 1 | ||
_('Billed: Daily') | ||
elsif interval(plan) == 'week' && interval_count(plan) == 1 | ||
_('Billed: Weekly') | ||
elsif interval(plan) == 'month' && interval_count(plan) == 1 | ||
_('Billed: Monthly') | ||
elsif interval(plan) == 'year' && interval_count(plan) == 1 | ||
_('Billed: Annually') | ||
else | ||
_('Billed: every {{interval}}', interval: pluralize_interval(plan)) | ||
end | ||
end | ||
|
||
def billing_interval(plan) | ||
if interval_count(plan) == 1 | ||
_('per user, per {{interval}}', interval: interval(plan)) | ||
else | ||
_('per user, every {{interval}}', interval: pluralize_interval(plan)) | ||
end | ||
end | ||
|
||
private | ||
|
||
def pluralize_interval(plan) | ||
count = interval_count(plan) | ||
interval = interval(plan) | ||
return interval if count == 1 | ||
|
||
pluralize(count, interval) | ||
end | ||
|
||
def interval(plan) | ||
plan.interval | ||
end | ||
|
||
def interval_count(plan) | ||
plan.interval_count | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
## | ||
# A wrapper for a Stripe::Coupon | ||
# | ||
class AlaveteliPro::Coupon < SimpleDelegator | ||
extend AlaveteliPro::StripeNamespace | ||
include AlaveteliPro::StripeNamespace | ||
|
||
def self.referral | ||
id = add_stripe_namespace(AlaveteliConfiguration.pro_referral_coupon) | ||
retrieve(id) if id | ||
end | ||
|
||
def self.retrieve(id) | ||
new(Stripe::Coupon.retrieve(add_stripe_namespace(id))) | ||
rescue Stripe::InvalidRequestError | ||
nil | ||
end | ||
|
||
def to_param | ||
remove_stripe_namespace(id) | ||
end | ||
|
||
def terms | ||
metadata.humanized_terms || name | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
## | ||
# A wrapper for a Stripe::Customer | ||
# | ||
class AlaveteliPro::Customer < SimpleDelegator | ||
def self.retrieve(id) | ||
new(Stripe::Customer.retrieve(id)) | ||
end | ||
|
||
def default_source | ||
@default_source ||= sources.find { |c| c.id == __getobj__.default_source } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
## | ||
# A wrapper for a Stripe::Plan | ||
# | ||
class AlaveteliPro::Plan < SimpleDelegator | ||
extend AlaveteliPro::StripeNamespace | ||
include AlaveteliPro::StripeNamespace | ||
include Taxable | ||
|
||
tax :amount | ||
|
||
def self.list | ||
[retrieve('pro')] | ||
end | ||
|
||
def self.retrieve(id) | ||
new(Stripe::Plan.retrieve(add_stripe_namespace(id))) | ||
rescue Stripe::InvalidRequestError | ||
nil | ||
end | ||
|
||
def to_param | ||
remove_stripe_namespace(id) | ||
end | ||
|
||
# product | ||
def product | ||
@product ||= ( | ||
product_id = __getobj__.product | ||
Stripe::Product.retrieve(product_id) if product_id | ||
) | ||
end | ||
end |
Oops, something went wrong.