@@ -1,31 +1,32 @@
1−module Web.Connexpay.Data where
1+{-# LANGUAGE OverloadedStrings #-}
2+module Web.Connexpay.Data ( TransactionStatus (..)
3+ ) where
24
3−import Web.Connexpay.Types
4−
5−import Data.Money (Money, USD)
5+import Data.Aeson
6+import Data.Aeson.Types
7+import Data.Maybe (fromMaybe)
68import Data.Text (Text)
79
8−-- | Create sale request type.
9−-- This is far from the complete description, but should be enough for our cause.
10−-- See documentation here: https://docs.connexpay.com/reference/getting-started-with-your-api
11−data CreateSale = CreateSale { deviceGuid :: DeviceGuid
12− , amount :: Money USD
13− , sequenceCode :: Text
14− , orderCode :: Text
15− , statementDesc :: Maybe Text
16− } deriving (Show)
17−
18−data CreateSaleResponse = CreateSaleResponse { -- Fill this later as needed
19− } deriving (Show)
10+-- | Transaction status in Connexpay
11+-- The list is taken from https://docs.connexpay.com/reference/search-sales
12+data TransactionStatus = TransactionApproved -- ^ Obvious
13+ | TransactionDeclined -- ^ Also obvious
14+ | TransactionCreatedLocal -- ^ Seems to only exist in a test environment, indicates success.
15+ | TransactionCreatedProcNotReached -- ^ Communication error between Connexpay and Card Processor
16+ | TransactionCreatedProcError -- ^ Processor errored out
17+ | TransactionApprovedWarning -- ^ Wut 0__o FIXME: figure out what this is
18+ | TransactionOther Text -- ^ In case they return something unexpected
19+ deriving (Show)
2020
21−-- | Void a previously create sale
22−-- Documentation: https://docs.connexpay.com/reference/void
23−data VoidSale = VoidSale { deviceGuid :: DeviceGuid
24− , saleGuid :: SaleGuid
25− , reason :: Maybe Text
26− , amount :: Maybe (Money USD)
27− , sequenceCode :: Text
28− } deriving (Show)
21+statuses :: [(Text, TransactionStatus)]
22+statuses = [ ( "Transaction - Approved", TransactionApproved )
23+ , ( "Transaction - Declined", TransactionDeclined )
24+ , ( "Transaction - CreatedLocal", TransactionCreatedLocal )
25+ , ( "Transaction - Created - Error: Processor not reached", TransactionCreatedProcNotReached )
26+ , ( "Transaction - Processor Error", TransactionCreatedProcError )
27+ , ( "Transaction - Approved - Warning", TransactionApprovedWarning )
28+ ]
2929
30−data VoidSaleResponse = VoidSaleResponse { -- Fill this later as needed
31− } deriving (Show)
30+instance FromJSON TransactionStatus where
31+ parseJSON (String s) = pure (fromMaybe (TransactionOther s) (lookup s statuses))
32+ parseJSON v = typeMismatch "TransactionStatus" v