module ThirdParty.StripeAPISpec (spec) where
import qualified Network.HTTP.Client as HTTPClient
import qualified StripeAPI as Stripe
import Test.Hspec (Spec, describe, expectationFailure, it)
import TestUtils
spec :: Spec
spec = do
describe "checkout sessions" $ do
it "should contain a payment intent and a session url" $ do
let params = (Stripe.mkPostCheckoutSessionsRequestBody "http://localhost:3000/" "http://localhost:3000/")
{ Stripe.postCheckoutSessionsRequestBodyLineItems = Just [lineItems]
, Stripe.postCheckoutSessionsRequestBodyMode = Just Stripe.PostCheckoutSessionsRequestBodyMode'EnumPayment
, Stripe.postCheckoutSessionsRequestBodyClientReferenceId = Just "some-booking-id"
}
lineItems = Stripe.mkPostCheckoutSessionsRequestBodyLineItems'
{ Stripe.postCheckoutSessionsRequestBodyLineItems'PriceData = Just priceData
, Stripe.postCheckoutSessionsRequestBodyLineItems'Quantity = Just 3
}
priceData = (Stripe.mkPostCheckoutSessionsRequestBodyLineItems'PriceData' "EUR")
{ Stripe.postCheckoutSessionsRequestBodyLineItems'PriceData'ProductData = Just productData
, Stripe.postCheckoutSessionsRequestBodyLineItems'PriceData'UnitAmount = Just 100
}
productData = Stripe.mkPostCheckoutSessionsRequestBodyLineItems'PriceData'ProductData' "foobar2000-î"
getCheckout = Stripe.postCheckoutSessions params
conf = Stripe.defaultConfiguration
{ Stripe.configSecurityScheme = Stripe.bearerAuthenticationSecurityScheme testStripeAPIKey
}
res <- Stripe.runWithConfiguration conf getCheckout
case HTTPClient.responseBody res of
Stripe.PostCheckoutSessionsResponse200 session -> do
let mPaymentIntentId = Stripe.checkout'sessionPaymentIntent session
mSessionUrl = Stripe.checkout'sessionUrl session
case (mSessionUrl, mPaymentIntentId) of
(Just _, Just (Stripe.Checkout'sessionPaymentIntent'Text _)) ->
pure ()
others -> expectationFailure $
"Did not find sessionPaymentIntent and sessionUrl in " <> show others
other -> expectationFailure $ "Did not find session response: " <> show other
1) ThirdParty.StripeAPI, checkout sessions, should contain a payment intent and a session url
Did not find session response: PostCheckoutSessionsResponseDefault (Error {errorError = ApiErrors {apiErrorsCharge = Nothing, apiErrorsCode = Just "invalid_utf8_in_post_body", apiErrorsDeclineCode = Nothing, apiErrorsDocUrl = Nothing, apiErrorsMessage = Just "Invalid UTF-8 characters found in POST body: \"foobar2000-\\xEE\". For assistance, please contact [email protected].", apiErrorsParam = Nothing, apiErrorsPaymentIntent = Nothing, apiErrorsPaymentMethod = Nothing, apiErrorsPaymentMethodType = Nothing, apiErrorsSetupIntent = Nothing, apiErrorsSource = Nothing, apiErrorsType = ApiErrorsType'EnumInvalidRequestError}})
I haven't really looked into this yet, just discovered the issue. Do you have any suggestion what's wrong here? Can you give me pointers?