@@ -30,10 +30,10 @@ import Web.Connexpay.Utils
3030-- | Credit card info
3131-- No 'Show' instance should be made for this type
3232-- in order to avoid sensitive data leaks.
33−data CreditCard = CreditCard { number :: Text
34− , cardholder :: Maybe Text
35− , expiration :: (Word, Word) -- ^ Expiration date (month,year)
36− , cvv :: Maybe Text
33+data CreditCard = CreditCard { number :: Text -- ^ Credit card number, as 'Text'.
34+ , cardholder :: Maybe Text -- ^ Cardholder name, optional.
35+ , expiration :: (Word, Word) -- ^ Expiration date (month,year).
36+ , cvv :: Maybe Text -- ^ CVC/CVV code.
3737 }
3838
3939type ShowError = TypeError.Text "CreditCard must not be shown in order to avoid leaking sensitive data"
@@ -89,14 +89,23 @@ instance FromJSON AuthResponse where
8989 <*> o .:? "processorResponseMessage"
9090 parseJSON v = typeMismatch "AuthReponse" v
9191
92−authorisePayment :: CreditCard -> Money USD -> ConnexpayM AuthResponse
93−authorisePayment cc amt = do resp <- sendRequestJson "authonlys" body
94− pure (responseBody resp)
95− where body = [ "Card" .= cc
96− , "Amount" .= getAmount amt
97− ]
98−
99−voidPayment :: SaleGuid -> Maybe (Money USD) -> ConnexpayM ()
92+-- | Authorise a credit card payment.
93+authorisePayment :: CreditCard -- ^ Credit card details (see 'CreditCard')
94+ -> Money USD -- ^ Amount to charge, USD
95+ -> Maybe Text -- ^ Merchant description that will appear in a customer's statement.
96+ -> ConnexpayM AuthResponse
97+authorisePayment cc amt vendor = do resp <- sendRequestJson "authonlys" body
98+ pure (responseBody resp)
99+ where body = execWriter $
100+ do tell [ "Card" .= cc ]
101+ tell ["Amount" .= getAmount amt ]
102+ whenJust vendor $ \v ->
103+ tell [ "StatementDescription" .= v ]
104+
105+-- | Void payment
106+voidPayment :: SaleGuid -- ^ Sales GUID, obtained from 'authorisePayment'.
107+ -> Maybe (Money USD) -- ^ Optionally, you may only void a partial sum, with the rest being subsequently charged.
108+ -> ConnexpayM ()
100109voidPayment pid amt = sendRequest_ "void" body
101110 where body = execWriter $
102111 do tell [ "AuthOnlyGuid" .= show pid ]
@@ -109,12 +118,17 @@ data CPTransaction = CPTransaction { expectedPayments :: Int32 }
109118instance ToJSON CPTransaction where
110119 toJSON t = object [ "ExpectedPayments" .= t.expectedPayments ]
111120
112−
113−capturePayment :: SaleGuid -> ConnexpayM ()
121+-- | Capture payment, previously authorised through 'authorisePayment'.
122+capturePayment :: SaleGuid -- ^ Sales GUID, obtained from 'authorisePayment'.
123+ -> ConnexpayM ()
114124capturePayment pid = sendRequest_ "Captures" body
115125 where body = [ "AuthOnlyGuid" .= show pid
116126 , "ConnexPayTransaction" .= CPTransaction 1 ]
117127
118−cancelPayment :: SaleGuid -> ConnexpayM ()
128+-- | Cancel voided or captured payment.
129+-- In case of an authorised-only payment, voiding is performed.
130+-- Otherwise, a payment goes through a refund process.
131+cancelPayment :: SaleGuid -- ^ Sales GUID, obtained from 'authorisePayment'.
132+ -> ConnexpayM ()
119133cancelPayment pid = sendRequest_ "cancel" body
120134 where body = [ "SaleGuid" .= show pid ]