pyc-website

main website for pyc inc.

git clone https://9o.is/git/pyc-website.git

PurchaseLimitField.scala

(2276B)


      1 package inc.pyc
      2 package model
      3 package field
      4 
      5 import net.liftweb._
      6 import http._
      7 import util.Helpers._
      8 import record._
      9 import field._
     10 import json.JsonAST._
     11 import common._
     12 
     13 trait PurchaseLimit extends Enumeration
     14 
     15 /**
     16  * Purchase limit in the United States by dollars.
     17  * 
     18  * $1,000      - not verified
     19  * $3,000      - verified phone
     20  * $10,000     - verified identification
     21  * 
     22  * For more information, visit
     23  * http://www.fincen.gov/financial_institutions/msb/materials/en/bank_reference.html
     24  * 
     25  * Note, to change unlimited value, change `UserVerification` `userLimitAsString` value,
     26  * and /settings/purchase_limit.html
     27  */
     28 object USAPurchaseLimit extends PurchaseLimit {
     29 
     30   val D1k             = Value("$1,000")
     31   val D3k             = Value("$3,000")
     32   val D10k_?          = Value("$10,000 Pending")
     33   val D10k            = Value("$10,000")
     34   
     35   def options: List[(String, String)] =
     36     USAPurchaseLimit.values.map(i => (i.toString, i.toString)).toList
     37     
     38   def select(s: String) = tryo(USAPurchaseLimit.withName(s))  
     39 }
     40 
     41 /**
     42  * Purchase Limit field for records.
     43  */
     44 class USAPurchaseLimitField[OwnerType <: Record[OwnerType]](rec: OwnerType) extends EnumField(rec, USAPurchaseLimit) {
     45   override def setFromJValue(jvalue: JValue): Box[USAPurchaseLimitField.this.MyType] = {
     46     val stringToInt = jvalue transform {
     47       case JString(s) => 
     48         val value: Box[Int] = USAPurchaseLimit.select(s).map(_.id)
     49         value.map(JInt(_)).openOr(JNothing)
     50       case _ => JNothing
     51     }
     52     super.setFromJValue(stringToInt)
     53   }
     54 }
     55 
     56 /**
     57  * Add this to a user to keep track of the user's real ID verification stage.
     58  */
     59 trait USAUserVerification[A <: Record[A]] {
     60   this: A =>
     61     
     62   /** The record's purchase limit. */
     63   object purchaseLimit extends USAPurchaseLimitField[A](this)
     64   
     65   /*
     66    * Friendly functions to check limits
     67    */
     68   def limit1k: Boolean = purchaseLimit.get == USAPurchaseLimit.D1k
     69   def limit3k: Boolean = purchaseLimit.get == USAPurchaseLimit.D3k || purchaseLimit.get == USAPurchaseLimit.D10k_?
     70   def limit10k: Boolean = purchaseLimit.get == USAPurchaseLimit.D10k
     71   
     72   def userLimitAsString = 
     73     if(limit10k) "$10,000"
     74     else if(limit3k) "$3,000"
     75     else "$1,000"
     76       
     77   def userLimitAsInt = userLimitAsString.tail.replaceAll(",", "").toInt
     78 }