diff --git a/src/PaymentServer/Processors/Stripe.hs b/src/PaymentServer/Processors/Stripe.hs index 5e78f3f64cdacca08977073828006035a48abd24..c1047deea4fce0a58617fff69ba10e6ebfac2599 100644 --- a/src/PaymentServer/Processors/Stripe.hs +++ b/src/PaymentServer/Processors/Stripe.hs @@ -18,14 +18,10 @@ import Control.Exception ( try , throwIO ) -import Data.ByteString - ( ByteString - ) import Data.Text ( Text , unpack ) -import qualified Data.Map as Map import Text.Read ( readMaybe ) @@ -41,8 +37,6 @@ import Data.Aeson import Servant ( Server , Handler - , err400 - , err500 , ServerError(ServerError, errHTTPCode, errBody, errHeaders, errReasonPhrase) , throwError ) @@ -51,22 +45,12 @@ import Servant.API , JSON , Post , (:>) - , (:<|>)((:<|>)) - ) -import Web.Stripe.Event - ( Event(Event, eventId, eventType, eventData) - , EventId(EventId) - , EventType(ChargeSucceededEvent) - , EventData(ChargeEvent) ) import Web.Stripe.Types ( Charge(Charge, chargeMetaData) , MetaData(MetaData) , Currency ) -import Web.Stripe.Error - ( StripeError(StripeError) - ) import Web.Stripe.Charge ( createCharge , Amount(Amount) @@ -79,6 +63,9 @@ import Web.Stripe ( stripe , (-&-) ) + +import qualified Prometheus as P + import PaymentServer.Persistence ( Voucher , VoucherDatabase(payForVoucher) @@ -126,10 +113,19 @@ instance FromJSON Charges where v .: "currency" parseJSON _ = mzero +chargeAttempts :: P.Counter +chargeAttempts + = P.unsafeRegister + $ P.counter + $ P.Info "charge_attempts" "The number of attempted charge requests received." + -- | call the stripe Charge API (with token, voucher in metadata, amount, currency etc -- and if the Charge is okay, then set the voucher as "paid" in the database. charge :: VoucherDatabase d => StripeConfig -> d -> Charges -> Handler Acknowledgement charge stripeConfig d (Charges token voucher amount currency) = do + + liftIO $ P.incCounter chargeAttempts + currency' <- getCurrency currency result <- liftIO (try (payForVoucher d voucher (completeStripeCharge currency'))) case result of