@@ -4,10 +4,12 @@
44module Web.Connexpay.Payments ( CreditCard(..)
55 , AuthResponse(..)
66 , authorisePayment
7+ , VoidRequest(..)
78 , voidPayment
89 , CaptureResponse(..)
910 , capturePayment
1011 , cancelPayment
12+ , returnPayment
1113 ) where
1214
1315import Control.Monad (when,void)
@@ -104,7 +106,7 @@ sendRequestJson = sendRequest' jsonResponse
104106sendRequest_ :: Text -> [Pair] -> ConnexpayM ()
105107sendRequest_ ep = void . sendRequest' ignoreResponse ep
106108
107−data AuthResponse = AuthResponse { paymentGuid :: SaleGuid
109+data AuthResponse = AuthResponse { paymentGuid :: AuthOnlyGuid
108110 , status :: TransactionStatus
109111 , processorStatusCode :: Maybe Text
110112 , processorMessage :: Maybe Text
@@ -147,13 +149,16 @@ authorisePayment cc amt invoice vendor =
147149 -- should the need arise.
148150 tell [ "RiskData" .= KeyMap.empty @() ]
149151
152+data VoidRequest = VoidAuthorized AuthOnlyGuid | VoidCaptured SaleGuid (Maybe (Money USD))
153+
150154-- | Void payment
151−voidPayment :: SaleGuid -- ^ Sales GUID, obtained from 'authorisePayment'.
152− -> Maybe (Money USD) -- ^ Optionally, you may only void a partial sum, with the rest being subsequently charged.
155+voidPayment :: VoidRequest
153156 -> ConnexpayM ()
154−voidPayment pid amt = sendRequest_ "void" body
157+voidPayment (VoidAuthorized pid) = sendRequest_ "void" body
158+ where body = [ "AuthOnlyGuid" .= show pid ]
159+voidPayment (VoidCaptured pid amt) = sendRequest_ "void" body
155160 where body = execWriter $
156− do tell [ "AuthOnlyGuid" .= show pid ]
161+ do tell [ "SaleGuid" .= show pid ]
157162 whenJust amt $ \m ->
158163 tell [ "Amount" .= getAmount m ]
159164
@@ -191,7 +196,16 @@ capturePayment pid =
191196-- | Cancel voided or captured payment.
192197-- In case of an authorised-only payment, voiding is performed.
193198-- Otherwise, a payment goes through a refund process.
194−cancelPayment :: SaleGuid -- ^ Sales GUID, obtained from 'authorisePayment'.
199+cancelPayment :: SaleGuid -- ^ Sales GUID, obtained from 'capturePayment'.
195200 -> ConnexpayM ()
196201cancelPayment pid = sendRequest_ "cancel" body
197202 where body = [ "SaleGuid" .= show pid ]
203+
204+returnPayment :: SaleGuid -- ^ Sales GUID, obtained from 'capturePayment'.
205+ -> Maybe (Money USD)
206+ -> ConnexpayM ()
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 ]