git.iko.soy/typeable/connexpay
on master help sign in
Merge pull request #1 from typeable/wip/yuras/refund
82a2166Yuras
README.org+5−1
@@ -35,8 +35,12 @@ Examples:
35
35
36 - ~stack run -- -c ./config.yaml auth CARDNUMBER "NAME" MMYY CVV SUM~
36 - ~stack run -- -c ./config.yaml auth CARDNUMBER "NAME" MMYY CVV SUM~
37 - ~stack run -- -c ./config.yaml capture SALEGUID~
37 - ~stack run -- -c ./config.yaml capture SALEGUID~
38− - ~stack run -- -c ./config.yaml void SALEGUID~
38+ - ~stack run -- -c ./config.yaml void-auth AUTHONLYGUID~
39+ - ~stack run -- -c ./config.yaml void-sale SALEGUID~
40+ - ~stack run -- -c ./config.yaml void-sale SALEGUID SUM~
39 - ~stack run -- -c ./config.yaml cancel SALEGUID~
41 - ~stack run -- -c ./config.yaml cancel SALEGUID~
42+ - ~stack run -- -c ./config.yaml return SALEGUID~
43+ - ~stack run -- -c ./config.yaml return SALEGUID SUM~
40
44
41Configuration file must include the values provided to you by Connexpay:
45Configuration file must include the values provided to you by Connexpay:
42
46
connexpay/src/Tool.hs+10−4
@@ -33,9 +33,11 @@ data Config = Config { login :: Text
33instance FromJSON Config
33instance FromJSON Config
34
34
35data Command = AuthSale CreditCard Centi
35data Command = AuthSale CreditCard Centi
36+ | VoidAuth AuthOnlyGuid
36− | VoidSale SaleGuid
37+ | VoidSale SaleGuid (Maybe Centi)
37− | CaptureSale SaleGuid
38+ | CaptureSale AuthOnlyGuid
38 | CancelSale SaleGuid
39 | CancelSale SaleGuid
40+ | ReturnSale SaleGuid (Maybe Centi)
39 | TestAuth
41 | TestAuth
40
42
41data CmdLine = CmdLine { configPath :: FilePath
43data CmdLine = CmdLine { configPath :: FilePath
@@ -46,9 +48,11 @@ cmdParser :: Parser CmdLine
46cmdParser = CmdLine <$> strOption (short 'c' <> metavar "FILE" <> help "Configuration file path")
48cmdParser = CmdLine <$> strOption (short 'c' <> metavar "FILE" <> help "Configuration file path")
47 <*> subparser operation
49 <*> subparser operation
48 where operation = command "auth" (info (AuthSale <$> cc <*> amt) (progDesc "Authorise payment"))
50 where operation = command "auth" (info (AuthSale <$> cc <*> amt) (progDesc "Authorise payment"))
51+ <> command "void-auth" (info (VoidAuth <$> guid) (progDesc "Void payment"))
49− <> command "void" (info (VoidSale <$> guid) (progDesc "Void payment"))
52+ <> command "void-sale" (info (VoidSale <$> guid <*> optional amt) (progDesc "Void payment"))
50 <> command "capture" (info (CaptureSale <$> guid) (progDesc "Capture payment"))
53 <> command "capture" (info (CaptureSale <$> guid) (progDesc "Capture payment"))
51 <> command "cancel" (info (CancelSale <$> guid) (progDesc "Cancel payment"))
54 <> command "cancel" (info (CancelSale <$> guid) (progDesc "Cancel payment"))
55+ <> command "return" (info (ReturnSale <$> guid <*> optional amt) (progDesc "return payment"))
52 <> command "test-auth" (info (pure TestAuth) (progDesc "Test token authorisation"))
56 <> command "test-auth" (info (pure TestAuth) (progDesc "Test token authorisation"))
53 amt = argument auto (metavar "Payment amount")
57 amt = argument auto (metavar "Payment amount")
54 cc = CreditCard <$> argument str mempty
58 cc = CreditCard <$> argument str mempty
@@ -82,7 +86,9 @@ doThing (AuthSale cc amt) = liftIO . print =<< authorisePayment cc usd pnr vendo
82 where usd = Money amt
86 where usd = Money amt
83 pnr = Just "PNRPNR"
87 pnr = Just "PNRPNR"
84 vendor = Just "Typeable payment"
88 vendor = Just "Typeable payment"
89+doThing (VoidAuth guid) = liftIO . print =<< voidPayment (VoidAuthorized guid)
85−doThing (VoidSale guid) = liftIO . print =<< voidPayment guid Nothing
90+doThing (VoidSale guid amt) = liftIO . print =<< voidPayment (VoidCaptured guid (Money <$> amt))
86doThing (CaptureSale guid) = liftIO . print =<< capturePayment guid
91doThing (CaptureSale guid) = liftIO . print =<< capturePayment guid
87doThing (CancelSale guid) = liftIO . print =<< cancelPayment guid
92doThing (CancelSale guid) = liftIO . print =<< cancelPayment guid
93+doThing (ReturnSale guid amt) = liftIO . print =<< returnPayment guid (Money <$> amt)
88doThing TestAuth = liftIO (forever yield)
94doThing TestAuth = liftIO (forever yield)
connexpay/src/Web/Connexpay/Payments.hs+20−6
@@ -4,10 +4,12 @@
4module Web.Connexpay.Payments ( CreditCard(..)
4module Web.Connexpay.Payments ( CreditCard(..)
5 , AuthResponse(..)
5 , AuthResponse(..)
6 , authorisePayment
6 , authorisePayment
7+ , VoidRequest(..)
7 , voidPayment
8 , voidPayment
8 , CaptureResponse(..)
9 , CaptureResponse(..)
9 , capturePayment
10 , capturePayment
10 , cancelPayment
11 , cancelPayment
12+ , returnPayment
11 ) where
13 ) where
12
14
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
106
108
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 @() ]
149
151
152+data VoidRequest = VoidAuthorized AuthOnlyGuid | VoidCaptured SaleGuid (Maybe (Money USD))
153+
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 ]
159
164
@@ -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 ]
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 ]
connexpay/src/Web/Connexpay/Types.hs+1
@@ -19,6 +19,7 @@ import Network.HTTP.Types
19
19
20type BearerToken = Text
20type BearerToken = Text
21type DeviceGuid = UUID
21type DeviceGuid = UUID
22+type AuthOnlyGuid = UUID
22type SaleGuid = UUID
23type SaleGuid = UUID
23type CaptureGuid = UUID
24type CaptureGuid = UUID
24
25