module Web.Stripe.Recipient
(
createRecipient
, createRecipientByCard
, createRecipientByToken
, createRecipientByBank
, createRecipientBase
, getRecipient
, getRecipientExpandable
, getRecipients
, getRecipientsExpandable
, updateRecipientName
, updateRecipientTaxID
, updateRecipientBankAccount
, updateRecipientTokenID
, updateRecipientDefaultCard
, updateRecipientEmail
, updateRecipientDescription
, updateRecipientMetaData
, updateRecipientBase
, deleteRecipient
, Recipient (..)
, RecipientId (..)
, FirstName (..)
, LastName (..)
, MiddleInitial
, RecipientType (..)
, TaxID
, BankAccount (..)
, TokenId
, CardNumber
, ExpMonth
, Email (..)
, ExpYear
, CVC
, Description
, Limit
, StripeDeleteResult (..)
, RoutingNumber (..)
, AccountNumber (..)
, Country (..)
, AddressCity (..)
, AddressCountry (..)
, AddressLine1 (..)
, AddressLine2 (..)
, AddressState (..)
, AddressZip (..)
, BankAccountId (..)
, BankAccountStatus (..)
) where
import Data.Monoid ((<>))
import qualified Data.Text as T
import Web.Stripe.Client.Internal (callAPI, Method(POST,GET,DELETE), Stripe,
StripeRequest(..), toMetaData, getParams,
toText, toExpandable, (</>))
import Web.Stripe.Types (AccountNumber (..),
BankAccount (..), CVC, CVC (..),
CardId (..), CardNumber, BankAccountId (..), BankAccountStatus(..),
CardNumber (..), Country (..),
Description, Email, Email (..),
ExpMonth, ExpMonth (..), ExpYear,
RoutingNumber (..), AccountNumber (..),
Country (..), AddressCity (..),
AddressCountry (..), AddressLine1 (..),
AddressLine2 (..), AddressState (..),
AddressZip (..), ExpYear (..),
FirstName (..), LastName (..), Limit,
MiddleInitial, Recipient (..),
RecipientId (..), ExpandParams,
RecipientType (..), StripeDeleteResult(..),
RoutingNumber (..), EndingBefore, StartingAfter,
StripeList (..), TaxID, TokenId,
TokenId (..), MetaData)
import Web.Stripe.Types.Util (getRecipientId)
createRecipientBase
:: FirstName
-> LastName
-> Maybe MiddleInitial
-> RecipientType
-> Maybe TaxID
-> Maybe Country
-> Maybe RoutingNumber
-> Maybe AccountNumber
-> Maybe TokenId
-> Maybe CardNumber
-> Maybe ExpMonth
-> Maybe ExpYear
-> Maybe CVC
-> Maybe Email
-> Maybe Description
-> MetaData
-> Stripe Recipient
createRecipientBase
(FirstName firstName)
(LastName lastName)
middleInitial
recipienttype
taxId
country
routingNumber
accountNumber
tokenId
cardNumber
expMonth
expYear
cvc
email
description
metadata = callAPI request
where request = StripeRequest POST url params
url = "recipients"
params =
let name = firstName <> middle <> lastName
middle = maybe " " (\x -> " " <> T.singleton x <> " ") middleInitial
in toMetaData metadata ++ getParams [
("name", Just name)
, ("type", toText `fmap` Just recipienttype)
, ("tax_id", taxId)
, ("bank_account[country]", (\(Country x) -> x) `fmap` country)
, ("bank_account[routing_number]", (\(RoutingNumber x ) -> x) `fmap` routingNumber)
, ("bank_account[account_number]", (\(AccountNumber x ) -> x) `fmap` accountNumber)
, ("card", (\(TokenId x) -> x) `fmap` tokenId)
, ("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)
, ("email", (\(Email x) -> x) `fmap` email)
, ("description", description)
]
createRecipient
:: FirstName
-> LastName
-> Maybe MiddleInitial
-> RecipientType
-> Stripe Recipient
createRecipient
firstName
lastName
middleInitial
recipienttype
= createRecipientBase firstName lastName middleInitial recipienttype
Nothing Nothing Nothing Nothing Nothing Nothing Nothing
Nothing Nothing Nothing Nothing []
createRecipientByCard
:: FirstName
-> LastName
-> Maybe MiddleInitial
-> RecipientType
-> CardNumber
-> ExpMonth
-> ExpYear
-> CVC
-> Stripe Recipient
createRecipientByCard
firstName
lastName
middleInitial
recipienttype
cardNumber
expMonth
expYear
cvc
= createRecipientBase firstName lastName middleInitial recipienttype
Nothing Nothing Nothing Nothing Nothing (Just cardNumber) (Just expMonth)
(Just expYear) (Just cvc) Nothing Nothing []
createRecipientByToken
:: FirstName
-> LastName
-> Maybe MiddleInitial
-> RecipientType
-> TokenId
-> Stripe Recipient
createRecipientByToken
firstName
lastName
middleInitial
recipienttype
tokenId
= createRecipientBase firstName lastName middleInitial recipienttype
Nothing Nothing Nothing Nothing (Just tokenId) Nothing Nothing
Nothing Nothing Nothing Nothing []
createRecipientByBank
:: FirstName
-> LastName
-> Maybe MiddleInitial
-> RecipientType
-> Country
-> RoutingNumber
-> AccountNumber
-> Stripe Recipient
createRecipientByBank
firstName
lastName
middleInitial
recipienttype
country
routingNumber
accountNumber
= createRecipientBase firstName lastName middleInitial recipienttype
Nothing (Just country) (Just routingNumber) (Just accountNumber) Nothing Nothing
Nothing Nothing Nothing Nothing Nothing []
getRecipient
:: RecipientId
-> Stripe Recipient
getRecipient
recipientid = getRecipientExpandable recipientid []
getRecipientExpandable
:: RecipientId
-> ExpandParams
-> Stripe Recipient
getRecipientExpandable
recipientid
expandParams = callAPI request
where request = StripeRequest GET url params
url = "recipients" </> getRecipientId recipientid
params = toExpandable expandParams
getRecipients
:: Limit
-> StartingAfter RecipientId
-> EndingBefore RecipientId
-> Stripe (StripeList Recipient)
getRecipients
limit
startingAfter
endingBefore =
getRecipientsExpandable
limit startingAfter endingBefore []
getRecipientsExpandable
:: Limit
-> StartingAfter RecipientId
-> EndingBefore RecipientId
-> ExpandParams
-> Stripe (StripeList Recipient)
getRecipientsExpandable
limit
startingAfter
endingBefore
expandParams = callAPI request
where request = StripeRequest GET url params
url = "recipients"
params = getParams [
("limit", toText `fmap` limit )
, ("starting_after", (\(RecipientId x) -> x) `fmap` startingAfter)
, ("ending_before", (\(RecipientId x) -> x) `fmap` endingBefore)
] ++ toExpandable expandParams
updateRecipientBase
:: RecipientId
-> Maybe FirstName
-> Maybe LastName
-> Maybe MiddleInitial
-> Maybe TaxID
-> Maybe Country
-> Maybe RoutingNumber
-> Maybe AccountNumber
-> Maybe TokenId
-> Maybe CardNumber
-> Maybe ExpMonth
-> Maybe ExpYear
-> Maybe CVC
-> Maybe CardId
-> Maybe Email
-> Maybe Description
-> MetaData
-> Stripe Recipient
updateRecipientBase
recipientid
firstName
lastName
middleInitial
taxId
country
routingNumber
accountNumber
tokenId
cardNumber
expMonth
expYear
cvc
cardId
email
description
metadata = callAPI request
where request = StripeRequest POST url params
url = "recipients" </> getRecipientId recipientid
params =
let name = if firstName == Nothing || lastName == Nothing
then Nothing
else do let Just (FirstName f) = firstName
Just (LastName l) = lastName
middle = maybe " " (\x -> " " <> T.singleton x <> " ") middleInitial
Just $ f <> middle <> l
in getParams [
("name", name)
, ("tax_id", taxId)
, ("bank_account[country]", (\(Country x) -> x) `fmap` country)
, ("bank_account[routing_number]", (\(RoutingNumber x ) -> x) `fmap` routingNumber)
, ("bank_account[account_number]", (\(AccountNumber x ) -> x) `fmap` accountNumber)
, ("card", (\(TokenId x) -> x) `fmap` tokenId)
, ("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)
, ("default_card", (\(CardId x) -> x) `fmap` cardId)
, ("email", (\(Email x) -> x) `fmap` email)
, ("description", description)
] ++ toMetaData metadata
updateRecipientName
:: RecipientId
-> FirstName
-> LastName
-> MiddleInitial
-> Stripe Recipient
updateRecipientName
recipientid
firstName
lastName
middleInitial = updateRecipientBase
recipientid (Just firstName) (Just lastName) (Just middleInitial)
Nothing Nothing Nothing Nothing
Nothing Nothing Nothing Nothing
Nothing Nothing Nothing Nothing []
updateRecipientBankAccount
:: RecipientId
-> Country
-> RoutingNumber
-> AccountNumber
-> Stripe Recipient
updateRecipientBankAccount
recipientid
country
routingNumber
accountNumber
= updateRecipientBase
recipientid Nothing Nothing Nothing
Nothing (Just country) (Just routingNumber)
(Just accountNumber) Nothing Nothing
Nothing Nothing Nothing Nothing
Nothing Nothing []
updateRecipientTaxID
:: RecipientId
-> TaxID
-> Stripe Recipient
updateRecipientTaxID
recipientid
taxID = updateRecipientBase
recipientid Nothing Nothing Nothing
(Just taxID) Nothing Nothing Nothing
Nothing Nothing Nothing Nothing
Nothing Nothing Nothing Nothing []
updateRecipientTokenID
:: RecipientId
-> TokenId
-> Stripe Recipient
updateRecipientTokenID
recipientid
tokenId = updateRecipientBase
recipientid Nothing Nothing Nothing
Nothing Nothing Nothing Nothing (Just tokenId) Nothing
Nothing Nothing Nothing Nothing Nothing Nothing []
updateRecipientDefaultCard
:: RecipientId
-> CardId
-> Stripe Recipient
updateRecipientDefaultCard
recipientid
cardId = updateRecipientBase
recipientid Nothing Nothing Nothing Nothing
Nothing Nothing Nothing Nothing
Nothing Nothing Nothing Nothing
(Just cardId) Nothing Nothing []
updateRecipientEmail
:: RecipientId
-> Email
-> Stripe Recipient
updateRecipientEmail
recipientid
email = updateRecipientBase
recipientid Nothing Nothing Nothing Nothing
Nothing Nothing Nothing Nothing
Nothing Nothing Nothing Nothing
Nothing (Just email) Nothing []
updateRecipientDescription
:: RecipientId
-> Description
-> Stripe Recipient
updateRecipientDescription
recipientid
description = updateRecipientBase
recipientid Nothing Nothing Nothing Nothing
Nothing Nothing Nothing Nothing
Nothing Nothing Nothing Nothing
Nothing Nothing (Just description) []
updateRecipientMetaData
:: RecipientId
-> MetaData
-> Stripe Recipient
updateRecipientMetaData
recipientid
metadata = updateRecipientBase
recipientid Nothing Nothing Nothing Nothing
Nothing Nothing Nothing Nothing
Nothing Nothing Nothing Nothing
Nothing Nothing Nothing metadata
deleteRecipient
:: RecipientId
-> Stripe StripeDeleteResult
deleteRecipient
recipientid = callAPI request
where request = StripeRequest DELETE url params
url = "recipients" </> getRecipientId recipientid
params = []