-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAllowedRegionsService.kts
41 lines (34 loc) · 1.45 KB
/
AllowedRegionsService.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import arrow.core.Either
import arrow.core.right
import org.ostelco.prime.model.Customer
import org.ostelco.prime.storage.StoreError
import org.ostelco.prime.storage.graph.AllowedRegionsService
import org.ostelco.prime.storage.graph.PrimeTransaction
object : AllowedRegionsService {
override fun get(customer: Customer, transaction: PrimeTransaction): Either<StoreError, Collection<String>> {
val allowedRegions = setOf(
"sg",
"my",
"no".takeIf {
isEmailAllowed(
customerEmail = customer.contactEmail.toLowerCase(),
allowedEmails = setOf(
"[email protected]" // <- Obviously a fake
),
allowedEmailSuffixes = setOf(
"@oya.sg",
"@oya.world",
"@redotter.sg",
"@redotter.world"
)
)
}
).filterNotNull()
return allowedRegions.right()
}
private fun isEmailAllowed(
customerEmail: String,
allowedEmails: Set<String>,
allowedEmailSuffixes: Set<String>
): Boolean = allowedEmailSuffixes.any { customerEmail.endsWith(it) } || allowedEmails.contains(customerEmail)
}