Skip to content

Commit a0088b4

Browse files
committed
add payment create
1 parent 134fcff commit a0088b4

File tree

5 files changed

+70
-11
lines changed

5 files changed

+70
-11
lines changed

haskell-uon.cabal

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
cabal-version: 1.12
22

3-
-- This file has been generated from package.yaml by hpack version 0.37.0.
3+
-- This file has been generated from package.yaml by hpack version 0.38.0.
44
--
55
-- see: https://github.com/sol/hpack
66

77
name: haskell-uon
8-
version: 0.1.2.14
8+
version: 0.1.3.0
99
description: Please see the README on GitHub at <https://github.com/mejgun/haskell-uon#readme>
1010
homepage: https://github.com/mejgun/haskell-uon#readme
1111
bug-reports: https://github.com/mejgun/haskell-uon/issues
@@ -40,6 +40,7 @@ library
4040
UON.Manager
4141
UON.Manager.GetOffice
4242
UON.Office
43+
UON.Payment
4344
UON.Reminder
4445
UON.Reminder.Create
4546
UON.Reminder.Search
@@ -66,7 +67,6 @@ library
6667
, http-client
6768
, req
6869
, scientific
69-
, sqlite-simple
7070
, text
7171
, time
7272
, unordered-containers

package.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: haskell-uon
2-
version: 0.1.2.14
2+
version: 0.1.3.0
33
github: "mejgun/haskell-uon"
44
license: MIT
55
author: "mejgun"
@@ -46,7 +46,6 @@ library:
4646
- bytestring
4747
- vector
4848
- scientific
49-
- sqlite-simple
5049
default-extensions:
5150
- OverloadedStrings
5251
- NoFieldSelectors

src/UON/Payment.hs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
module UON.Payment
2+
( create,
3+
SearchParam (..),
4+
TypeId (..),
5+
CioId (..),
6+
)
7+
where
8+
9+
import Data.Aeson (FromJSON)
10+
import Data.Aeson qualified as Aeson
11+
import Data.Text qualified as T
12+
import GHC.Generics (Generic)
13+
import Network.HTTP.Req ((=:))
14+
import UON qualified (Key)
15+
import UON.Internal.Param (Param (toQuery))
16+
import UON.Internal.Request qualified as Request
17+
18+
data SearchParam
19+
= Id Int -- ID заявки
20+
| CioId CioId -- Вид платежа
21+
| TypeId TypeId -- Тип платежа
22+
| Price Double -- Стоимость клиенту
23+
| FormId Int -- ID вида платежа
24+
| Note T.Text -- Примечание по платежу
25+
| Reason T.Text -- Основание платежа
26+
27+
data TypeId = Clients | Partners
28+
29+
data CioId = Arrival | Expense
30+
31+
instance Param SearchParam where
32+
toQuery (Id x) = "r_id" =: x
33+
toQuery (Price x) = "price" =: x
34+
toQuery (Note x) = "note" =: x
35+
toQuery (Reason x) = "reason" =: x
36+
toQuery (FormId x) = "form_id" =: x
37+
toQuery (TypeId x) =
38+
"type_id" =: case x of
39+
Clients -> 1 :: Int
40+
Partners -> 2
41+
toQuery (CioId x) =
42+
"cio_id" =: case x of
43+
Arrival -> 1 :: Int
44+
Expense -> 2
45+
46+
newtype Res = Res {result :: Maybe Int}
47+
deriving (Generic)
48+
49+
instance FromJSON Res
50+
51+
create :: UON.Key -> [SearchParam] -> IO (Either T.Text ())
52+
create k p = do
53+
a <- Request.post ["payment", "create"] k p
54+
case a of
55+
Request.Ok (v :: Aeson.Value) ->
56+
case Aeson.fromJSON v of
57+
(Aeson.Success (Res {result = Just 200})) -> pure $ Right ()
58+
_ -> pure $ Left $ "unknown result: " <> T.pack (show v)
59+
Request.Status _ t -> pure $ Left t
60+
Request.Error t -> pure $ Left t

stack.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# A snapshot resolver dictates the compiler version and the set of packages
99
# to be used for project dependencies. For example:
1010
#
11-
resolver: lts-21.25
11+
resolver: lts-22.44
1212
# resolver: nightly-2015-09-21
1313
# resolver: ghc-7.10.2
1414
#

stack.yaml.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# This file was autogenerated by Stack.
22
# You should not edit this file by hand.
33
# For more information, please see the documentation at:
4-
# https://docs.haskellstack.org/en/stable/lock_files
4+
# https://docs.haskellstack.org/en/stable/topics/lock_files
55

66
packages: []
77
snapshots:
88
- completed:
9-
sha256: a81fb3877c4f9031e1325eb3935122e608d80715dc16b586eb11ddbff8671ecd
10-
size: 640086
11-
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/21/25.yaml
12-
original: lts-21.25
9+
sha256: 238fa745b64f91184f9aa518fe04bdde6552533d169b0da5256670df83a0f1a9
10+
size: 721141
11+
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/44.yaml
12+
original: lts-22.44

0 commit comments

Comments
 (0)