{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.MarketplaceMetering.ResolveCustomer
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- ResolveCustomer is called by a SaaS application during the registration
-- process. When a buyer visits your website during the registration
-- process, the buyer submits a registration token through their browser.
-- The registration token is resolved through this API to obtain a
-- CustomerIdentifier and product code.
module Amazonka.MarketplaceMetering.ResolveCustomer
  ( -- * Creating a Request
    ResolveCustomer (..),
    newResolveCustomer,

    -- * Request Lenses
    resolveCustomer_registrationToken,

    -- * Destructuring the Response
    ResolveCustomerResponse (..),
    newResolveCustomerResponse,

    -- * Response Lenses
    resolveCustomerResponse_customerIdentifier,
    resolveCustomerResponse_productCode,
    resolveCustomerResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.MarketplaceMetering.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | Contains input to the ResolveCustomer operation.
--
-- /See:/ 'newResolveCustomer' smart constructor.
data ResolveCustomer = ResolveCustomer'
  { -- | When a buyer visits your website during the registration process, the
    -- buyer submits a registration token through the browser. The registration
    -- token is resolved to obtain a CustomerIdentifier and product code.
    ResolveCustomer -> Text
registrationToken :: Prelude.Text
  }
  deriving (ResolveCustomer -> ResolveCustomer -> Bool
(ResolveCustomer -> ResolveCustomer -> Bool)
-> (ResolveCustomer -> ResolveCustomer -> Bool)
-> Eq ResolveCustomer
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResolveCustomer -> ResolveCustomer -> Bool
$c/= :: ResolveCustomer -> ResolveCustomer -> Bool
== :: ResolveCustomer -> ResolveCustomer -> Bool
$c== :: ResolveCustomer -> ResolveCustomer -> Bool
Prelude.Eq, ReadPrec [ResolveCustomer]
ReadPrec ResolveCustomer
Int -> ReadS ResolveCustomer
ReadS [ResolveCustomer]
(Int -> ReadS ResolveCustomer)
-> ReadS [ResolveCustomer]
-> ReadPrec ResolveCustomer
-> ReadPrec [ResolveCustomer]
-> Read ResolveCustomer
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ResolveCustomer]
$creadListPrec :: ReadPrec [ResolveCustomer]
readPrec :: ReadPrec ResolveCustomer
$creadPrec :: ReadPrec ResolveCustomer
readList :: ReadS [ResolveCustomer]
$creadList :: ReadS [ResolveCustomer]
readsPrec :: Int -> ReadS ResolveCustomer
$creadsPrec :: Int -> ReadS ResolveCustomer
Prelude.Read, Int -> ResolveCustomer -> ShowS
[ResolveCustomer] -> ShowS
ResolveCustomer -> String
(Int -> ResolveCustomer -> ShowS)
-> (ResolveCustomer -> String)
-> ([ResolveCustomer] -> ShowS)
-> Show ResolveCustomer
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResolveCustomer] -> ShowS
$cshowList :: [ResolveCustomer] -> ShowS
show :: ResolveCustomer -> String
$cshow :: ResolveCustomer -> String
showsPrec :: Int -> ResolveCustomer -> ShowS
$cshowsPrec :: Int -> ResolveCustomer -> ShowS
Prelude.Show, (forall x. ResolveCustomer -> Rep ResolveCustomer x)
-> (forall x. Rep ResolveCustomer x -> ResolveCustomer)
-> Generic ResolveCustomer
forall x. Rep ResolveCustomer x -> ResolveCustomer
forall x. ResolveCustomer -> Rep ResolveCustomer x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ResolveCustomer x -> ResolveCustomer
$cfrom :: forall x. ResolveCustomer -> Rep ResolveCustomer x
Prelude.Generic)

-- |
-- Create a value of 'ResolveCustomer' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'registrationToken', 'resolveCustomer_registrationToken' - When a buyer visits your website during the registration process, the
-- buyer submits a registration token through the browser. The registration
-- token is resolved to obtain a CustomerIdentifier and product code.
newResolveCustomer ::
  -- | 'registrationToken'
  Prelude.Text ->
  ResolveCustomer
newResolveCustomer :: Text -> ResolveCustomer
newResolveCustomer Text
pRegistrationToken_ =
  ResolveCustomer' :: Text -> ResolveCustomer
ResolveCustomer'
    { $sel:registrationToken:ResolveCustomer' :: Text
registrationToken =
        Text
pRegistrationToken_
    }

-- | When a buyer visits your website during the registration process, the
-- buyer submits a registration token through the browser. The registration
-- token is resolved to obtain a CustomerIdentifier and product code.
resolveCustomer_registrationToken :: Lens.Lens' ResolveCustomer Prelude.Text
resolveCustomer_registrationToken :: (Text -> f Text) -> ResolveCustomer -> f ResolveCustomer
resolveCustomer_registrationToken = (ResolveCustomer -> Text)
-> (ResolveCustomer -> Text -> ResolveCustomer)
-> Lens ResolveCustomer ResolveCustomer Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResolveCustomer' {Text
registrationToken :: Text
$sel:registrationToken:ResolveCustomer' :: ResolveCustomer -> Text
registrationToken} -> Text
registrationToken) (\s :: ResolveCustomer
s@ResolveCustomer' {} Text
a -> ResolveCustomer
s {$sel:registrationToken:ResolveCustomer' :: Text
registrationToken = Text
a} :: ResolveCustomer)

instance Core.AWSRequest ResolveCustomer where
  type
    AWSResponse ResolveCustomer =
      ResolveCustomerResponse
  request :: ResolveCustomer -> Request ResolveCustomer
request = Service -> ResolveCustomer -> Request ResolveCustomer
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy ResolveCustomer
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ResolveCustomer)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse ResolveCustomer))
-> Logger
-> Service
-> Proxy ResolveCustomer
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ResolveCustomer)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Text -> Maybe Text -> Int -> ResolveCustomerResponse
ResolveCustomerResponse'
            (Maybe Text -> Maybe Text -> Int -> ResolveCustomerResponse)
-> Either String (Maybe Text)
-> Either String (Maybe Text -> Int -> ResolveCustomerResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"CustomerIdentifier")
            Either String (Maybe Text -> Int -> ResolveCustomerResponse)
-> Either String (Maybe Text)
-> Either String (Int -> ResolveCustomerResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"ProductCode")
            Either String (Int -> ResolveCustomerResponse)
-> Either String Int -> Either String ResolveCustomerResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable ResolveCustomer

instance Prelude.NFData ResolveCustomer

instance Core.ToHeaders ResolveCustomer where
  toHeaders :: ResolveCustomer -> ResponseHeaders
toHeaders =
    ResponseHeaders -> ResolveCustomer -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"AWSMPMeteringService.ResolveCustomer" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON ResolveCustomer where
  toJSON :: ResolveCustomer -> Value
toJSON ResolveCustomer' {Text
registrationToken :: Text
$sel:registrationToken:ResolveCustomer' :: ResolveCustomer -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"RegistrationToken" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
registrationToken)
          ]
      )

instance Core.ToPath ResolveCustomer where
  toPath :: ResolveCustomer -> ByteString
toPath = ByteString -> ResolveCustomer -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Core.ToQuery ResolveCustomer where
  toQuery :: ResolveCustomer -> QueryString
toQuery = QueryString -> ResolveCustomer -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | The result of the ResolveCustomer operation. Contains the
-- CustomerIdentifier and product code.
--
-- /See:/ 'newResolveCustomerResponse' smart constructor.
data ResolveCustomerResponse = ResolveCustomerResponse'
  { -- | The CustomerIdentifier is used to identify an individual customer in
    -- your application. Calls to BatchMeterUsage require CustomerIdentifiers
    -- for each UsageRecord.
    ResolveCustomerResponse -> Maybe Text
customerIdentifier :: Prelude.Maybe Prelude.Text,
    -- | The product code is returned to confirm that the buyer is registering
    -- for your product. Subsequent BatchMeterUsage calls should be made using
    -- this product code.
    ResolveCustomerResponse -> Maybe Text
productCode :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ResolveCustomerResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ResolveCustomerResponse -> ResolveCustomerResponse -> Bool
(ResolveCustomerResponse -> ResolveCustomerResponse -> Bool)
-> (ResolveCustomerResponse -> ResolveCustomerResponse -> Bool)
-> Eq ResolveCustomerResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResolveCustomerResponse -> ResolveCustomerResponse -> Bool
$c/= :: ResolveCustomerResponse -> ResolveCustomerResponse -> Bool
== :: ResolveCustomerResponse -> ResolveCustomerResponse -> Bool
$c== :: ResolveCustomerResponse -> ResolveCustomerResponse -> Bool
Prelude.Eq, ReadPrec [ResolveCustomerResponse]
ReadPrec ResolveCustomerResponse
Int -> ReadS ResolveCustomerResponse
ReadS [ResolveCustomerResponse]
(Int -> ReadS ResolveCustomerResponse)
-> ReadS [ResolveCustomerResponse]
-> ReadPrec ResolveCustomerResponse
-> ReadPrec [ResolveCustomerResponse]
-> Read ResolveCustomerResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ResolveCustomerResponse]
$creadListPrec :: ReadPrec [ResolveCustomerResponse]
readPrec :: ReadPrec ResolveCustomerResponse
$creadPrec :: ReadPrec ResolveCustomerResponse
readList :: ReadS [ResolveCustomerResponse]
$creadList :: ReadS [ResolveCustomerResponse]
readsPrec :: Int -> ReadS ResolveCustomerResponse
$creadsPrec :: Int -> ReadS ResolveCustomerResponse
Prelude.Read, Int -> ResolveCustomerResponse -> ShowS
[ResolveCustomerResponse] -> ShowS
ResolveCustomerResponse -> String
(Int -> ResolveCustomerResponse -> ShowS)
-> (ResolveCustomerResponse -> String)
-> ([ResolveCustomerResponse] -> ShowS)
-> Show ResolveCustomerResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResolveCustomerResponse] -> ShowS
$cshowList :: [ResolveCustomerResponse] -> ShowS
show :: ResolveCustomerResponse -> String
$cshow :: ResolveCustomerResponse -> String
showsPrec :: Int -> ResolveCustomerResponse -> ShowS
$cshowsPrec :: Int -> ResolveCustomerResponse -> ShowS
Prelude.Show, (forall x.
 ResolveCustomerResponse -> Rep ResolveCustomerResponse x)
-> (forall x.
    Rep ResolveCustomerResponse x -> ResolveCustomerResponse)
-> Generic ResolveCustomerResponse
forall x. Rep ResolveCustomerResponse x -> ResolveCustomerResponse
forall x. ResolveCustomerResponse -> Rep ResolveCustomerResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ResolveCustomerResponse x -> ResolveCustomerResponse
$cfrom :: forall x. ResolveCustomerResponse -> Rep ResolveCustomerResponse x
Prelude.Generic)

-- |
-- Create a value of 'ResolveCustomerResponse' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'customerIdentifier', 'resolveCustomerResponse_customerIdentifier' - The CustomerIdentifier is used to identify an individual customer in
-- your application. Calls to BatchMeterUsage require CustomerIdentifiers
-- for each UsageRecord.
--
-- 'productCode', 'resolveCustomerResponse_productCode' - The product code is returned to confirm that the buyer is registering
-- for your product. Subsequent BatchMeterUsage calls should be made using
-- this product code.
--
-- 'httpStatus', 'resolveCustomerResponse_httpStatus' - The response's http status code.
newResolveCustomerResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ResolveCustomerResponse
newResolveCustomerResponse :: Int -> ResolveCustomerResponse
newResolveCustomerResponse Int
pHttpStatus_ =
  ResolveCustomerResponse' :: Maybe Text -> Maybe Text -> Int -> ResolveCustomerResponse
ResolveCustomerResponse'
    { $sel:customerIdentifier:ResolveCustomerResponse' :: Maybe Text
customerIdentifier =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:productCode:ResolveCustomerResponse' :: Maybe Text
productCode = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ResolveCustomerResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The CustomerIdentifier is used to identify an individual customer in
-- your application. Calls to BatchMeterUsage require CustomerIdentifiers
-- for each UsageRecord.
resolveCustomerResponse_customerIdentifier :: Lens.Lens' ResolveCustomerResponse (Prelude.Maybe Prelude.Text)
resolveCustomerResponse_customerIdentifier :: (Maybe Text -> f (Maybe Text))
-> ResolveCustomerResponse -> f ResolveCustomerResponse
resolveCustomerResponse_customerIdentifier = (ResolveCustomerResponse -> Maybe Text)
-> (ResolveCustomerResponse
    -> Maybe Text -> ResolveCustomerResponse)
-> Lens
     ResolveCustomerResponse
     ResolveCustomerResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResolveCustomerResponse' {Maybe Text
customerIdentifier :: Maybe Text
$sel:customerIdentifier:ResolveCustomerResponse' :: ResolveCustomerResponse -> Maybe Text
customerIdentifier} -> Maybe Text
customerIdentifier) (\s :: ResolveCustomerResponse
s@ResolveCustomerResponse' {} Maybe Text
a -> ResolveCustomerResponse
s {$sel:customerIdentifier:ResolveCustomerResponse' :: Maybe Text
customerIdentifier = Maybe Text
a} :: ResolveCustomerResponse)

-- | The product code is returned to confirm that the buyer is registering
-- for your product. Subsequent BatchMeterUsage calls should be made using
-- this product code.
resolveCustomerResponse_productCode :: Lens.Lens' ResolveCustomerResponse (Prelude.Maybe Prelude.Text)
resolveCustomerResponse_productCode :: (Maybe Text -> f (Maybe Text))
-> ResolveCustomerResponse -> f ResolveCustomerResponse
resolveCustomerResponse_productCode = (ResolveCustomerResponse -> Maybe Text)
-> (ResolveCustomerResponse
    -> Maybe Text -> ResolveCustomerResponse)
-> Lens
     ResolveCustomerResponse
     ResolveCustomerResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResolveCustomerResponse' {Maybe Text
productCode :: Maybe Text
$sel:productCode:ResolveCustomerResponse' :: ResolveCustomerResponse -> Maybe Text
productCode} -> Maybe Text
productCode) (\s :: ResolveCustomerResponse
s@ResolveCustomerResponse' {} Maybe Text
a -> ResolveCustomerResponse
s {$sel:productCode:ResolveCustomerResponse' :: Maybe Text
productCode = Maybe Text
a} :: ResolveCustomerResponse)

-- | The response's http status code.
resolveCustomerResponse_httpStatus :: Lens.Lens' ResolveCustomerResponse Prelude.Int
resolveCustomerResponse_httpStatus :: (Int -> f Int)
-> ResolveCustomerResponse -> f ResolveCustomerResponse
resolveCustomerResponse_httpStatus = (ResolveCustomerResponse -> Int)
-> (ResolveCustomerResponse -> Int -> ResolveCustomerResponse)
-> Lens ResolveCustomerResponse ResolveCustomerResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResolveCustomerResponse' {Int
httpStatus :: Int
$sel:httpStatus:ResolveCustomerResponse' :: ResolveCustomerResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: ResolveCustomerResponse
s@ResolveCustomerResponse' {} Int
a -> ResolveCustomerResponse
s {$sel:httpStatus:ResolveCustomerResponse' :: Int
httpStatus = Int
a} :: ResolveCustomerResponse)

instance Prelude.NFData ResolveCustomerResponse