module Web.Stripe.Customer
(
createEmptyCustomer
, createCustomerByEmail
, createCustomerByToken
, createCustomerByCard
, createCustomerBase
, updateCustomerBase
, updateCustomerAccountBalance
, updateCustomerDefaultCard
, deleteCustomer
, getCustomer
, getCustomerExpandable
, getCustomers
, getCustomersExpandable
, Customer (..)
, CustomerId (..)
, CardId (..)
, StripeList (..)
, TokenId (..)
, CardNumber (..)
, ExpMonth (..)
, ExpYear (..)
, CVC (..)
, CouponId (..)
, Email (..)
, PlanId (..)
, Quantity (..)
, StripeDeleteResult (..)
, TrialPeriod (..)
, Description
, AccountBalance
, Limit
) where
import Web.Stripe.Client.Internal (Method (GET, POST, DELETE), Stripe,
StripeRequest (..), callAPI, toMetaData,
toSeconds, getParams, toText, (</>), toExpandable)
import Web.Stripe.Types (AccountBalance, CVC (..),
CardId (..), CardNumber (..),
CouponId (..), Customer (..),
CustomerId (..), Description,
Email (..), EndingBefore,
ExpMonth (..), ExpYear (..), Limit,
PlanId (..), Quantity (..), MetaData,
StartingAfter,
StripeDeleteResult (..),
StripeList (..), TokenId (..),
TrialPeriod(..), ExpandParams)
import Web.Stripe.Types.Util
createCustomerBase
:: Maybe AccountBalance
-> Maybe TokenId
-> Maybe CardNumber
-> Maybe ExpMonth
-> Maybe ExpYear
-> Maybe CVC
-> Maybe CouponId
-> Maybe Description
-> Maybe Email
-> Maybe PlanId
-> Maybe Quantity
-> Maybe TrialPeriod
-> MetaData
-> Stripe Customer
createCustomerBase
accountBalance
cardId
cardNumber
expMonth
expYear
cvc
couponId
description
email
planId
quantity
trialEnd
metadata = callAPI request
where request = StripeRequest POST "customers" params
params = toMetaData metadata ++ getParams [
("account_balance", toText `fmap` accountBalance)
, ("card", (\(TokenId x) -> x) `fmap` cardId)
, ("card[number]", (\(CardNumber x) -> x) `fmap` cardNumber)
, ("card[exp_month]", (\(ExpMonth x) -> toText x) `fmap` expMonth)
, ("card[exp_year]", (\(ExpYear x) -> toText x) `fmap` expYear)
, ("card[cvc]", (\(CVC x) -> x) `fmap` cvc)
, ("coupon", (\(CouponId x) -> x) `fmap` couponId)
, ("description", description)
, ("email", (\(Email x) -> x) `fmap` email)
, ("plan", (\(PlanId x) -> x) `fmap` planId)
, ("quantity", (\(Quantity x) -> toText x) `fmap` quantity)
, ("trial_end", (\(TrialPeriod x) -> toText $ toSeconds x) `fmap` trialEnd)
]
createCustomerByEmail
:: Email
-> Stripe Customer
createCustomerByEmail e =
createCustomerBase Nothing Nothing Nothing Nothing
Nothing Nothing Nothing Nothing
(Just e) Nothing Nothing Nothing []
createEmptyCustomer
:: Stripe Customer
createEmptyCustomer =
createCustomerBase Nothing Nothing Nothing Nothing
Nothing Nothing Nothing Nothing
Nothing Nothing Nothing Nothing []
createCustomerByToken
:: TokenId
-> Stripe Customer
createCustomerByToken t =
createCustomerBase Nothing (Just t) Nothing Nothing
Nothing Nothing Nothing Nothing
Nothing Nothing Nothing Nothing []
createCustomerByCard
:: CardNumber
-> ExpMonth
-> ExpYear
-> CVC
-> Stripe Customer
createCustomerByCard
cardNumber
expMonth
expYear
cvc = createCustomerBase Nothing Nothing (Just cardNumber) (Just expMonth)
(Just expYear) (Just cvc) Nothing Nothing
Nothing Nothing Nothing Nothing []
updateCustomerBase
:: CustomerId
-> Maybe AccountBalance
-> Maybe TokenId
-> Maybe CardNumber
-> Maybe ExpMonth
-> Maybe ExpYear
-> Maybe CVC
-> Maybe CouponId
-> Maybe CardId
-> Maybe Description
-> Maybe Email
-> MetaData
-> Stripe Customer
updateCustomerBase
customerid
accountBalance
cardId
cardNumber
expMonth
expYear
cvc
couponId
defaultCardId
description
email
metadata = callAPI request
where request = StripeRequest POST url params
url = "customers" </> getCustomerId customerid
params = toMetaData metadata ++ getParams [
("account_balance", toText `fmap` accountBalance)
, ("card", (\(TokenId x) -> x) `fmap` cardId)
, ("card[number]", (\(CardNumber x) -> x) `fmap` cardNumber)
, ("card[exp_month]", (\(ExpMonth x) -> toText x) `fmap` expMonth)
, ("card[exp_year]", (\(ExpYear x) -> toText x) `fmap` expYear)
, ("card[cvc]", (\(CVC x) -> x) `fmap` cvc)
, ("coupon", (\(CouponId x) -> x) `fmap` couponId)
, ("default_card", (\(CardId x) -> x) `fmap` defaultCardId)
, ("description", description)
, ("email", (\(Email x) -> x) `fmap` email)
]
updateCustomerAccountBalance
:: CustomerId
-> AccountBalance
-> Stripe Customer
updateCustomerAccountBalance
customerid
accountbalance
= updateCustomerBase customerid (Just accountbalance)
Nothing Nothing Nothing
Nothing Nothing Nothing
Nothing Nothing Nothing []
updateCustomerDefaultCard
:: CustomerId
-> CardId
-> Stripe Customer
updateCustomerDefaultCard
customerId
defaultCard
= updateCustomerBase customerId Nothing
Nothing Nothing Nothing
Nothing Nothing Nothing
(Just defaultCard) Nothing Nothing []
deleteCustomer
:: CustomerId
-> Stripe StripeDeleteResult
deleteCustomer customerid = callAPI request
where request = StripeRequest DELETE url params
url = "customers" </> getCustomerId customerid
params = []
getCustomer
:: CustomerId
-> Stripe Customer
getCustomer customerid =
getCustomerExpandable customerid []
getCustomerExpandable
:: CustomerId
-> ExpandParams
-> Stripe Customer
getCustomerExpandable
customerid
expandParams = callAPI request
where request = StripeRequest GET url params
url = "customers" </> getCustomerId customerid
params = toExpandable expandParams
getCustomers
:: Limit
-> StartingAfter CustomerId
-> EndingBefore CustomerId
-> Stripe (StripeList Customer)
getCustomers
limit
startingAfter
endingBefore =
getCustomersExpandable limit startingAfter endingBefore []
getCustomersExpandable
:: Limit
-> StartingAfter CustomerId
-> EndingBefore CustomerId
-> ExpandParams
-> Stripe (StripeList Customer)
getCustomersExpandable
limit
startingAfter
endingBefore
expandParams = callAPI request
where request = StripeRequest GET url params
url = "customers"
params = getParams [
("limit", toText `fmap` limit )
, ("starting_after", (\(CustomerId x) -> x) `fmap` startingAfter)
, ("ending_before", (\(CustomerId x) -> x) `fmap` endingBefore)
] ++ toExpandable expandParams