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

Allow credit card updates based on subscription state #1567

Merged
merged 2 commits into from
Oct 3, 2024
Merged
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
4 changes: 2 additions & 2 deletions apps/kort/src/Components/Subscription.purs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Data.Maybe (Maybe(..))
import Data.Nullable (toMaybe)
import Data.Tuple (Tuple(..))
import KSF.Api.Subscription (toString) as Subsno
import KSF.Api.Subscription (isSubscriptionExpired)
import KSF.Api.Subscription (isSubscriptionExpired, isSubscriptionRenewable)
import KSF.DescriptionList as DescriptionList
import KSF.Grid as Grid
import KSF.User as User
Expand Down Expand Up @@ -79,5 +79,5 @@ render self@{ props: { now, subscription: sub } } informationColumn =
, id: "subscription-" <> subsno
}
where
expired = isSubscriptionExpired sub now
expired = isSubscriptionExpired sub now && not (isSubscriptionRenewable sub)
subsno = Subsno.toString sub.subsno
2 changes: 1 addition & 1 deletion ci/Prelude.dhall
Original file line number Diff line number Diff line change
@@ -1 +1 @@
https://prelude.dhall-lang.org/v18.0.0/package.dhall sha256:2086c6a2e7ce8ee371858036ab60d24d045969defadb4bc9d87639921ec2e028
https://raw.githubusercontent.com/dhall-lang/dhall-lang/v18.0.0/Prelude/package.dhall sha256:2086c6a2e7ce8ee371858036ab60d24d045969defadb4bc9d87639921ec2e028
10 changes: 10 additions & 0 deletions packages/components/src/Api/Subscription.purs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Bottega.Models.PaymentMethod (PaymentMethodId)
import Control.Alt ((<|>))
import Data.Date (Date)
import Data.Either (Either(..))
import Data.Foldable (elem)
import Data.Generic.Rep (class Generic)
import Data.Int as Int
import Data.JSDate (JSDate, toDate)
Expand Down Expand Up @@ -146,3 +147,12 @@ isSubscriptionExpired subs today =
let end = toDate =<< toMaybe subs.dates.end
suspend = toDate =<< toMaybe subs.dates.suspend
in maybe false (_ < today) end || maybe false (_ <= today) suspend

-- Can the payment card be changed
isSubscriptionRenewable :: Subscription -> Boolean
isSubscriptionRenewable subs =
(\(SubscriptionState x) -> x) subs.state `elem`
[ "Active"
, "Paused"
, "RestartedAfterLatePayment"
]
Loading