@@ -4,10 +4,12 @@
4module Web.Connexpay.Payments ( CreditCard(..)
4module Web.Connexpay.Payments ( CreditCard(..)
5 , AuthResponse(..)
5 , AuthResponse(..)
6 , authorisePayment
6 , authorisePayment
7 , voidPayment
8 , voidPayment
8 , CaptureResponse(..)
9 , CaptureResponse(..)
9 , capturePayment
10 , capturePayment
10 , cancelPayment
11 , cancelPayment
13import Control.Monad (when,void)
15import Control.Monad (when,void)
@@ -104,7 +106,7 @@ sendRequestJson = sendRequest' jsonResponse
104sendRequest_ :: Text -> [Pair] -> ConnexpayM ()
106sendRequest_ :: Text -> [Pair] -> ConnexpayM ()
105sendRequest_ ep = void . sendRequest' ignoreResponse ep
107sendRequest_ ep = void . sendRequest' ignoreResponse ep
107−data AuthResponse = AuthResponse { paymentGuid :: SaleGuid
109+data AuthResponse = AuthResponse { paymentGuid :: AuthOnlyGuid
108 , status :: TransactionStatus
110 , status :: TransactionStatus
109 , processorStatusCode :: Maybe Text
111 , processorStatusCode :: Maybe Text
110 , processorMessage :: Maybe Text
112 , processorMessage :: Maybe Text
@@ -147,13 +149,16 @@ authorisePayment cc amt invoice vendor =
147 -- should the need arise.
149 -- should the need arise.
148 tell [ "RiskData" .= KeyMap.empty @() ]
150 tell [ "RiskData" .= KeyMap.empty @() ]
152+data VoidRequest = VoidAuthorized AuthOnlyGuid | VoidCaptured SaleGuid (Maybe (Money USD))
150-- | Void payment
154-- | Void payment
151−voidPayment :: SaleGuid -- ^ Sales GUID, obtained from 'authorisePayment'.
155+voidPayment :: VoidRequest
152− -> Maybe (Money USD) -- ^ Optionally, you may only void a partial sum, with the rest being subsequently charged.
153 -> ConnexpayM ()
156 -> ConnexpayM ()
157+voidPayment (VoidAuthorized pid) = sendRequest_ "void" body
158+ where body = [ "AuthOnlyGuid" .= show pid ]
154−voidPayment pid amt = sendRequest_ "void" body
159+voidPayment (VoidCaptured pid amt) = sendRequest_ "void" body
155 where body = execWriter $
160 where body = execWriter $
156− do tell [ "AuthOnlyGuid" .= show pid ]
161+ do tell [ "SaleGuid" .= show pid ]
157 whenJust amt $ \m ->
162 whenJust amt $ \m ->
158 tell [ "Amount" .= getAmount m ]
163 tell [ "Amount" .= getAmount m ]
@@ -191,7 +196,16 @@ capturePayment pid =
191-- | Cancel voided or captured payment.
196-- | Cancel voided or captured payment.
192-- In case of an authorised-only payment, voiding is performed.
197-- In case of an authorised-only payment, voiding is performed.
193-- Otherwise, a payment goes through a refund process.
198-- Otherwise, a payment goes through a refund process.
194−cancelPayment :: SaleGuid -- ^ Sales GUID, obtained from 'authorisePayment'.
199+cancelPayment :: SaleGuid -- ^ Sales GUID, obtained from 'capturePayment'.
195 -> ConnexpayM ()
200 -> ConnexpayM ()
196cancelPayment pid = sendRequest_ "cancel" body
201cancelPayment pid = sendRequest_ "cancel" body
197 where body = [ "SaleGuid" .= show pid ]
202 where body = [ "SaleGuid" .= show pid ]
204+returnPayment :: SaleGuid -- ^ Sales GUID, obtained from 'capturePayment'.
205+ -> Maybe (Money USD)
207+returnPayment pid amt = sendRequest_ "returns" body
208+ where body = execWriter $
209+ do tell [ "SaleGuid" .= show pid ]
210+ whenJust amt $ \m ->
211+ tell [ "Amount" .= getAmount m ]