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

Update stripe api spec #15

Merged
merged 5 commits into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
32 changes: 0 additions & 32 deletions .circleci/config.yml

This file was deleted.

37 changes: 37 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: "Build"
on:
pull_request:
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up GHC
uses: haskell-actions/setup@v2
id: setup
with:
ghc-version: "9.4.8"
enable-stack: true
stack-version: "latest"
- name: Restore cached dependencies
uses: actions/cache/restore@v3
id: cache
env:
key: ${{ steps.setup.outputs.ghc-version }}-stack-${{ steps.setup.outputs.stack-version }}
with:
path: ${{ steps.setup.outputs.stack-root }}
key: ${{ env.key }}-lock-${{ hashFiles('stack.yaml.lock') }}
restore-keys: ${{ env.key }}-
- name: Build example
run: cd example && stack --no-terminal build --fast
- name: Save cached dependencies
uses: actions/cache/save@v3
# If we had an exact cache hit, trying to save the cache would error because of key clash.
if: steps.cache.outputs.cache-hit != 'true'
with:
path: ${{ steps.setup.outputs.stack-root }}
key: ${{ steps.cache.outputs.cache-primary-key }}
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ cd example
stack run --fast
```

## Extra modules

There are a few hand-written modules which are currently:

- StripeAPI.Types.NotificationEventData.Extra

As they are not reexported (to modify as little of the generated code as possible) you need to explicitly import them (see `example/src/StripeHandling.hs` for an example).

## On the package level
### From hackage
- install [cabal](https://www.haskell.org/cabal/)
Expand Down
4 changes: 2 additions & 2 deletions example/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import StripeHandling

main :: IO ()
main = do
result <- getCheckoutSessionEvents
either (putStrLn . T.unpack) (mapM_ (putStrLn . T.unpack)) result
result <- getCheckoutSessionId
putStrLn result
32 changes: 5 additions & 27 deletions example/src/StripeHandling.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import qualified Data.Maybe as Maybe
import qualified Data.Text as T
import qualified Network.HTTP.Simple as HS
import qualified StripeAPI as Stripe
import qualified StripeAPI.Types.NotificationEventData.Extra as Stripe

stripeAPIKey :: T.Text
stripeAPIKey = "sk_test_XXXXXXXXXX" -- Insert your API key here
Expand Down Expand Up @@ -41,11 +40,10 @@ checkoutLineItem2 =
}

checkoutSession =
( Stripe.mkPostCheckoutSessionsRequestBody
"https://localhost:8080/payments/index.html?success=false&sessionId={CHECKOUT_SESSION_ID}"
"https://localhost:8080/payments/index.html?success=true&sessionId={CHECKOUT_SESSION_ID}"
)
{ Stripe.postCheckoutSessionsRequestBodyLineItems = Just [checkoutLineItem, checkoutLineItem2],
Stripe.mkPostCheckoutSessionsRequestBody
{ Stripe.postCheckoutSessionsRequestBodySuccessUrl = Just "https://localhost:8080/payments/index.html?success=false&sessionId={CHECKOUT_SESSION_ID}",
Stripe.postCheckoutSessionsRequestBodyCancelUrl = Just "https://localhost:8080/payments/index.html?success=true&sessionId={CHECKOUT_SESSION_ID}",
Stripe.postCheckoutSessionsRequestBodyLineItems = Just [checkoutLineItem, checkoutLineItem2],
Stripe.postCheckoutSessionsRequestBodyPaymentMethodTypes = Just [Stripe.PostCheckoutSessionsRequestBodyPaymentMethodTypes'EnumCard]
}

Expand All @@ -68,7 +66,7 @@ conf = defaultConf {Stripe.configSecurityScheme = config}
getCheckoutSessionId :: IO String
getCheckoutSessionId = do
putStrLn "getCheckoutSessionId"
resp <- Stripe.runWithConfiguration conf $ Stripe.postCheckoutSessions checkoutSession
resp <- Stripe.runWithConfiguration conf $ Stripe.postCheckoutSessions $ Just checkoutSession
print resp
pure $
T.unpack $ case HS.getResponseBody resp of
Expand Down Expand Up @@ -149,23 +147,3 @@ getPaymentIntentSepaCallSecret =
MIO.liftIO $ print resp
pure $ trans resp
_ -> pure "response was not a success"

getCheckoutSessionEvents :: IO (Either T.Text [T.Text])
getCheckoutSessionEvents = Stripe.runWithConfiguration conf $ do
res <-
Stripe.getEvents
Stripe.mkGetEventsParameters
{ Stripe.getEventsParametersQueryType = Just "checkout.session.completed"
}
pure $ case HS.getResponseBody res of
Stripe.GetEventsResponse200 eventResponse ->
Right $
( \case
Stripe.CheckoutSessionCompletedEvent session -> Stripe.checkout'sessionId session
Stripe.UnknownEvent t -> "Unknown event type: " <> t
_ -> "Other event"
)
. Stripe.getEventData
<$> Stripe.getEventsResponseBody200Data eventResponse
Stripe.GetEventsResponseError err -> Left $ T.pack err
Stripe.GetEventsResponseDefault err -> Left $ Maybe.fromMaybe "" $ Stripe.apiErrorsMessage $ Stripe.errorError err
Loading
Loading