Add billing create API call.

[?]
Feb 2, 2021, 4:55 AM
27H4DECZW4CEDSV5XYJQA5HOMUW73K5G2DBQNLQB7AFZXXVXCFCAC

Dependencies

  • [2] VTZT2ILU Wire up billing navigation.
  • [3] IPG33FAW Add billing daemon
  • [4] IR75ZMX3 Return actual events for interval ends, not just timestamps.
  • [5] ANDJ6GEY Add billing component skeleton.

Change contents

  • replacement in client/src/Aftok/Api/Billing.purs at line 4
    [3.49][3.49:105]()
    import Control.Monad.Except.Trans (ExceptT, runExceptT)
    [3.49]
    [3.105]
    import Control.Monad.Error.Class (throwError)
    import Control.Monad.Except.Trans (runExceptT, except, withExceptT)
  • replacement in client/src/Aftok/Api/Billing.purs at line 8
    [3.234][3.234:335]()
    -- import Data.Argonaut.Core (Json)
    import Data.Argonaut.Decode (class DecodeJson, decodeJson, (.:))
    [3.234]
    [3.335]
    import Data.Argonaut.Core (Json)
    import Data.Argonaut.Decode (class DecodeJson, decodeJson)
    import Data.Argonaut.Encode (encodeJson)
    import Data.BigInt (toNumber)
  • replacement in client/src/Aftok/Api/Billing.purs at line 19
    [3.600][3.600:626]()
    import Data.Maybe (Maybe)
    [3.600]
    [3.626]
    import Data.Maybe (Maybe(..))
  • replacement in client/src/Aftok/Api/Billing.purs at line 23
    [3.755][3.755:785]()
    import Data.Tuple (Tuple(..))
    [3.755]
    [3.785]
    import Data.Tuple (Tuple)
  • replacement in client/src/Aftok/Api/Billing.purs at line 30
    [3.990][3.990:1051]()
    -- import Affjax (get)
    -- import Affjax.ResponseFormat as RF
    [3.990]
    [3.1051]
    import Affjax (post, printError)
    import Affjax.RequestBody as RB
    import Affjax.ResponseFormat as RF
    import Affjax.StatusCode (StatusCode(..))
  • replacement in client/src/Aftok/Api/Billing.purs at line 35
    [3.1070][3.1070:1086]()
    ( ProjectId )
    [3.1070]
    [2.293]
    ( ProjectId, pidStr )
  • replacement in client/src/Aftok/Api/Billing.purs at line 67
    [3.1635][3.1635:1666]()
    newtype Billable' t = Billable
    [3.1635]
    [2.401]
    recurrenceJSON :: Recurrence -> Json
    recurrenceJSON = case _ of
    Annually -> encodeJson $ { annually: {} }
    Monthly i -> encodeJson $ { monthly: i }
    Weekly i -> encodeJson $ { weekly: i }
    OneTime -> encodeJson $ { onetime: {} }
    type Billable =
  • edit in client/src/Aftok/Api/Billing.purs at line 77
    [2.446]
    [2.446]
    , message :: String
  • replacement in client/src/Aftok/Api/Billing.purs at line 84
    [3.1675][3.1675:1710]()
    type Billable = Billable' DateTime
    [3.1675]
    [3.1710]
    billableJSON :: Billable -> Json
    billableJSON b = encodeJson $
    { name: b.name
    , description: b.description
    , message: b.message
    , recurrence: recurrenceJSON b.recurrence
    , currency: "ZEC"
    , amount: toNumber (unwrap b.amount)
    }
  • replacement in client/src/Aftok/Api/Billing.purs at line 116
    [3.2349][3.2349:2396]()
    createBillable pid bid = pure $ Left Forbidden
    [3.2349]
    [3.2396]
    createBillable pid billable = do
    let body = RB.json $ billableJSON billable
    response <- post RF.json ("/api/projects/" <> pidStr pid <> "/billables") (Just body)
    runExceptT $ case response of
    Left err -> throwError $ Error { status: Nothing, message: printError err }
    Right r -> case r.status of
    StatusCode 403 -> throwError $ Forbidden
    StatusCode 200 -> withExceptT (ParseFailure r.body) <<< except $ decodeJson r.body
    other -> throwError $ Error { status: Just other, message: r.statusText }
  • replacement in client/src/Aftok/Zcash.purs at line 3
    [2.656][2.656:686]()
    newtype Zatoshi = Zatoshi Int
    [2.656]
    import Prelude
    import Data.Newtype (class Newtype)
    import Data.BigInt (BigInt)
    import Data.Fixed (Fixed, P1000000, TenTimes)
    newtype Zatoshi = Zatoshi (BigInt)
    derive instance zatoshiEq :: Eq Zatoshi
    derive instance zatoshiOrd :: Ord Zatoshi
    derive instance zatoshiNewtype :: Newtype Zatoshi _
    type ZPrec = TenTimes (TenTimes P1000000)
    newtype ZEC = ZEC (Fixed ZPrec)
    derive instance zecEq :: Eq ZEC
    derive instance zecOrd :: Ord ZEC
    derive instance zecNewtype :: Newtype ZEC _
  • replacement in server/Aftok/Snaplet/Billing.hs at line 104
    [3.26593][3.26593:26667]()
    parseOneTime o' = const (pure B.OneTime) <$> O.lookup "one-time" o'
    [3.26593]
    [3.26667]
    parseOneTime o' = const (pure B.OneTime) <$> O.lookup "onetime" o'