stripe
stripe copied to clipboard
WIP: More SCA upgrades
Building on @NorfairKing's PR, these are the types and endpoints we added to get SCA working on our app. Still a work-in-progress. I realized a bit into our work that we were using the wrong API version in the Stripe Dashboard, so there are probably some inconsistencies with the pinned 2014 version of the API. Still somehow everything works in practice. Next planning on adding all the missing types and endpoints and checking it all against the 2014 version docs.
Awesome! Looks like great work so far.
@emhoracek Not sure if I'm reading it incorrectly or doing something wrong when trying to expand the CreateSession
, but it looks as though expanding with SessionModeSubscription
for creating new recurring subscriptions is not implemented yet. Is that right?
EDIT: Ok, I managed to get this working with a local clone.
I added this to Web.Stripe.Session
:
instance StripeHasParam CreateSession SessionMode
and this to Web.Stripe.StripeRequest
:
instance ToStripeParam SessionMode where
toStripeParam mode =
(("mode", case mode of
SessionModePayment -> "payment"
SessionModeSetup -> "setup"
SessionModeSubscription -> "subscription"
UnknownSessionMode t -> Text.encodeUtf8 t) :)
According to the API docs, Stripe will only accept the first three session modes. Not sure if I've implemented that fourth case correctly, but it works.
Usage is something like this:
postNewCheckoutSessionR :: Handler ()
postNewCheckoutSessionR = do
req <- requireCheckJsonBody :: Handler Value
stripeKey <- appStripeSecretKey <$> getsYesod appSettings
ur <- getUrlRenderParams
-- TODO: Fix typo in 'Sucess'
-- https://github.com/dmjio/stripe/pull/135/files#r607576380
let successUrl =
Stripe.SucessUrl $ ur AccountR params
where params = [("session_id", "{CHECKOUT_SESSION_ID}")]
cancelUrl = Stripe.CancelUrl $ ur PricingR []
methods = Stripe.PaymentMethodTypes [Stripe.PaymentMethodTypeCard]
config = Stripe.StripeConfig stripeKey Nothing
action = Stripe.createSession successUrl cancelUrl methods Stripe.-&- Stripe.SessionModeSubscription
liftIO (Stripe.stripe config action) >>= \case
Left err -> do
$(logDebug) $ tshow err
pure ()
Right res -> do
$(logDebug) $ tshow res
pure ()
@emhoracek when doing 3d secure returns "TODO" on "cardHash3DSUsage" where this placeholder coming from?
@emhoracek when doing 3d secure returns "TODO" on "cardHash3DSUsage" where this placeholder coming from?
nevermind, it's a fallback function unknownCode
, I guess I'll have to add 3DS on my own