Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: SCA upgrade #122

Closed
wants to merge 19 commits into from
12 changes: 12 additions & 0 deletions stack.yaml.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file was autogenerated by Stack.
# You should not edit this file by hand.
# For more information, please see the documentation at:
# https://docs.haskellstack.org/en/stable/lock_files

packages: []
snapshots:
- completed:
size: 535471
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/9/5.yaml
sha256: 452763f820c6cf01f7c917c71dd4e172578d7e53a7763bce863b99f9a8bc843d
original: lts-9.5
15 changes: 8 additions & 7 deletions stripe-core/src/Web/Stripe/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,17 @@ handleStream
handleStream decodeValue statusCode r =
case statusCode of
200 -> case r of
Error message -> parseFail message
Error message -> parseFail message Nothing
(Success value) ->
case decodeValue value of
(Error message) -> parseFail message
(Error message) -> parseFail message (Just value)
(Success a) -> (Right a)
code | code >= 400 ->
case r of
Error message -> parseFail message
Error message -> parseFail message Nothing
(Success value) ->
case fromJSON value of
(Error message) -> parseFail message
(Error message) -> parseFail message (Just value)
(Success stripeError) ->
Left $ setErrorHTTP code stripeError
_ -> unknownCode
Expand All @@ -119,16 +119,17 @@ attemptDecode code = code == 200 || code >= 400
-- | lift a parser error to be a StripeError
parseFail
:: String -- ^ error message
-> Maybe Value
-> Either StripeError a
parseFail errorMessage =
Left $ StripeError ParseFailure (T.pack errorMessage) Nothing Nothing Nothing
parseFail errorMessage mval =
Left $ StripeError ParseFailure (T.pack errorMessage) Nothing Nothing Nothing mval

------------------------------------------------------------------------------
-- | `StripeError` to return when we don't know what to do with the
-- received HTTP status code.
unknownCode :: Either StripeError a
unknownCode =
Left $ StripeError UnknownErrorType mempty Nothing Nothing Nothing
Left $ StripeError UnknownErrorType mempty Nothing Nothing Nothing Nothing

------------------------------------------------------------------------------
-- | set the `errorHTTP` field of the `StripeError` based on the HTTP
Expand Down
4 changes: 3 additions & 1 deletion stripe-core/src/Web/Stripe/Error.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ data StripeError = StripeError {
, errorCode :: Maybe StripeErrorCode
, errorParam :: Maybe Text
, errorHTTP :: Maybe StripeErrorHTTPCode
, errorValue :: Maybe Value
} deriving (Show, Typeable)

instance Exception StripeError
Expand Down Expand Up @@ -109,5 +110,6 @@ instance FromJSON StripeError where
msg <- e .: "message"
code <- fmap toErrorCode <$> e .:? "code"
param <- e .:? "param"
return $ StripeError typ msg code param Nothing
value <- e .:? "value"
return $ StripeError typ msg code param Nothing value
parseJSON _ = mzero
2 changes: 1 addition & 1 deletion stripe-core/src/Web/Stripe/Event.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@ instance StripeHasParam GetEvents Created
instance StripeHasParam GetEvents (EndingBefore EventId)
instance StripeHasParam GetEvents Limit
instance StripeHasParam GetEvents (StartingAfter EventId)
-- instance StripeHasParam GetEvents EventType -- FIXME
instance StripeHasParam GetEvents EventType
161 changes: 161 additions & 0 deletions stripe-core/src/Web/Stripe/PaymentIntent.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}
-------------------------------------------
-- |
-- Module : Web.Stripe.PaymentIntent
-- Copyright : (c) David Johnson, 2014
-- Maintainer : djohnson.m@gmail.com
-- Stability : experimental
-- Portability : POSIX
module Web.Stripe.PaymentIntent
( -- * API
CreatePaymentIntent
, createPaymentIntent
, GetPaymentIntent
, getPaymentIntent
, UpdatePaymentIntent
, updatePaymentIntent
, ConfirmPaymentIntent
, confirmPaymentIntent
, CapturePaymentIntent
, capturePaymentIntent
, CancelPaymentIntent
, cancelPaymentIntent
, GetPaymentIntents
, getPaymentIntents
-- * Types
, Amount (..)
, Charge (..)
, ChargeId (..)
, EndingBefore (..)
, ExpandParams (..)
, PaymentIntent (..)
, PaymentIntentId (..)
, PaymentMethodTypes (..)
, PaymentMethodType (..)
, StripeList (..)
) where

import Web.Stripe.StripeRequest (Method (GET, POST),
StripeHasParam, StripeReturn,
StripeRequest (..), toStripeParam, mkStripeRequest)
import Web.Stripe.Util ((</>))
import Web.Stripe.Types (Amount(..), Charge (..), ChargeId (..), Currency(..), CustomerId(..),
EndingBefore(..), Limit(..),
MetaData(..), PaymentIntent (..), PaymentMethodTypes(..), PaymentMethodType(..),
PaymentIntentId (..), ReceiptEmail(..),
StartingAfter(..), ExpandParams(..),
StripeList (..))

------------------------------------------------------------------------------
-- | create a `PaymentIntent`
createPaymentIntent
:: Amount
-> Currency
-> StripeRequest CreatePaymentIntent
createPaymentIntent
amount
currency = request
where request = mkStripeRequest POST url params
url = "payment_intents"
params = toStripeParam amount $
toStripeParam currency $
[]

data CreatePaymentIntent
type instance StripeReturn CreatePaymentIntent = PaymentIntent
instance StripeHasParam CreatePaymentIntent CustomerId
instance StripeHasParam CreatePaymentIntent ReceiptEmail
instance StripeHasParam CreatePaymentIntent PaymentMethodTypes

------------------------------------------------------------------------------
-- | Retrieve a `PaymentIntent` by `ChargeId` and `PaymentIntentId`
getPaymentIntent
:: PaymentIntentId -- ^ `PaymentIntentId` associated with the `PaymentIntent` to be retrieved
-> StripeRequest GetPaymentIntent
getPaymentIntent
(PaymentIntentId paymentIntentid) = request
where request = mkStripeRequest GET url params
url = "payment_intents" </> paymentIntentid
params = []

data GetPaymentIntent
type instance StripeReturn GetPaymentIntent = PaymentIntent
instance StripeHasParam GetPaymentIntent ExpandParams

------------------------------------------------------------------------------
-- | Update a `PaymentIntent` by `ChargeId` and `PaymentIntentId`
updatePaymentIntent
:: PaymentIntentId -- ^ `PaymentIntentId` associated with the `PaymentIntent` to be retrieved
-> StripeRequest UpdatePaymentIntent
updatePaymentIntent
(PaymentIntentId paymentIntentid)
= request
where request = mkStripeRequest POST url params
url = "payment_intents" </> paymentIntentid
params = []

data UpdatePaymentIntent
type instance StripeReturn UpdatePaymentIntent = PaymentIntent
instance StripeHasParam UpdatePaymentIntent MetaData

confirmPaymentIntent
:: PaymentIntentId
-> StripeRequest ConfirmPaymentIntent
confirmPaymentIntent
(PaymentIntentId paymentIntentid)
= request
where request = mkStripeRequest POST url params
url = "payment_intents" </> paymentIntentid </> "confirm"
params = []

data ConfirmPaymentIntent
type instance StripeReturn ConfirmPaymentIntent = PaymentIntent
instance StripeHasParam ConfirmPaymentIntent MetaData

capturePaymentIntent
:: PaymentIntentId
-> StripeRequest CapturePaymentIntent
capturePaymentIntent
(PaymentIntentId paymentIntentid)
= request
where request = mkStripeRequest POST url params
url = "payment_intents" </> paymentIntentid </> "capture"
params = []

data CapturePaymentIntent
type instance StripeReturn CapturePaymentIntent = PaymentIntent
instance StripeHasParam CapturePaymentIntent MetaData

cancelPaymentIntent
:: PaymentIntentId
-> StripeRequest CancelPaymentIntent
cancelPaymentIntent
(PaymentIntentId paymentIntentid)
= request
where request = mkStripeRequest POST url params
url = "payment_intents" </> paymentIntentid </> "cancel"
params = []

data CancelPaymentIntent
type instance StripeReturn CancelPaymentIntent = PaymentIntent
instance StripeHasParam CancelPaymentIntent MetaData

------------------------------------------------------------------------------
-- | Retrieve a list of PaymentIntents
getPaymentIntents
:: StripeRequest GetPaymentIntents
getPaymentIntents
= request
where request = mkStripeRequest GET url params
url = "payment_intents"
params = []

data GetPaymentIntents
type instance StripeReturn GetPaymentIntents = StripeList PaymentIntent
instance StripeHasParam GetPaymentIntents ExpandParams
instance StripeHasParam GetPaymentIntents (EndingBefore PaymentIntentId)
instance StripeHasParam GetPaymentIntents Limit
instance StripeHasParam GetPaymentIntents (StartingAfter PaymentIntentId)
88 changes: 88 additions & 0 deletions stripe-core/src/Web/Stripe/Session.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}
-------------------------------------------
-- |
-- Module : Web.Stripe.Session
-- Copyright : (c) David Johnson, 2014
-- Maintainer : djohnson.m@gmail.com
-- Stability : experimental
-- Portability : POSIX
module Web.Stripe.Session
( -- * API
CreateSession
, createSession
, GetSession
, getSession
-- * Types
, SuccessUrl(..)
, CancelUrl(..)
, ClientReferenceId(..)
, CustomerEmail(..)
, Amount (..)
, LineItems(..)
, LineItem(..)
, Charge (..)
, ChargeId (..)
, EndingBefore (..)
, ExpandParams (..)
, Session (..)
, SessionId (..)
, SessionData (..)
, StripeList (..)
, PaymentMethodTypes(..)
) where

import Web.Stripe.StripeRequest (Method (GET, POST),
StripeHasParam, StripeReturn,
StripeRequest (..), toStripeParam, mkStripeRequest)
import Web.Stripe.Util ((</>))
import Web.Stripe.Types (Amount(..), Charge (..), ChargeId (..),
EndingBefore(..),
Session (..),
SessionId (..), SuccessUrl(..), CancelUrl(..), LineItems(..), LineItem(..), CustomerId(..), CustomerEmail(..), ClientReferenceId(..), SessionData(..), PaymentMethodTypes(..),
ExpandParams(..),
StripeList (..))

------------------------------------------------------------------------------
-- | create a `Session`
createSession
:: SuccessUrl -- ^ Success url
-> CancelUrl -- ^ Cancel url
-> PaymentMethodTypes
-> StripeRequest CreateSession
createSession
successUrl
cancelUrl
paymentMethodTypes = request
where request = mkStripeRequest POST url params
url = "checkout" </> "sessions"
params = toStripeParam successUrl $
toStripeParam cancelUrl $
toStripeParam paymentMethodTypes $
[]

data CreateSession
type instance StripeReturn CreateSession = Session
instance StripeHasParam CreateSession LineItems
instance StripeHasParam CreateSession CustomerId
instance StripeHasParam CreateSession ClientReferenceId
instance StripeHasParam CreateSession CustomerEmail
instance StripeHasParam CreateSession PaymentMethodTypes
instance StripeHasParam CreateSession ExpandParams

------------------------------------------------------------------------------
-- | Retrieve a `Session` by `ChargeId` and `SessionId`
getSession
:: SessionId -- ^ `SessionId` associated with the `Session` to be retrieved
-> StripeRequest GetSession
getSession
(SessionId sessionid) = request
where request = mkStripeRequest GET url params
url = "checkout" </> "sessions" </> sessionid
params = []

data GetSession
type instance StripeReturn GetSession = Session
instance StripeHasParam GetSession ExpandParams
Loading