| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Web.Payments.Cielo
Contents
- runCielo :: CieloConfig -> CieloM a -> IO a
- cieloConfigFromEnv :: IO CieloConfig
- productionEnv :: Environment
- sandboxEnv :: Environment
- getMerchantOrderId :: MonadIO m => m Text
- createSale :: MonadCielo m => Sale -> m Sale
- querySale :: MonadCielo m => Text -> m Sale
- captureSale :: MonadCielo m => Text -> Maybe Int -> Maybe Int -> m SaleUpdate
- voidSale :: MonadCielo m => Text -> Maybe Int -> m SaleUpdate
- updateSale :: MonadCielo m => Text -> Text -> [(Text, Text)] -> m SaleUpdate
- querySalesByMerchantOrderId :: MonadCielo m => Text -> m SalesByMerchantOrderQuery
- queryRecurrentSale :: MonadCielo m => Text -> m RecurrentPaymentQuery
- cancelRecurrentPayment :: MonadCielo m => Text -> m ()
- uncancelRecurrentPayment :: MonadCielo m => Text -> m ()
- updateRecurrentPaymentEndDate :: MonadCielo m => Text -> Text -> m ()
- updateRecurrentPaymentPayment :: MonadCielo m => Text -> Payment -> m ()
- updateRecurrentPaymentInterval :: MonadCielo m => Text -> Int -> m ()
- updateRecurrentPaymentInstallments :: MonadCielo m => Text -> Int -> m ()
- updateRecurrentPaymentCustomer :: MonadCielo m => Text -> Customer -> m ()
- updateRecurrentPaymentRecurrencyDay :: MonadCielo m => Text -> Int -> m ()
- updateRecurrentPaymentNextPaymentDate :: MonadCielo m => Text -> Text -> m ()
- updateRecurrentPaymentNextPaymentAmount :: MonadCielo m => Text -> Int -> m ()
- data CieloConfig = CieloConfig {}
- data CreditCard = CreditCard {}
- type MonadCielo m = (MonadIO m, MonadReader CieloConfig m, MonadError CieloError m)
- data CieloError
- data Merchant = Merchant {
- merchantId :: Text
- merchantKey :: Text
- data Environment = Environment {}
- data Sale = Sale {}
- data PaymentProvider
- data PaymentType
- data Currency
- data Interval
- data RecurrentPayment = RecurrentPayment {}
- data RecurrentPaymentQuery = RecurrentPaymentQuery {}
- data Address = Address {}
- data Customer = Customer {}
- data Payment = Payment {
- paymentServiceTaxAmount :: Maybe Int
- paymentInstallments :: Maybe Int
- paymentInterest :: Maybe Value
- paymentCreditCard :: Maybe CreditCard
- paymentType :: Maybe PaymentType
- paymentAmount :: Maybe Int
- paymentCapture :: Maybe Bool
- paymentAuthenticate :: Maybe Bool
- paymentRecurrent :: Maybe Bool
- paymentRecurrentPayment :: Maybe RecurrentPayment
- paymentTid :: Maybe Text
- paymentProofOfSale :: Maybe Text
- paymentAuthorizationCode :: Maybe Text
- paymentSoftDescriptor :: Maybe Text
- paymentReturnUrl :: Maybe Text
- paymentProvider :: Maybe PaymentProvider
- paymentPaymentId :: Maybe Text
- paymentReceivedDate :: Maybe Text
- paymentCapturedAmount :: Maybe Int
- paymentCapturedDate :: Maybe Text
- paymentCurrency :: Maybe Currency
- paymentCountry :: Maybe Text
- paymentReturnCode :: Maybe Text
- paymentReturnMessage :: Maybe Text
- paymentStatus :: Maybe Int
- paymentLinks :: Maybe [Value]
- paymentExtraDataCollection :: Maybe [Value]
- paymentExpirationDate :: Maybe Text
- paymentUrl :: Maybe Text
- paymentNumber :: Maybe Text
- paymentBarCodeNumber :: Maybe Text
- paymentDigitableLine :: Maybe Text
- paymentAddress :: Maybe Text
- data SalesByMerchantOrderQuery = SalesByMerchantOrderQuery {}
- class Default a where
- class Monad m => MonadIO m where
- liftIO :: MonadIO m => forall a. IO a -> m a
- class FromJSON a where
- class ToJSON a where
Running the API calls
runCielo :: CieloConfig -> CieloM a -> IO a Source #
API Calls happen in a MonadCielo type-class
CieloM is a helper instance of this class, which runs exceptions on the IO
monad and exposes the configuration through a ReaderT
cieloConfigFromEnv :: IO CieloConfig Source #
We can load CieloConfig from the CIELO_MERCHANTID and
CIELO_MERCHANTKEY environment variables
Available API Calls
Generating Merchant Order IDs
getMerchantOrderId :: MonadIO m => m Text Source #
Generates a new merchant UIID
Sales
createSale :: MonadCielo m => Sale -> m Sale Source #
Creates a Sale
Arguments
| :: MonadCielo m | |
| => Text | Payment ID |
| -> Maybe Int | Amount |
| -> Maybe Int | Service Tax Amount |
| -> m SaleUpdate |
Captures a sale
Arguments
| :: MonadCielo m | |
| => Text | Payment ID |
| -> Maybe Int | Amount |
| -> m SaleUpdate |
Voids a sale
Low-Level
Arguments
| :: MonadCielo m | |
| => Text | Payment ID |
| -> Text | :type |
| -> [(Text, Text)] | Data to PUT |
| -> m SaleUpdate |
Updates a sale (Generalized PUT over a type of Sale update 1sales:id:type)
Querying Sales
querySalesByMerchantOrderId :: MonadCielo m => Text -> m SalesByMerchantOrderQuery Source #
Queries for a sales given a merchant UUID
queryRecurrentSale :: MonadCielo m => Text -> m RecurrentPaymentQuery Source #
Queries for a recurrent sale given it's paymentId
Recurrent Sales
Cancelling / Uncancelling
cancelRecurrentPayment :: MonadCielo m => Text -> m () Source #
uncancelRecurrentPayment :: MonadCielo m => Text -> m () Source #
Updates
updateRecurrentPaymentEndDate :: MonadCielo m => Text -> Text -> m () Source #
updateRecurrentPaymentPayment :: MonadCielo m => Text -> Payment -> m () Source #
updateRecurrentPaymentInterval :: MonadCielo m => Text -> Int -> m () Source #
updateRecurrentPaymentInstallments :: MonadCielo m => Text -> Int -> m () Source #
updateRecurrentPaymentCustomer :: MonadCielo m => Text -> Customer -> m () Source #
updateRecurrentPaymentRecurrencyDay :: MonadCielo m => Text -> Int -> m () Source #
updateRecurrentPaymentNextPaymentDate :: MonadCielo m => Text -> Text -> m () Source #
updateRecurrentPaymentNextPaymentAmount :: MonadCielo m => Text -> Int -> m () Source #
Types
data CieloConfig Source #
Constructors
| CieloConfig | |
Fields | |
data CreditCard Source #
Constructors
| CreditCard | |
type MonadCielo m = (MonadIO m, MonadReader CieloConfig m, MonadError CieloError m) Source #
data CieloError Source #
Constructors
| CieloJSONError String SomeException ByteString | |
| CieloInvalidError String HttpException (Maybe Value) | |
| CieloNotFoundError String HttpException | |
| CieloHttpException String HttpException (Maybe Value) |
Instances
Constructors
| Merchant | |
Fields
| |
Constructors
| Sale | |
Fields | |
data PaymentProvider Source #
data PaymentType Source #
data RecurrentPayment Source #
Constructors
| RecurrentPayment | |
data RecurrentPaymentQuery Source #
Constructors
| RecurrentPaymentQuery | |
Constructors
| Address | |
Fields
| |
Constructors
| Customer | |
Fields | |
Constructors
data SalesByMerchantOrderQuery Source #
Constructors
| SalesByMerchantOrderQuery | |
Fields | |
Re-exports
A class for types with a default value.
Instances
class Monad m => MonadIO m where #
Monads in which IO computations may be embedded.
Any monad built by applying a sequence of monad transformers to the
IO monad will be an instance of this class.
Instances should satisfy the following laws, which state that liftIO
is a transformer of monads:
Minimal complete definition
Instances
| MonadIO IO | |
| MonadIO m => MonadIO (ListT m) | |
| MonadIO m => MonadIO (MaybeT m) | |
| MonadIO m => MonadIO (IdentityT * m) | |
| (Functor f, MonadIO m) => MonadIO (FreeT f m) | |
| (Error e, MonadIO m) => MonadIO (ErrorT e m) | |
| MonadIO m => MonadIO (ExceptT e m) | |
| MonadIO m => MonadIO (StateT s m) | |
| MonadIO m => MonadIO (StateT s m) | |
| (Monoid w, MonadIO m) => MonadIO (WriterT w m) | |
| (Monoid w, MonadIO m) => MonadIO (WriterT w m) | |
| MonadIO m => MonadIO (ContT * r m) | |
| MonadIO m => MonadIO (ReaderT * r m) | |
| (Monoid w, MonadIO m) => MonadIO (RWST r w s m) | |
| (Monoid w, MonadIO m) => MonadIO (RWST r w s m) | |
A type that can be converted from JSON, with the possibility of failure.
In many cases, you can get the compiler to generate parsing code for you (see below). To begin, let's cover writing an instance by hand.
There are various reasons a conversion could fail. For example, an
Object could be missing a required key, an Array could be of
the wrong size, or a value could be of an incompatible type.
The basic ways to signal a failed conversion are as follows:
emptyandmzerowork, but are terse and uninformativefailyields a custom error messagetypeMismatchproduces an informative message for cases when the value encountered is not of the expected type
An example type and instance:
-- Allow ourselves to writeTextliterals. {-# LANGUAGE OverloadedStrings #-} data Coord = Coord { x :: Double, y :: Double } instance FromJSON Coord where parseJSON (Objectv) = Coord<$>v.:"x"<*>v.:"y" -- We do not expect a non-Objectvalue here. -- We could usemzeroto fail, buttypeMismatch-- gives a much more informative error message. parseJSON invalid =typeMismatch"Coord" invalid
Instead of manually writing your FromJSON instance, there are two options
to do it automatically:
- Data.Aeson.TH provides Template Haskell functions which will derive an instance at compile time. The generated instance is optimized for your type so will probably be more efficient than the following two options:
- The compiler can provide a default generic implementation for
parseJSON.
To use the second, simply add a deriving clause to your
datatype and declare a GenericFromJSON instance for your datatype without giving
a definition for parseJSON.
For example, the previous example can be simplified to just:
{-# LANGUAGE DeriveGeneric #-}
import GHC.Generics
data Coord = Coord { x :: Double, y :: Double } deriving Generic
instance FromJSON Coord
If DefaultSignatures doesn't give exactly the results you want,
you can customize the generic decoding with only a tiny amount of
effort, using genericParseJSON with your preferred Options:
instance FromJSON Coord where
parseJSON = genericParseJSON defaultOptions
Instances
A type that can be converted to JSON.
An example type and instance:
-- Allow ourselves to writeTextliterals. {-# LANGUAGE OverloadedStrings #-} data Coord = Coord { x :: Double, y :: Double } instance ToJSON Coord where toJSON (Coord x y) =object["x".=x, "y".=y] toEncoding (Coord x y) =pairs("x".=x<>"y".=y)
Instead of manually writing your ToJSON instance, there are two options
to do it automatically:
- Data.Aeson.TH provides Template Haskell functions which will derive an instance at compile time. The generated instance is optimized for your type so will probably be more efficient than the following two options:
- The compiler can provide a default generic implementation for
toJSON.
To use the second, simply add a deriving clause to your
datatype and declare a GenericToJSON instance for your datatype without giving
definitions for toJSON or toEncoding.
For example, the previous example can be simplified to a more minimal instance:
{-# LANGUAGE DeriveGeneric #-}
import GHC.Generics
data Coord = Coord { x :: Double, y :: Double } deriving Generic
instance ToJSON Coord where
toEncoding = genericToEncoding defaultOptions
Why do we provide an implementation for toEncoding here? The
toEncoding function is a relatively new addition to this class.
To allow users of older versions of this library to upgrade without
having to edit all of their instances or encounter surprising
incompatibilities, the default implementation of toEncoding uses
toJSON. This produces correct results, but since it performs an
intermediate conversion to a Value, it will be less efficient
than directly emitting an Encoding. Our one-liner definition of
toEncoding above bypasses the intermediate Value.
If DefaultSignatures doesn't give exactly the results you want,
you can customize the generic encoding with only a tiny amount of
effort, using genericToJSON and genericToEncoding with your
preferred Options:
instance ToJSON Coord where
toJSON = genericToJSON defaultOptions
toEncoding = genericToEncoding defaultOptions
Methods
Convert a Haskell value to a JSON-friendly intermediate type.
toEncoding :: a -> Encoding #
Encode a Haskell value as JSON.
The default implementation of this method creates an
intermediate Value using toJSON. This provides
source-level compatibility for people upgrading from older
versions of this library, but obviously offers no performance
advantage.
To benefit from direct encoding, you must provide an
implementation for this method. The easiest way to do so is by
having your types implement Generic using the DeriveGeneric
extension, and then have GHC generate a method body as follows.
instance ToJSON Coord where
toEncoding = genericToEncoding defaultOptions
toJSONList :: [a] -> Value #
toEncodingList :: [a] -> Encoding #
Instances