module Web.Stripe.Card
(
createCustomerCard
, createCustomerCardByToken
, getCustomerCard
, getCustomerCardExpandable
, getCustomerCards
, getCustomerCardsExpandable
, updateCustomerCard
, deleteCustomerCard
, createRecipientCard
, createRecipientCardByToken
, getRecipientCard
, getRecipientCardExpandable
, getRecipientCards
, getRecipientCardsExpandable
, updateRecipientCard
, deleteRecipientCard
, Brand (..)
, Card (..)
, RecipientCard (..)
, CardId (..)
, RecipientCardId (..)
, CardNumber (..)
, ExpMonth (..)
, ExpYear (..)
, CVC (..)
, Name
, AddressLine1 (..)
, AddressLine2 (..)
, AddressCity (..)
, AddressCountry (..)
, AddressState (..)
, AddressZip (..)
, RecipientId (..)
) where
import Control.Applicative ((<$>))
import Data.Aeson (FromJSON)
import Web.Stripe.Client.Internal
import Web.Stripe.Types
import Web.Stripe.Types.Util
createCardBase
:: FromJSON a
=> URL
-> ID
-> Maybe TokenId
-> Maybe CardNumber
-> Maybe ExpMonth
-> Maybe ExpYear
-> Maybe CVC
-> Maybe Name
-> Maybe AddressCity
-> Maybe AddressCountry
-> Maybe AddressLine1
-> Maybe AddressLine2
-> Maybe AddressState
-> Maybe AddressZip
-> Stripe a
createCardBase
requestType
requestId
tokenid
cardNumber
expMonth
expYear
cvc
name
addressCity
addressCountry
addressLine1
addressLine2
addressState
addressZip = callAPI request
where request = StripeRequest POST url params
url = requestType </> requestId </> "cards"
params = getParams [
("card", (\(TokenId x) -> x) <$> tokenid)
, ("card[number]", (\(CardNumber x) -> x) <$> cardNumber)
, ("card[exp_month]", (\(ExpMonth x) -> toText x) <$> expMonth)
, ("card[exp_year]", (\(ExpYear x) -> toText x) <$> expYear)
, ("card[cvc]", (\(CVC x) -> x) <$> cvc)
, ("name", name)
, ("address_city", (\(AddressCity x) -> x) <$> addressCity)
, ("address_country", (\(AddressCountry x) -> x) <$> addressCountry)
, ("address_line1", (\(AddressLine1 x) -> x) <$> addressLine1 )
, ("address_line2", (\(AddressLine2 x) -> x) <$> addressLine2 )
, ("address_state", (\(AddressState x) -> x) <$> addressState )
, ("address_zip", (\(AddressZip x) -> x) <$> addressZip )
]
createCustomerCardByToken
:: CustomerId
-> TokenId
-> Stripe Card
createCustomerCardByToken
customerid
tokenid = createCardBase "customers" (getCustomerId customerid) (Just tokenid)
Nothing Nothing Nothing
Nothing Nothing Nothing
Nothing Nothing Nothing
Nothing Nothing
createRecipientCardByToken
:: RecipientId
-> TokenId
-> Stripe RecipientCard
createRecipientCardByToken
recipientid
tokenid = createCardBase "recipients" (getRecipientId recipientid) (Just tokenid)
Nothing Nothing Nothing
Nothing Nothing Nothing
Nothing Nothing Nothing
Nothing Nothing
createCustomerCard
:: CustomerId
-> CardNumber
-> ExpMonth
-> ExpYear
-> CVC
-> Stripe Card
createCustomerCard
customerid
cardNumber
expMonth
expYear
cvc = createCardBase "customers" (getCustomerId customerid) Nothing
(Just cardNumber) (Just expMonth) (Just expYear)
(Just cvc) Nothing Nothing
Nothing Nothing Nothing
Nothing Nothing
createRecipientCard
:: RecipientId
-> CardNumber
-> ExpMonth
-> ExpYear
-> CVC
-> Stripe RecipientCard
createRecipientCard
recipientid
cardNumber
expMonth
expYear
cvc = createCardBase "recipients" (getRecipientId recipientid) Nothing
(Just cardNumber) (Just expMonth) (Just expYear)
(Just cvc) Nothing Nothing
Nothing Nothing Nothing
Nothing Nothing
updateCardBase
:: FromJSON a
=> URL
-> ID
-> Either CardId RecipientCardId
-> Maybe Name
-> Maybe AddressCity
-> Maybe AddressCountry
-> Maybe AddressLine1
-> Maybe AddressLine2
-> Maybe AddressState
-> Maybe AddressZip
-> Stripe a
updateCardBase
requestType
requestId
cardid
name
addressCity
addressCountry
addressLine1
addressLine2
addressState
addressZip = callAPI request
where request = StripeRequest POST url params
url = requestType </> requestId </> "cards" </> case cardid of
Right x -> getRecipientCardId x
Left x -> getCardId x
params = getParams [
("name", name)
, ("address_city", (\(AddressCity x) -> x) <$> addressCity)
, ("address_country", (\(AddressCountry x) -> x) <$> addressCountry)
, ("address_line1", (\(AddressLine1 x) -> x) <$> addressLine1 )
, ("address_line2", (\(AddressLine2 x) -> x) <$> addressLine2 )
, ("address_state", (\(AddressState x) -> x) <$> addressState )
, ("address_zip", (\(AddressZip x) -> x) <$> addressZip )
]
updateCustomerCard
:: CustomerId
-> CardId
-> Maybe Name
-> Maybe AddressCity
-> Maybe AddressCountry
-> Maybe AddressLine1
-> Maybe AddressLine2
-> Maybe AddressState
-> Maybe AddressZip
-> Stripe Card
updateCustomerCard
customerid
cardid = updateCardBase "customers" (getCustomerId customerid) (Left cardid)
updateRecipientCard
:: RecipientId
-> RecipientCardId
-> Maybe Name
-> Maybe AddressCity
-> Maybe AddressCountry
-> Maybe AddressLine1
-> Maybe AddressLine2
-> Maybe AddressState
-> Maybe AddressZip
-> Stripe RecipientCard
updateRecipientCard
recipientid
cardid = updateCardBase "recipients" (getRecipientId recipientid) (Right cardid)
getCardBase
:: FromJSON a
=> URL
-> ID
-> ID
-> ExpandParams
-> Stripe a
getCardBase
requestType
requestId
cardid
expandParams = callAPI request
where request = StripeRequest GET url params
url = requestType </> requestId </> "cards" </> cardid
params = toExpandable expandParams
getCustomerCard
:: CustomerId
-> CardId
-> Stripe Card
getCustomerCard
customerid cardid = getCustomerCardExpandable customerid cardid []
getCustomerCardExpandable
:: CustomerId
-> CardId
-> ExpandParams
-> Stripe Card
getCustomerCardExpandable
customerid cardid expandParams =
getCardBase "customers" (getCustomerId customerid) (getCardId cardid) expandParams
getRecipientCard
:: RecipientId
-> RecipientCardId
-> Stripe RecipientCard
getRecipientCard
recipientid
cardid = getRecipientCardExpandable recipientid cardid []
getRecipientCardExpandable
:: RecipientId
-> RecipientCardId
-> ExpandParams
-> Stripe RecipientCard
getRecipientCardExpandable
recipientid
cardid
expandParams
= getCardBase "recipients" (getRecipientId recipientid)
(getRecipientCardId cardid) expandParams
getCustomerCardsBase
:: CustomerId
-> Maybe Limit
-> StartingAfter CardId
-> EndingBefore CardId
-> ExpandParams
-> Stripe (StripeList Card)
getCustomerCardsBase
customerid
limit
startingAfter
endingBefore
expandParams = callAPI request
where request = StripeRequest GET url params
url = "customers" </> getCustomerId customerid </> "cards"
params = getParams [
("limit", toText `fmap` limit )
, ("starting_after", (\(CardId x) -> x) `fmap` startingAfter)
, ("ending_before", (\(CardId x) -> x) `fmap` endingBefore)
] ++ toExpandable expandParams
getRecipientCardsBase
:: RecipientId
-> Maybe Limit
-> StartingAfter RecipientCardId
-> EndingBefore RecipientCardId
-> ExpandParams
-> Stripe (StripeList RecipientCard)
getRecipientCardsBase
recipientid
limit
startingAfter
endingBefore
expandParams = callAPI request
where request = StripeRequest GET url params
url = "recipients" </> getRecipientId recipientid </> "cards"
params = getParams [
("limit", toText `fmap` limit )
, ("starting_after", (\(RecipientCardId x) -> x) `fmap` startingAfter)
, ("ending_before", (\(RecipientCardId x) -> x) `fmap` endingBefore)
] ++ toExpandable expandParams
getCustomerCards
:: CustomerId
-> Maybe Limit
-> StartingAfter CardId
-> EndingBefore CardId
-> Stripe (StripeList Card)
getCustomerCards
customerid
limit
startingAfter
endingBefore
= getCustomerCardsExpandable customerid limit startingAfter endingBefore []
getCustomerCardsExpandable
:: CustomerId
-> Maybe Limit
-> StartingAfter CardId
-> EndingBefore CardId
-> ExpandParams
-> Stripe (StripeList Card)
getCustomerCardsExpandable
customerid
limit
startingAfter
endingBefore
expandParams =
getCustomerCardsBase customerid
limit startingAfter endingBefore expandParams
getRecipientCards
:: RecipientId
-> Maybe Limit
-> StartingAfter RecipientCardId
-> EndingBefore RecipientCardId
-> Stripe (StripeList RecipientCard)
getRecipientCards
recipientid
limit
startingAfter
endingBefore =
getRecipientCardsExpandable recipientid limit
startingAfter endingBefore []
getRecipientCardsExpandable
:: RecipientId
-> Maybe Limit
-> StartingAfter RecipientCardId
-> EndingBefore RecipientCardId
-> ExpandParams
-> Stripe (StripeList RecipientCard)
getRecipientCardsExpandable
recipientid
limit
startingAfter
endingBefore
expandParams =
getRecipientCardsBase recipientid
limit startingAfter endingBefore expandParams
deleteCustomerCard
:: CustomerId
-> CardId
-> Stripe StripeDeleteResult
deleteCustomerCard
customerid
cardid = callAPI request
where request = StripeRequest DELETE url params
url = "customers" </> getCustomerId customerid </> "cards" </> getCardId cardid
params = []
deleteRecipientCard
:: RecipientId
-> RecipientCardId
-> Stripe StripeDeleteResult
deleteRecipientCard
recipientid
cardid = callAPI request
where request = StripeRequest DELETE url params
url = "recipients" </> getRecipientId recipientid
</> "cards"
</> getRecipientCardId cardid
params = []