From 5be7f3a67aef71a28b9eca37fe0e6272c528b355 Mon Sep 17 00:00:00 2001 From: Ramakrishnan Muthukrishnan <ram@leastauthority.com> Date: Wed, 6 Nov 2019 11:49:34 +0530 Subject: [PATCH] type alias for stripe secret key --- src/PaymentServer/Main.hs | 2 +- src/PaymentServer/Processors/Stripe.hs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/PaymentServer/Main.hs b/src/PaymentServer/Main.hs index 4e1afc9..7593bfb 100644 --- a/src/PaymentServer/Main.hs +++ b/src/PaymentServer/Main.hs @@ -93,7 +93,7 @@ data ServerConfig = ServerConfig , database :: Database , databasePath :: Maybe Text , endpoint :: Endpoint - , stripeKey :: ByteString + , stripeKey :: ByteString } deriving (Show, Eq) diff --git a/src/PaymentServer/Processors/Stripe.hs b/src/PaymentServer/Processors/Stripe.hs index 5d8b367..6c2b601 100644 --- a/src/PaymentServer/Processors/Stripe.hs +++ b/src/PaymentServer/Processors/Stripe.hs @@ -77,6 +77,8 @@ import PaymentServer.Persistence , VoucherDatabase(payForVoucher) ) +type StripePrivateKey = ByteString + data Acknowledgement = Ok instance ToJSON Acknowledgement where @@ -94,7 +96,7 @@ getVoucher (MetaData []) = Nothing getVoucher (MetaData (("Voucher", value):xs)) = Just value getVoucher (MetaData (x:xs)) = getVoucher (MetaData xs) -stripeServer :: VoucherDatabase d => d -> ByteString -> Server StripeAPI +stripeServer :: VoucherDatabase d => d -> StripePrivateKey -> Server StripeAPI stripeServer d key = webhook d :<|> charge d key @@ -143,7 +145,7 @@ instance FromJSON Charges where -- | 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 => d -> ByteString -> Charges -> Handler Acknowledgement +charge :: VoucherDatabase d => d -> StripePrivateKey -> Charges -> Handler Acknowledgement charge d key (Charges token voucher amount currency) = do let config = StripeConfig (StripeKey key) Nothing tokenId = TokenId token -- GitLab