dmjio / stripe

:moneybag: Stripe API
http://hackage.haskell.org/package/stripe-haskell
176 stars 74 forks source link

Passing the token from stripe.js #125

Open vu3rdd opened 4 years ago

vu3rdd commented 4 years ago

I am trying to call the stripe charge API. The frontend using the stripe.js gives me a token, which needs to be passed as source parameter to the API. Looking at the Web.Stripe.Charge module, I wonder how to do the equivalent step with the older version of the API. In the older version's documentation, there is an equivalent parameter called card. But I don't see how to pass it, the (Charge)[https://hackage.haskell.org/package/stripe-core-2.5.0/docs/Web-Stripe-Charge.html#t:Charge] data type do not seem to have a way to accept the token. Is there anything I am missing? Would appreciate any help. Thanks.

vu3rdd commented 4 years ago

Ok, this seem to do the trick. In the posted JSON, I see a card key and that would hopefully do the same job as the source key in the new API versions..

  let config = StripeConfig (StripeKey key) Nothing
      tokenId = TokenId token
  result <- liftIO $ stripe config $ do
    createCharge amount currency
      -&- tokenId