Vibescript Showcase
Refund decision
Make refund decisions with typed enums, money values, and Duration-based policy windows.
Source
showcase/policies/refund_decision.vibe
# title: Refund decision
# category: Vibescript Showcase
# difficulty: Showcase
# summary: Make refund decisions with typed enums, money values, and Duration-based policy windows.
# description: This example keeps policy logic readable by using domain types instead of raw numbers and strings everywhere.
# tags: policies, money, durations, enums
# featured: true
# feature_rank: 4
# vibe: 0.2
enum RefundDecision
Full
Partial
Denied
end
def refund_decision(age: duration, used: bool) -> RefundDecision
if age <= 7.days && !used
RefundDecision::Full
elsif age <= 30.days
RefundDecision::Partial
else
RefundDecision::Denied
end
end
def refund_amount(total: money, decision: RefundDecision) -> money
if decision == RefundDecision::Full
total
elsif decision == RefundDecision::Partial
total - money("15.00 USD")
else
money("0.00 USD")
end
end
def refund_quote(total: money, purchased_at: time, requested_at: time, used: bool) -> hash
age = requested_at - purchased_at
decision = refund_decision(age, used)
{
decision: decision.name,
age: age.iso8601,
used: used,
refund: refund_amount(total, decision)
}
end
def run
purchased_at = Time.at(1700000000)
{
full: refund_quote(money("89.00 USD"), purchased_at, 3.days.after(purchased_at), false),
partial: refund_quote(money("89.00 USD"), purchased_at, 14.days.after(purchased_at), true),
denied: refund_quote(money("89.00 USD"), purchased_at, 45.days.after(purchased_at), true)
}
end
Output
Press run to execute run from this example.