{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}
module Web.Stripe.Token
(
CreateCardToken
, createCardToken
, CreateBankAccountToken
, createBankAccountToken
, GetCardToken
, getCardToken
, GetBankAccountToken
, getBankAccountToken
, Account (..)
, AccountNumber (..)
, BankAccount (..)
, Card (..)
, CardNumber (..)
, Country (..)
, CustomerId (..)
, CVC (..)
, ExpMonth (..)
, ExpYear (..)
, NewBankAccount (..)
, mkNewCard
, NewCard (..)
, RoutingNumber (..)
, Token (..)
, TokenId (..)
, TokenType (..)
) where
import Web.Stripe.StripeRequest (Method (GET, POST),
StripeHasParam, StripeRequest (..),
StripeReturn, ToStripeParam(..),
mkStripeRequest)
import Web.Stripe.Util ((</>))
import Web.Stripe.Types (Account(..), AccountNumber (..),
CVC (..), CardNumber (..), CustomerId(..),
Country (..), ExpMonth (..),
BankAccount(..), ExpYear (..),
NewBankAccount(..), mkNewCard,
NewCard(..), RoutingNumber (..),
Card(..), Token (..),
TokenId (..), TokenType(..)
)
createCardToken
:: Maybe NewCard
-> StripeRequest CreateCardToken
createCardToken
newCard
= request
where request = mkStripeRequest POST url params
url = "tokens"
params = maybe id toStripeParam newCard $ []
data CreateCardToken
type instance StripeReturn CreateCardToken = Token Card
instance StripeHasParam CreateCardToken CustomerId
createBankAccountToken
:: Maybe NewBankAccount
-> StripeRequest CreateBankAccountToken
createBankAccountToken
newBankAccount
= request
where request = mkStripeRequest POST url params
url = "tokens"
params = maybe id toStripeParam newBankAccount $ []
data CreateBankAccountToken
type instance StripeReturn CreateBankAccountToken = Token BankAccount
getCardToken
:: TokenId
-> StripeRequest GetCardToken
getCardToken (TokenId token) = request
where request = mkStripeRequest GET url params
url = "tokens" </> token
params = []
data GetCardToken
type instance StripeReturn GetCardToken = Token Card
getBankAccountToken
:: TokenId
-> StripeRequest GetBankAccountToken
getBankAccountToken (TokenId token) = request
where request = mkStripeRequest GET url params
url = "tokens" </> token
params = []
data GetBankAccountToken
type instance StripeReturn GetBankAccountToken = Token BankAccount