Skip to content

WIP: More SCA upgrades#135

Open
emhoracek wants to merge 48 commits into
dmjio:masterfrom
positiondev:sca-upgrade
Open

WIP: More SCA upgrades#135
emhoracek wants to merge 48 commits into
dmjio:masterfrom
positiondev:sca-upgrade

Conversation

@emhoracek

Copy link
Copy Markdown
Contributor

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.

@dmjio

dmjio commented Jan 19, 2021

Copy link
Copy Markdown
Owner

Awesome! Looks like great work so far.

(("trial_period_days", toBytestring days) :)

instance ToStripeParam SuccessUrl where
toStripeParam (SucessUrl url) =

@jezen jezen Apr 6, 2021

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found a minor typo here.

-  toStripeParam (SucessUrl url) =
+  toStripeParam (SuccessUrl url) =

@jezen

jezen commented Apr 6, 2021

Copy link
Copy Markdown
Contributor

@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 ()

@sigrlami

Copy link
Copy Markdown

@emhoracek when doing 3d secure returns "TODO" on "cardHash3DSUsage" where this placeholder coming from?

@sigrlami

Copy link
Copy Markdown

@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

@NorfairKing NorfairKing mentioned this pull request Dec 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants