Skip to content

Products

AsyncProduct

Bases: BaseAsyncAPI

Provides a wrapper for paystack Products API

The Products API allows you to create and manage inventories on your integration. https://paystack.com/docs/api/product/

Source code in src/pypaystack2/api/products.py
class AsyncProduct(BaseAsyncAPI):
    """Provides a wrapper for paystack Products API

    The Products API allows you to create and manage inventories on your integration.
    https://paystack.com/docs/api/product/
    """

    async def create(
        self,
        name: str,
        description: str,
        price: int,
        currency: Currency,
        unlimited: Optional[bool] = None,
        quantity: Optional[int] = None,
    ) -> Response:
        """Create a product on your integration

        Args:
            name: Name of product
            description: A description for this product
            price: Price should be in kobo if currency is ``Currency.NGN``, pesewas,
                if currency is ``Currency.GHS``, and cents, if currency is ``Currency.ZAR``
            currency: Any value from the ``Currency`` enum
            unlimited: Set to ``True`` if the product has unlimited stock.
                Leave as ``False`` if the product has limited stock
            quantity: Number of products in stock. Use if unlimited is ``False``

        Returns:
            A named tuple containing the response gotten from paystack's server.

        Raises:
            InvalidDataError: When unlimited is set to True and quantity has a value.
        """

        if unlimited is True and quantity is not None:
            raise InvalidDataException(
                "You can't have unlimited set to True and have a quantity value."
            )

        url = self._parse_url("/product")

        payload = {
            "name": name,
            "description": description,
            "price": price,
            "currency": currency,
        }
        optional_params = [
            ("unlimited", unlimited),
            ("quantity", quantity),
        ]
        payload = add_to_payload(optional_params, payload)
        return await self._handle_request(HTTPMethod.POST, url, payload)

    async def get_products(
        self,
        page: int = 1,
        pagination: int = 50,
        start_date: Optional[str] = None,
        end_date: Optional[str] = None,
    ) -> Response:
        """Fetches products available on your integration.

        Args:
            page: Specifies exactly what page you want to retrieve.
                If not specified we use a default value of 1.
            pagination: Specifies how many records you want to retrieve per page.
                If not specified we use a default value of 50.
            start_date: A timestamp from which to start listing product e.g. 2016-09-24T00:00:05.000Z, 2016-09-21
            end_date: timestamp at which to stop listing product e.g. 2016-09-24T00:00:05.000Z, 2016-09-21

        Returns:
            A named tuple containing the response gotten from paystack's server.
        """

        url = self._parse_url("/product?perPage=" + str(pagination))
        query_params = [
            ("page", page),
            ("start_date", start_date),
            ("end_date", end_date),
        ]
        url = append_query_params(query_params, url)
        return await self._handle_request(HTTPMethod.GET, url)

    async def get_product(self, id: str) -> Response:
        """Get details of a product on your integration.

        Args:
            id: The product ``ID`` you want to fetch

        Returns:
            A named tuple containing the response gotten from paystack's server.
        """

        url = self._parse_url(f"/product/{id}")
        return await self._handle_request(HTTPMethod.GET, url)

    async def update(
        self,
        id: str,
        name: str,
        description: str,
        price: int,
        currency: Currency,
        unlimited: Optional[bool] = None,
        quantity: Optional[int] = None,
    ) -> Response:
        """Update a product details on your integration

        Args:
            id: Product ID
            name: Name of product
            description: A description for this product
            price: Price should be in kobo if currency is ``Currency.NGN``, pesewas,
                if currency is GHS, and cents, if currency is ``Currency.ZAR``
            currency: Any value from the ``Currency`` enum
            unlimited: Set to ``True`` if the product has unlimited stock.
                Leave as ``False`` if the product has limited stock
            quantity: Number of products in stock. Use if unlimited is ``False``

        Returns:
            A named tuple containing the response gotten from paystack's server.

        Raises:
            InvalidDataError: When unlimited is set to True and quantity has a value.
        """

        if unlimited is True and quantity is not None:
            raise InvalidDataException(
                "You can't have unlimited set to True and quantity have a value."
            )
        url = self._parse_url(f"/product/{id}")
        payload = {
            "name": name,
            "description": description,
            "price": price,
            "currency": currency,
        }
        optional_params = [
            ("unlimited", unlimited),
            ("quantity", quantity),
        ]
        payload = add_to_payload(optional_params, payload)
        return await self._handle_request(HTTPMethod.PUT, url, payload)

create(name, description, price, currency, unlimited=None, quantity=None) async

Create a product on your integration

Parameters:

Name Type Description Default
name str

Name of product

required
description str

A description for this product

required
price int

Price should be in kobo if currency is Currency.NGN, pesewas, if currency is Currency.GHS, and cents, if currency is Currency.ZAR

required
currency Currency

Any value from the Currency enum

required
unlimited Optional[bool]

Set to True if the product has unlimited stock. Leave as False if the product has limited stock

None
quantity Optional[int]

Number of products in stock. Use if unlimited is False

None

Returns:

Type Description
Response

A named tuple containing the response gotten from paystack's server.

Raises:

Type Description
InvalidDataError

When unlimited is set to True and quantity has a value.

Source code in src/pypaystack2/api/products.py
async def create(
    self,
    name: str,
    description: str,
    price: int,
    currency: Currency,
    unlimited: Optional[bool] = None,
    quantity: Optional[int] = None,
) -> Response:
    """Create a product on your integration

    Args:
        name: Name of product
        description: A description for this product
        price: Price should be in kobo if currency is ``Currency.NGN``, pesewas,
            if currency is ``Currency.GHS``, and cents, if currency is ``Currency.ZAR``
        currency: Any value from the ``Currency`` enum
        unlimited: Set to ``True`` if the product has unlimited stock.
            Leave as ``False`` if the product has limited stock
        quantity: Number of products in stock. Use if unlimited is ``False``

    Returns:
        A named tuple containing the response gotten from paystack's server.

    Raises:
        InvalidDataError: When unlimited is set to True and quantity has a value.
    """

    if unlimited is True and quantity is not None:
        raise InvalidDataException(
            "You can't have unlimited set to True and have a quantity value."
        )

    url = self._parse_url("/product")

    payload = {
        "name": name,
        "description": description,
        "price": price,
        "currency": currency,
    }
    optional_params = [
        ("unlimited", unlimited),
        ("quantity", quantity),
    ]
    payload = add_to_payload(optional_params, payload)
    return await self._handle_request(HTTPMethod.POST, url, payload)

get_product(id) async

Get details of a product on your integration.

Parameters:

Name Type Description Default
id str

The product ID you want to fetch

required

Returns:

Type Description
Response

A named tuple containing the response gotten from paystack's server.

Source code in src/pypaystack2/api/products.py
async def get_product(self, id: str) -> Response:
    """Get details of a product on your integration.

    Args:
        id: The product ``ID`` you want to fetch

    Returns:
        A named tuple containing the response gotten from paystack's server.
    """

    url = self._parse_url(f"/product/{id}")
    return await self._handle_request(HTTPMethod.GET, url)

get_products(page=1, pagination=50, start_date=None, end_date=None) async

Fetches products available on your integration.

Parameters:

Name Type Description Default
page int

Specifies exactly what page you want to retrieve. If not specified we use a default value of 1.

1
pagination int

Specifies how many records you want to retrieve per page. If not specified we use a default value of 50.

50
start_date Optional[str]

A timestamp from which to start listing product e.g. 2016-09-24T00:00:05.000Z, 2016-09-21

None
end_date Optional[str]

timestamp at which to stop listing product e.g. 2016-09-24T00:00:05.000Z, 2016-09-21

None

Returns:

Type Description
Response

A named tuple containing the response gotten from paystack's server.

Source code in src/pypaystack2/api/products.py
async def get_products(
    self,
    page: int = 1,
    pagination: int = 50,
    start_date: Optional[str] = None,
    end_date: Optional[str] = None,
) -> Response:
    """Fetches products available on your integration.

    Args:
        page: Specifies exactly what page you want to retrieve.
            If not specified we use a default value of 1.
        pagination: Specifies how many records you want to retrieve per page.
            If not specified we use a default value of 50.
        start_date: A timestamp from which to start listing product e.g. 2016-09-24T00:00:05.000Z, 2016-09-21
        end_date: timestamp at which to stop listing product e.g. 2016-09-24T00:00:05.000Z, 2016-09-21

    Returns:
        A named tuple containing the response gotten from paystack's server.
    """

    url = self._parse_url("/product?perPage=" + str(pagination))
    query_params = [
        ("page", page),
        ("start_date", start_date),
        ("end_date", end_date),
    ]
    url = append_query_params(query_params, url)
    return await self._handle_request(HTTPMethod.GET, url)

update(id, name, description, price, currency, unlimited=None, quantity=None) async

Update a product details on your integration

Parameters:

Name Type Description Default
id str

Product ID

required
name str

Name of product

required
description str

A description for this product

required
price int

Price should be in kobo if currency is Currency.NGN, pesewas, if currency is GHS, and cents, if currency is Currency.ZAR

required
currency Currency

Any value from the Currency enum

required
unlimited Optional[bool]

Set to True if the product has unlimited stock. Leave as False if the product has limited stock

None
quantity Optional[int]

Number of products in stock. Use if unlimited is False

None

Returns:

Type Description
Response

A named tuple containing the response gotten from paystack's server.

Raises:

Type Description
InvalidDataError

When unlimited is set to True and quantity has a value.

Source code in src/pypaystack2/api/products.py
async def update(
    self,
    id: str,
    name: str,
    description: str,
    price: int,
    currency: Currency,
    unlimited: Optional[bool] = None,
    quantity: Optional[int] = None,
) -> Response:
    """Update a product details on your integration

    Args:
        id: Product ID
        name: Name of product
        description: A description for this product
        price: Price should be in kobo if currency is ``Currency.NGN``, pesewas,
            if currency is GHS, and cents, if currency is ``Currency.ZAR``
        currency: Any value from the ``Currency`` enum
        unlimited: Set to ``True`` if the product has unlimited stock.
            Leave as ``False`` if the product has limited stock
        quantity: Number of products in stock. Use if unlimited is ``False``

    Returns:
        A named tuple containing the response gotten from paystack's server.

    Raises:
        InvalidDataError: When unlimited is set to True and quantity has a value.
    """

    if unlimited is True and quantity is not None:
        raise InvalidDataException(
            "You can't have unlimited set to True and quantity have a value."
        )
    url = self._parse_url(f"/product/{id}")
    payload = {
        "name": name,
        "description": description,
        "price": price,
        "currency": currency,
    }
    optional_params = [
        ("unlimited", unlimited),
        ("quantity", quantity),
    ]
    payload = add_to_payload(optional_params, payload)
    return await self._handle_request(HTTPMethod.PUT, url, payload)

Product

Bases: BaseAPI

Provides a wrapper for paystack Products API

The Products API allows you to create and manage inventories on your integration. https://paystack.com/docs/api/product/

Source code in src/pypaystack2/api/products.py
class Product(BaseAPI):
    """Provides a wrapper for paystack Products API

    The Products API allows you to create and manage inventories on your integration.
    https://paystack.com/docs/api/product/
    """

    def create(
        self,
        name: str,
        description: str,
        price: int,
        currency: Currency,
        unlimited: Optional[bool] = None,
        quantity: Optional[int] = None,
    ) -> Response:
        """Create a product on your integration

        Args:
            name: Name of product
            description: A description for this product
            price: Price should be in kobo if currency is ``Currency.NGN``, pesewas,
                if currency is ``Currency.GHS``, and cents, if currency is ``Currency.ZAR``
            currency: Any value from the ``Currency`` enum
            unlimited: Set to ``True`` if the product has unlimited stock.
                Leave as ``False`` if the product has limited stock
            quantity: Number of products in stock. Use if unlimited is ``False``

        Returns:
            A named tuple containing the response gotten from paystack's server.

        Raises:
            InvalidDataError: When unlimited is set to True and quantity has a value.
        """

        if unlimited is True and quantity is not None:
            raise InvalidDataException(
                "You can't have unlimited set to True and have a quantity value."
            )

        url = self._parse_url("/product")

        payload = {
            "name": name,
            "description": description,
            "price": price,
            "currency": currency,
        }
        optional_params = [
            ("unlimited", unlimited),
            ("quantity", quantity),
        ]
        payload = add_to_payload(optional_params, payload)
        return self._handle_request(HTTPMethod.POST, url, payload)

    def get_products(
        self,
        page: int = 1,
        pagination: int = 50,
        start_date: Optional[str] = None,
        end_date: Optional[str] = None,
    ) -> Response:
        """Fetches products available on your integration.

        Args:
            page: Specifies exactly what page you want to retrieve.
                If not specified we use a default value of 1.
            pagination: Specifies how many records you want to retrieve per page.
                If not specified we use a default value of 50.
            start_date: A timestamp from which to start listing product e.g. 2016-09-24T00:00:05.000Z, 2016-09-21
            end_date: timestamp at which to stop listing product e.g. 2016-09-24T00:00:05.000Z, 2016-09-21

        Returns:
            A named tuple containing the response gotten from paystack's server.
        """

        url = self._parse_url("/product?perPage=" + str(pagination))
        query_params = [
            ("page", page),
            ("start_date", start_date),
            ("end_date", end_date),
        ]
        url = append_query_params(query_params, url)
        return self._handle_request(HTTPMethod.GET, url)

    def get_product(self, id: str) -> Response:
        """Get details of a product on your integration.

        Args:
            id: The product ``ID`` you want to fetch

        Returns:
            A named tuple containing the response gotten from paystack's server.
        """

        url = self._parse_url(f"/product/{id}")
        return self._handle_request(HTTPMethod.GET, url)

    def update(
        self,
        id: str,
        name: str,
        description: str,
        price: int,
        currency: Currency,
        unlimited: Optional[bool] = None,
        quantity: Optional[int] = None,
    ) -> Response:
        """Update a product details on your integration

        Args:
            id: Product ID
            name: Name of product
            description: A description for this product
            price: Price should be in kobo if currency is ``Currency.NGN``, pesewas,
                if currency is GHS, and cents, if currency is ``Currency.ZAR``
            currency: Any value from the ``Currency`` enum
            unlimited: Set to ``True`` if the product has unlimited stock.
                Leave as ``False`` if the product has limited stock
            quantity: Number of products in stock. Use if unlimited is ``False``

        Returns:
            A named tuple containing the response gotten from paystack's server.

        Raises:
            InvalidDataError: When unlimited is set to True and quantity has a value.
        """

        if unlimited is True and quantity is not None:
            raise InvalidDataException(
                "You can't have unlimited set to True and quantity have a value."
            )
        url = self._parse_url(f"/product/{id}")
        payload = {
            "name": name,
            "description": description,
            "price": price,
            "currency": currency,
        }
        optional_params = [
            ("unlimited", unlimited),
            ("quantity", quantity),
        ]
        payload = add_to_payload(optional_params, payload)
        return self._handle_request(HTTPMethod.PUT, url, payload)

create(name, description, price, currency, unlimited=None, quantity=None)

Create a product on your integration

Parameters:

Name Type Description Default
name str

Name of product

required
description str

A description for this product

required
price int

Price should be in kobo if currency is Currency.NGN, pesewas, if currency is Currency.GHS, and cents, if currency is Currency.ZAR

required
currency Currency

Any value from the Currency enum

required
unlimited Optional[bool]

Set to True if the product has unlimited stock. Leave as False if the product has limited stock

None
quantity Optional[int]

Number of products in stock. Use if unlimited is False

None

Returns:

Type Description
Response

A named tuple containing the response gotten from paystack's server.

Raises:

Type Description
InvalidDataError

When unlimited is set to True and quantity has a value.

Source code in src/pypaystack2/api/products.py
def create(
    self,
    name: str,
    description: str,
    price: int,
    currency: Currency,
    unlimited: Optional[bool] = None,
    quantity: Optional[int] = None,
) -> Response:
    """Create a product on your integration

    Args:
        name: Name of product
        description: A description for this product
        price: Price should be in kobo if currency is ``Currency.NGN``, pesewas,
            if currency is ``Currency.GHS``, and cents, if currency is ``Currency.ZAR``
        currency: Any value from the ``Currency`` enum
        unlimited: Set to ``True`` if the product has unlimited stock.
            Leave as ``False`` if the product has limited stock
        quantity: Number of products in stock. Use if unlimited is ``False``

    Returns:
        A named tuple containing the response gotten from paystack's server.

    Raises:
        InvalidDataError: When unlimited is set to True and quantity has a value.
    """

    if unlimited is True and quantity is not None:
        raise InvalidDataException(
            "You can't have unlimited set to True and have a quantity value."
        )

    url = self._parse_url("/product")

    payload = {
        "name": name,
        "description": description,
        "price": price,
        "currency": currency,
    }
    optional_params = [
        ("unlimited", unlimited),
        ("quantity", quantity),
    ]
    payload = add_to_payload(optional_params, payload)
    return self._handle_request(HTTPMethod.POST, url, payload)

get_product(id)

Get details of a product on your integration.

Parameters:

Name Type Description Default
id str

The product ID you want to fetch

required

Returns:

Type Description
Response

A named tuple containing the response gotten from paystack's server.

Source code in src/pypaystack2/api/products.py
def get_product(self, id: str) -> Response:
    """Get details of a product on your integration.

    Args:
        id: The product ``ID`` you want to fetch

    Returns:
        A named tuple containing the response gotten from paystack's server.
    """

    url = self._parse_url(f"/product/{id}")
    return self._handle_request(HTTPMethod.GET, url)

get_products(page=1, pagination=50, start_date=None, end_date=None)

Fetches products available on your integration.

Parameters:

Name Type Description Default
page int

Specifies exactly what page you want to retrieve. If not specified we use a default value of 1.

1
pagination int

Specifies how many records you want to retrieve per page. If not specified we use a default value of 50.

50
start_date Optional[str]

A timestamp from which to start listing product e.g. 2016-09-24T00:00:05.000Z, 2016-09-21

None
end_date Optional[str]

timestamp at which to stop listing product e.g. 2016-09-24T00:00:05.000Z, 2016-09-21

None

Returns:

Type Description
Response

A named tuple containing the response gotten from paystack's server.

Source code in src/pypaystack2/api/products.py
def get_products(
    self,
    page: int = 1,
    pagination: int = 50,
    start_date: Optional[str] = None,
    end_date: Optional[str] = None,
) -> Response:
    """Fetches products available on your integration.

    Args:
        page: Specifies exactly what page you want to retrieve.
            If not specified we use a default value of 1.
        pagination: Specifies how many records you want to retrieve per page.
            If not specified we use a default value of 50.
        start_date: A timestamp from which to start listing product e.g. 2016-09-24T00:00:05.000Z, 2016-09-21
        end_date: timestamp at which to stop listing product e.g. 2016-09-24T00:00:05.000Z, 2016-09-21

    Returns:
        A named tuple containing the response gotten from paystack's server.
    """

    url = self._parse_url("/product?perPage=" + str(pagination))
    query_params = [
        ("page", page),
        ("start_date", start_date),
        ("end_date", end_date),
    ]
    url = append_query_params(query_params, url)
    return self._handle_request(HTTPMethod.GET, url)

update(id, name, description, price, currency, unlimited=None, quantity=None)

Update a product details on your integration

Parameters:

Name Type Description Default
id str

Product ID

required
name str

Name of product

required
description str

A description for this product

required
price int

Price should be in kobo if currency is Currency.NGN, pesewas, if currency is GHS, and cents, if currency is Currency.ZAR

required
currency Currency

Any value from the Currency enum

required
unlimited Optional[bool]

Set to True if the product has unlimited stock. Leave as False if the product has limited stock

None
quantity Optional[int]

Number of products in stock. Use if unlimited is False

None

Returns:

Type Description
Response

A named tuple containing the response gotten from paystack's server.

Raises:

Type Description
InvalidDataError

When unlimited is set to True and quantity has a value.

Source code in src/pypaystack2/api/products.py
def update(
    self,
    id: str,
    name: str,
    description: str,
    price: int,
    currency: Currency,
    unlimited: Optional[bool] = None,
    quantity: Optional[int] = None,
) -> Response:
    """Update a product details on your integration

    Args:
        id: Product ID
        name: Name of product
        description: A description for this product
        price: Price should be in kobo if currency is ``Currency.NGN``, pesewas,
            if currency is GHS, and cents, if currency is ``Currency.ZAR``
        currency: Any value from the ``Currency`` enum
        unlimited: Set to ``True`` if the product has unlimited stock.
            Leave as ``False`` if the product has limited stock
        quantity: Number of products in stock. Use if unlimited is ``False``

    Returns:
        A named tuple containing the response gotten from paystack's server.

    Raises:
        InvalidDataError: When unlimited is set to True and quantity has a value.
    """

    if unlimited is True and quantity is not None:
        raise InvalidDataException(
            "You can't have unlimited set to True and quantity have a value."
        )
    url = self._parse_url(f"/product/{id}")
    payload = {
        "name": name,
        "description": description,
        "price": price,
        "currency": currency,
    }
    optional_params = [
        ("unlimited", unlimited),
        ("quantity", quantity),
    ]
    payload = add_to_payload(optional_params, payload)
    return self._handle_request(HTTPMethod.PUT, url, payload)