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: More SCA upgrades #135

Open
wants to merge 48 commits into
base: master
Choose a base branch
from
Open

Conversation

emhoracek
Copy link
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
Copy link
Owner

dmjio commented Jan 19, 2021

Awesome! Looks like great work so far.

@@ -427,6 +465,67 @@ instance ToStripeParam TrialPeriodDays where
toStripeParam (TrialPeriodDays days) =
(("trial_period_days", toBytestring days) :)

instance ToStripeParam SuccessUrl where
toStripeParam (SucessUrl url) =
Copy link
Contributor

@jezen jezen Apr 6, 2021

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
Copy link
Contributor

jezen commented Apr 6, 2021

@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

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

@sigrlami
Copy link

@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