API Reference#

API Reference for YenePay

Client#

class yenepay.models.client.Client(merchant_id: str, token: Optional[str] = None, use_sandbox: Optional[bool] = False)[source]#

Representation of a single merchant account in YenePay platform.

Parameters
  • merchant_id (str()) – A unique merchant short code that is assigned to a merchant when signing up for a YenePay merchant account. Has a minimum of 4 digits and can be found after signing into YenePay account manager (https://www.yenepay.com/account)

  • token (str()) – A request authentication token that is assigned to a YenePay merchant account can be found on the Settings page of YenePay’s account manager.

  • use_sandbox (Optional bool()) – Use sandbox environment. Default is False.

Return type

None

property merchant_id: str#
Returns

client merchant id.

Return type

str()

property token: str#
Returns

client pdt token.

Return type

str()

property is_sandbox: bool#

check client running sandbox environment.

Return type

bool()

get_cart_checkout(*args, **kwargs)[source]#

Create yenepay.models.checkout.CartCheckout instance using a given information. for parameter information refer to a class parameters.

Returns

checkout instance

Return type

yenepay.models.checkout.CartCheckout

get_express_checkout(*args, **kwargs)[source]#

Create yenepay.models.checkout.ExpressCheckout instance using a given information. for parameter information refer to a class parameters.

Returns

checkout instance

Return type

yenepay.models.checkout.CartCheckout

check_pdt_status(merchant_order_id: str, transaction_id: str, use_sandbox: bool = False)[source]#

Check payment order status for a given transaction.

Parameters
  • merchant_order_id (Optional str()) – A unique identifier for this payment order on the merchant’s platform. Will be used to track payment status for this order.

  • transaction_id (str()) – a unique identifier id of the payment transaction that is set on YenePay’s platform. This id can be obtained from your checkout success_url or ipn_url endpoints.

Returns

Return pdt respose of a server

Return type

yenepay.models.pdt.PDTRespose

Raises

yenepay.exceptions.CheckoutError – if paramenters are incorrect.

Checkout#

Item#

class yenepay.models.checkout.Item(name: str, unit_price: float, quantity: int, item_id: Optional[str] = None)[source]#

Represent a single item to be purchased. Item will be used when Express or Cart checkout is created.

Note

Item ID is not required, but if not given the class will generate new UUID for an item.

  • Sample usage

>>> from yenepay import Item
>>>
>>> # Creating a single item
>>> item = Item(
        name="PC-1",
        unit_price=42_000.00,
        quantity=1,
    )
>>> # Or using positional arguments
>>> item = Item("PC-1", 42_000.00, 1)
>>> # Creating multiple items
>>> items = [
        Item("PC-2", 40_000.99, 1),
        Item("PC-3", 40_000.99, 1),
        Item("PC-4", 40_000.99, 1),
        Item("PC-5", 40_000.99, 1),
]
>>> # Or using Cart
>>> from yenepay import Cart, Item
>>> cart = Cart(
        Item("PC-6", 50_700.99, 1),
        Item("PC-7", 43_001.99, 1),
    )
Parameters
  • name (str()) – A unique identifier of the item (SKU, UUID,…) that is used to identify the item on the merchant’s platform.

  • unit_price (float()) – Amount in ETB currency.

  • quantity (int()) – Quantity of the item.

  • item_id (Optional str()) – Optional item id.

Return type

None

property id: Union[str, UUID]#
Returns

item id

Return type

str() or uuid.UUID

property name: str#
Returns

item name

Return type

str()

property unit_price: float#
Returns

item unit price

Return type

float()

to_dict() dict[source]#

Convert item properties into dictionary object.

Returns

dictionary of item properties.

Return type

dict()

to_json() bytes[source]#

Convert item properties into json format. usefull while creating requests.

Returns

Json representation of item properties.

Return type

bytes()

Cart#

class yenepay.models.checkout.Cart(*items: List[Item])[source]#

Represent a collection of multiple items to be purchased. Add addtional functionalityies for items.

Parameters

items (List of yenepay.models.checkout.Item) – Collection of yenepay.models.checkout.Item objects

Return type

None

create_item(name: str, unit_price: float, quantity: int, item_id: Optional[str] = None) Item[source]#

Create a new Item instance and add into a cart.

Parameters
  • name (str()) – A unique identifier of the item (SKU, UUID,…) that is used to identify the item on the merchant’s platform.

  • unit_price (float()) – Amount in ETB currency. Required for Express type checkout.

  • quantity (int()) – Quantity of the item. Required for Express type checkout.

  • item_id (Optional str()) – Optional item id. Required for Express type checkout.

Returns

Created item

Return type

yenepay.models.checkout.Item

add_item(item: Item) None[source]#

Add a single item into a cart.

Parameters

item (yenepay.models.checkout.Item) – Item to be added into a cart.

Return type

None

property total_price: float#
Returns

cart total price

Return type

float()

property total_quantity: int#
Returns

cart total quantity.

Return type

int()

Checkout#

class yenepay.models.checkout.Checkout(client: str, process: str, items: Union[List[Item], Cart], merchant_order_id: Optional[str] = None, success_url: Optional[str] = None, cancel_url: Optional[str] = None, ipn_url: Optional[str] = None, failure_url: Optional[str] = None, expires_after: Optional[int] = None, expires_in_days: Optional[int] = 1, total_items_handling_fee: Optional[float] = None, total_items_delivery_fee: Optional[float] = None, total_items_discount: Optional[float] = None, total_items_tax1: Optional[float] = None, total_items_tax2: Optional[float] = None)[source]#

An abstract class to creates a new payment order on YenePay for a given items and generate redirect link to checkout application to complete the payment.

Parameters
  • client (yenepay.models.client.Client) – yenepay.Client instance.

  • process (str()) – Checkout type for this payment. Should have a value of either Express or Cart. Use Express checkout type for single item payment and Cart if this payment includes more than one item.

  • items (List yenepay.models.checkout.Item) – Items to be purchased.

  • merchant_order_id (Optional str()) – A unique identifier for this payment order on the merchant’s platform. Will be used to track payment status for this order.

  • success_url (Optional str()) – A fully qualified URL endpoint on the merchant’s platform that will be used to redirect the paying customer after the payment has successfully been completed.

  • cancel_url (Optional str()) – A fully qualified URL endpoint on the merchant’s platform that will be used to redirect the paying customer if this payment is cancelled by the customer.

  • ipn_url (Optional str()) – A fully qualified URL endpoint on the merchant’s platform that will be used to send Instant Payment Notification to the merchant’s platform when a payment is successfully completed.

  • failure_url (Optional str()) – A fully qualified URL endpoint on the merchant’s platform that will be used to redirect the paying customer if this payment fails.

  • expires_after (Optional int()) – Expiration period for this payment in minutes. This payment order will expire after the specified number of minutes, if specified.

  • expires_in_days (Optional int()) – Expiration period for this payment in days. This payment order will expire after the specified number of days. The default value is 1 day.

  • total_items_handling_fee (Optional float()) – Handling fee in ETB currency for this payment order, if applicable. Set this value for Cart type checkout. When calculating total payment amount, this will be added to the cart items total amount.

  • total_items_delivery_fee – Delivery or shipping fee in ETB currency for this payment order, if applicable. Set this value for Cart type checkout. When calculating total payment amount, this will be added to the cart items total amount.

  • total_items_discount (Optional float()) – Discount amount in ETB currency for this payment order, if applicable. Set this value for Cart type checkout. When calculating total payment amount, this will be deducted from the cart items total amount.

  • total_items_tax1 (Optional float()) – Tax amount in ETB currency for this payment order, if applicable. Set this value for Cart type checkout. When calculating total payment amount, this will be added to the cart items total amount.

  • total_items_tax2 (Optional float()) – Tax amount in ETB currency for this payment order, if applicable. Set this value for Cart type checkout. When calculating total payment amount, this will be added to the cart items total amount.

Return type

None

property process: str#
Returns

checkout process type.

Return type

str()

property merchant_id: str#
Returns

checkout merchant id.

Return type

str()

property merchantId: str#
Returns

checkout merchant id.

Return type

str()

property token: str#
Returns

client pdt token.

Return type

str()

property merchant_order_id: Optional[str]#
Returns

checkout merchant order id.

Return type

str()

property success_url: Optional[str]#
Returns

checkout success url.

Return type

str()

property cancel_url#
Returns

chechout cancel url.

Return type

str()

property ipn_url: Optional[str]#
Returns

chckout ipn url.

Return type

str()

property failure_url: Optional[str]#
Returns

checkout failure url.

Return type

str()

property expires_after: int#
Returns

checkout expires after.

Return type

int()

property expires_in_days: int#
Returns

checkout expires in days.

Return type

int()

property total_items_handling_fee: Optional[float]#
Returns

checkout total items handling fee.

Return type

int()

property total_items_delivery_fee: Optional[float]#
Returns

checkout total items delivery fee.

Return type

float()

property total_items_discount: Optional[float]#
Returns

checkout total items discount

Return type

float()

property total_items_tax1: Optional[float]#
Returns

checkout total items tax1.

Return type

float()

property total_items_tax2: Optional[float]#
Returns

checkout total items tax2.

Return type

float()

property is_sandbox: bool#
Returns

check if sandbox is enabled or not.

Return type

bool()

property total_price: float#
Returns

checkout total price.

Return type

float()

property total_quantity: int#
Returns

checkout total quantity.

Return type

int()

to_dict() dict[source]#

Convert checkout properties into dictionary object.

Returns

dictionary of checkout properties

Return type

dict()

to_json() bytes[source]#

Convert checkout properties into json format. usefull while creating requests.

Returns

json representaion of checkout properties

Return type

bytes()

get_url() str[source]#
Returns

checkout url for payment order

Return type

str()

Raises

yenepay.exceptions.CheckoutError – if paramenters are incorrect.

check_pdt_status(transaction_id: str)[source]#

Check pdt status of checkout.

Parameters

transaction_id (str()) – a unique identifier id of the payment transaction that is set on YenePay’s platform. This id can be obtained from your checkout success_url or ipn_url endpoints.

Returns

Return pdt respose of a server

Return type

yenepay.models.pdt.PDTRespose

Raises

yenepay.exceptions.CheckoutError – if paramenters are incorrect.

ExpressCheckout#

class yenepay.models.checkout.ExpressCheckout(client, *args, **kwargs)[source]#

Bases: Checkout

A Checkout class that process express

Parameters
  • client (yenepay.models.client.Client) – yenepay.Client instance.

  • process (str()) – Checkout type for this payment. Should have a value of either Express or Cart. Use Express checkout type for single item payment and Cart if this payment includes more than one item.

  • items (List yenepay.models.checkout.Item) – Items to be purchased.

  • merchant_order_id (Optional str()) – A unique identifier for this payment order on the merchant’s platform. Will be used to track payment status for this order.

  • success_url (Optional str()) – A fully qualified URL endpoint on the merchant’s platform that will be used to redirect the paying customer after the payment has successfully been completed.

  • cancel_url (Optional str()) – A fully qualified URL endpoint on the merchant’s platform that will be used to redirect the paying customer if this payment is cancelled by the customer.

  • ipn_url (Optional str()) – A fully qualified URL endpoint on the merchant’s platform that will be used to send Instant Payment Notification to the merchant’s platform when a payment is successfully completed.

  • failure_url (Optional str()) – A fully qualified URL endpoint on the merchant’s platform that will be used to redirect the paying customer if this payment fails.

  • expires_after (Optional int()) – Expiration period for this payment in minutes. This payment order will expire after the specified number of minutes, if specified.

  • expires_in_days (Optional int()) – Expiration period for this payment in days. This payment order will expire after the specified number of days. The default value is 1 day.

  • total_items_handling_fee (Optional float()) – Handling fee in ETB currency for this payment order, if applicable. Set this value for Cart type checkout. When calculating total payment amount, this will be added to the cart items total amount.

  • total_items_delivery_fee – Delivery or shipping fee in ETB currency for this payment order, if applicable. Set this value for Cart type checkout. When calculating total payment amount, this will be added to the cart items total amount.

  • total_items_discount (Optional float()) – Discount amount in ETB currency for this payment order, if applicable. Set this value for Cart type checkout. When calculating total payment amount, this will be deducted from the cart items total amount.

  • total_items_tax1 (Optional float()) – Tax amount in ETB currency for this payment order, if applicable. Set this value for Cart type checkout. When calculating total payment amount, this will be added to the cart items total amount.

  • total_items_tax2 (Optional float()) – Tax amount in ETB currency for this payment order, if applicable. Set this value for Cart type checkout. When calculating total payment amount, this will be added to the cart items total amount.

Return type

None

property cancel_url#
Returns

chechout cancel url.

Return type

str()

check_pdt_status(transaction_id: str)#

Check pdt status of checkout.

Parameters

transaction_id (str()) – a unique identifier id of the payment transaction that is set on YenePay’s platform. This id can be obtained from your checkout success_url or ipn_url endpoints.

Returns

Return pdt respose of a server

Return type

yenepay.models.pdt.PDTRespose

Raises

yenepay.exceptions.CheckoutError – if paramenters are incorrect.

property expires_after: int#
Returns

checkout expires after.

Return type

int()

property expires_in_days: int#
Returns

checkout expires in days.

Return type

int()

property failure_url: Optional[str]#
Returns

checkout failure url.

Return type

str()

get_url() str#
Returns

checkout url for payment order

Return type

str()

Raises

yenepay.exceptions.CheckoutError – if paramenters are incorrect.

property ipn_url: Optional[str]#
Returns

chckout ipn url.

Return type

str()

property is_sandbox: bool#
Returns

check if sandbox is enabled or not.

Return type

bool()

property merchantId: str#
Returns

checkout merchant id.

Return type

str()

property merchant_id: str#
Returns

checkout merchant id.

Return type

str()

property merchant_order_id: Optional[str]#
Returns

checkout merchant order id.

Return type

str()

property process: str#
Returns

checkout process type.

Return type

str()

property success_url: Optional[str]#
Returns

checkout success url.

Return type

str()

to_dict() dict#

Convert checkout properties into dictionary object.

Returns

dictionary of checkout properties

Return type

dict()

to_json() bytes#

Convert checkout properties into json format. usefull while creating requests.

Returns

json representaion of checkout properties

Return type

bytes()

property token: str#
Returns

client pdt token.

Return type

str()

property total_items_delivery_fee: Optional[float]#
Returns

checkout total items delivery fee.

Return type

float()

property total_items_discount: Optional[float]#
Returns

checkout total items discount

Return type

float()

property total_items_handling_fee: Optional[float]#
Returns

checkout total items handling fee.

Return type

int()

property total_items_tax1: Optional[float]#
Returns

checkout total items tax1.

Return type

float()

property total_items_tax2: Optional[float]#
Returns

checkout total items tax2.

Return type

float()

property total_price: float#
Returns

checkout total price.

Return type

float()

property total_quantity: int#
Returns

checkout total quantity.

Return type

int()

property item: Item#
Returns

an item of express checkout.

Return type

yenepay.models.checkout.Item

CartCheckout#

class yenepay.models.checkout.CartCheckout(client, *args, **kwargs)[source]#

Bases: Checkout

A Checkout class that process cart

Parameters
  • client (yenepay.models.client.Client) – yenepay.Client instance.

  • process (str()) – Checkout type for this payment. Should have a value of either Express or Cart. Use Express checkout type for single item payment and Cart if this payment includes more than one item.

  • items (List yenepay.models.checkout.Item) – Items to be purchased.

  • merchant_order_id (Optional str()) – A unique identifier for this payment order on the merchant’s platform. Will be used to track payment status for this order.

  • success_url (Optional str()) – A fully qualified URL endpoint on the merchant’s platform that will be used to redirect the paying customer after the payment has successfully been completed.

  • cancel_url (Optional str()) – A fully qualified URL endpoint on the merchant’s platform that will be used to redirect the paying customer if this payment is cancelled by the customer.

  • ipn_url (Optional str()) – A fully qualified URL endpoint on the merchant’s platform that will be used to send Instant Payment Notification to the merchant’s platform when a payment is successfully completed.

  • failure_url (Optional str()) – A fully qualified URL endpoint on the merchant’s platform that will be used to redirect the paying customer if this payment fails.

  • expires_after (Optional int()) – Expiration period for this payment in minutes. This payment order will expire after the specified number of minutes, if specified.

  • expires_in_days (Optional int()) – Expiration period for this payment in days. This payment order will expire after the specified number of days. The default value is 1 day.

  • total_items_handling_fee (Optional float()) – Handling fee in ETB currency for this payment order, if applicable. Set this value for Cart type checkout. When calculating total payment amount, this will be added to the cart items total amount.

  • total_items_delivery_fee – Delivery or shipping fee in ETB currency for this payment order, if applicable. Set this value for Cart type checkout. When calculating total payment amount, this will be added to the cart items total amount.

  • total_items_discount (Optional float()) – Discount amount in ETB currency for this payment order, if applicable. Set this value for Cart type checkout. When calculating total payment amount, this will be deducted from the cart items total amount.

  • total_items_tax1 (Optional float()) – Tax amount in ETB currency for this payment order, if applicable. Set this value for Cart type checkout. When calculating total payment amount, this will be added to the cart items total amount.

  • total_items_tax2 (Optional float()) – Tax amount in ETB currency for this payment order, if applicable. Set this value for Cart type checkout. When calculating total payment amount, this will be added to the cart items total amount.

Return type

None

property cancel_url#
Returns

chechout cancel url.

Return type

str()

check_pdt_status(transaction_id: str)#

Check pdt status of checkout.

Parameters

transaction_id (str()) – a unique identifier id of the payment transaction that is set on YenePay’s platform. This id can be obtained from your checkout success_url or ipn_url endpoints.

Returns

Return pdt respose of a server

Return type

yenepay.models.pdt.PDTRespose

Raises

yenepay.exceptions.CheckoutError – if paramenters are incorrect.

property expires_after: int#
Returns

checkout expires after.

Return type

int()

property expires_in_days: int#
Returns

checkout expires in days.

Return type

int()

property failure_url: Optional[str]#
Returns

checkout failure url.

Return type

str()

get_url() str#
Returns

checkout url for payment order

Return type

str()

Raises

yenepay.exceptions.CheckoutError – if paramenters are incorrect.

property ipn_url: Optional[str]#
Returns

chckout ipn url.

Return type

str()

property is_sandbox: bool#
Returns

check if sandbox is enabled or not.

Return type

bool()

property merchantId: str#
Returns

checkout merchant id.

Return type

str()

property merchant_id: str#
Returns

checkout merchant id.

Return type

str()

property merchant_order_id: Optional[str]#
Returns

checkout merchant order id.

Return type

str()

property process: str#
Returns

checkout process type.

Return type

str()

property success_url: Optional[str]#
Returns

checkout success url.

Return type

str()

to_dict() dict#

Convert checkout properties into dictionary object.

Returns

dictionary of checkout properties

Return type

dict()

to_json() bytes#

Convert checkout properties into json format. usefull while creating requests.

Returns

json representaion of checkout properties

Return type

bytes()

property token: str#
Returns

client pdt token.

Return type

str()

property total_items_delivery_fee: Optional[float]#
Returns

checkout total items delivery fee.

Return type

float()

property total_items_discount: Optional[float]#
Returns

checkout total items discount

Return type

float()

property total_items_handling_fee: Optional[float]#
Returns

checkout total items handling fee.

Return type

int()

property total_items_tax1: Optional[float]#
Returns

checkout total items tax1.

Return type

float()

property total_items_tax2: Optional[float]#
Returns

checkout total items tax2.

Return type

float()

property total_price: float#
Returns

checkout total price.

Return type

float()

property total_quantity: int#
Returns

checkout total quantity.

Return type

int()

add_item(item)[source]#

Add item into a cart.

Parameters

item (yenepay.models.checkout.Item) – an item, that need to be added into a cart.

Return type

None

add_items(*items)[source]#

Add multiple items into a cart.

Parameters

items (List of yenepay.models.checkout.Item) – list of itmems, that need to be added into a cart.

Return type

None

PDT#

PDT#

class yenepay.models.pdt.PDT(client, merchant_order_id: str, transaction_id: str, use_sandbox=False)[source]#

A class to checks the latest status of a payment order

Parameters
  • client (yenepay.models.client.Client) – yenepay client account

  • transaction_id (str()) – a unique identifier id of the payment transaction that is set on YenePay’s platform. This id can be obtained from your SuccessUrl or IPNUrl endpoints.

  • merchant_order_id (str()) – the order id for this transaction that is set on your platform.

  • use_sandbox (Optional bool()) – Use sandbox environment. Default is False.

Return type

None

property requestType: str#
Returns

PDT request type. always PDT

Return type

str()

property request_type: str#
Returns

PDT request type. alway PDT

Return type

str()

property token: str#
Returns

client pdt token.

Return type

str()

property pdtToken: str#
Returns

client pdt token.

Return type

str()

property transaction_id: str#
Returns

checkout transaction id.

Return type

str()

property merchant_order_id: str#
Returns

checkout merchant order id.

Return type

str()

property is_sandbox: bool#

check client running sandbox environment.

Return type

bool()

to_dict() dict[source]#

Convert PDT properties into dictionary object.

Returns

dictionary of PDT properties

Return type

dict()

check_status()[source]#

Check the latest status of a given payment order.

Returns

PDT Status

Return type

yenepay.models.pdt.PDTResponse

PDTResponse#

class yenepay.models.pdt.PDTResponse(response: str, pdt: PDT)[source]#

PDT status resposen class.

Parameters
  • response (str()) – Actutal response from api endpoint.

  • pdt (yenepay.models.pdt.PDT) – a PDT instance that reqest in sent from.

Return type

None

IPN#

IPN#

API#

ApiRequest#

class yenepay.api.ApiRequest[source]#

A class that represents YenePay API request.

classmethod checkout(data, is_sandbox: Optional[bool] = False) Tuple[int, dict][source]#

Send request to yenepay checkout endpoint.

Parameters
  • data (dict()) – parameters that needed to be sent to YenePay server.

  • is_sandbox (bool()) – Whether the given client account is usng sandbox environment or not.

Returns

Request respose status and content.

Return type

Tuple of int() and bytes() or json()

classmethod pdt(data: Union[str, int, float], is_sandbox: Optional[bool] = False) Tuple[int, dict][source]#

Send request to yenepay PDT endpoint.

Parameters
  • data (dict()) – parameters that needed to be sent to YenePay server.

  • is_sandbox (bool()) – Whether the given client account is usng sandbox environment or not.

Returns

Request respose status and content.

Return type

Tuple of int() and bytes() or json()

classmethod ipn(data: Union[str, int, float], is_sandbox: Optional[bool] = False) Tuple[int, dict][source]#

Send request to yenepay IPN endpoint.

Parameters
  • data (dict()) – parameters that needed to be sent to YenePay server.

  • is_sandbox (bool()) – Whether the given client account is usng sandbox environment or not.

Returns

Request respose status and content.

Return type

Tuple of int() and bytes() or json()

Exceptions#

class yenepay.exceptions.CheckoutError[source]#

Exception for checkout errors.