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

[FEATURE] [MER-3782] no payment feature #5340

Open
wants to merge 3 commits into
base: master
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
40 changes: 23 additions & 17 deletions lib/oli/delivery/paywall.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ defmodule Oli.Delivery.Paywall do

def summarize_access(
%User{id: id} = user,
%Section{slug: slug, requires_payment: true} = section
%Section{slug: slug, requires_payment: true, amount: amount} = section
) do
if Sections.is_instructor?(user, slug) or Sections.is_admin?(user, slug) do
AccessSummary.instructor()
Expand All @@ -45,19 +45,19 @@ defmodule Oli.Delivery.Paywall do
if section.pay_by_institution do
AccessSummary.pay_by_institution()
else
case has_paid?(enrollment) do
true ->
if has_zero_cost?(amount) do
AccessSummary.has_zero_cost()
else
if has_paid?(enrollment) do
AccessSummary.paid()

_ ->
case within_grace_period?(enrollment, section) do
true ->
grace_period_seconds_remaining(enrollment, section)
|> AccessSummary.within_grace()

_ ->
AccessSummary.not_paid()
else
if within_grace_period?(enrollment, section) do
grace_period_seconds_remaining(enrollment, section)
|> AccessSummary.within_grace()
else
AccessSummary.not_paid()
end
end
end
end
end
Expand All @@ -69,7 +69,7 @@ defmodule Oli.Delivery.Paywall do

def summarize_access(
%User{} = user,
%Section{slug: slug, requires_payment: true} = section,
%Section{slug: slug, requires_payment: true, amount: amount} = section,
user_role_id,
enrollment,
payment
Expand All @@ -90,13 +90,15 @@ defmodule Oli.Delivery.Paywall do
AccessSummary.paid()

_ ->
case within_grace_period?(enrollment, section) do
true ->
if has_zero_cost?(amount) do
AccessSummary.has_zero_cost()
else
if within_grace_period?(enrollment, section) do
grace_period_seconds_remaining(enrollment, section)
|> AccessSummary.within_grace()

_ ->
else
AccessSummary.not_paid()
end
end
end
end
Expand All @@ -120,6 +122,10 @@ defmodule Oli.Delivery.Paywall do
end
end

defp has_zero_cost?(nil), do: true

defp has_zero_cost?(amount), do: Money.zero?(amount)

defp within_grace_period?(nil, _), do: false

defp within_grace_period?(_, %Section{has_grace_period: false}), do: false
Expand Down
8 changes: 8 additions & 0 deletions lib/oli/delivery/paywall/access_summary.ex
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,12 @@ defmodule Oli.Delivery.Paywall.AccessSummary do
grace_period_remaining: nil
}
end

def has_zero_cost() do
%AccessSummary{
available: true,
reason: :has_zero_cost,
grace_period_remaining: nil
}
end
end
Loading