fsspyipay package

Submodules

fsspyipay.exceptions module

exception fsspyipay.exceptions.InvalidAlias[source]

Bases: Exception

exception fsspyipay.exceptions.InvalidGatewayResponse[source]

Bases: Exception

exception fsspyipay.exceptions.InvalidUrl[source]

Bases: Exception

exception fsspyipay.exceptions.KeyNotFound[source]

Bases: Exception

fsspyipay.pyipay module

class fsspyipay.pyipay.Gateway(keystore, resource, alias, amount, lang='en', currency='KWD', tracking_id=None)[source]

Bases: object

A class that represents a payment gateway for hosted transactions, using the resource kit.

The first step is to initialize the gateway by providing it the configuration received from the bank. This configuration consists of the following:

  • A resource file (called resource.cgn), which is an encrypted file that contains connection and credentials for the gateway.
  • A keystore file (called keystore.bin), which is a Java keystore that contains the encrption key which is used to decrypt the resource file.
  • The alias, which is a string. This is the friendly name of your terminal as setup by the bank. It it used to extract the correct configuration from the resource file.

In addition to the above three values, you must also pass in the amount that you want to charge the customer for this transaction.

Parameters:
  • keystore (str) – The file system path to the keystore file (normally called keystore.bin)
  • resource (str) – The file system path to the resource file (normally called resource.cgn)
  • alias (str) – The terminal alias that is to be used.
  • amount (float) – The amount that needs to be charged. 3 decimal places by default for KWD.

The following can be optionally specified, but are set to reasonable defaults:

Parameters:
  • lang (str) – The language which will be used for the hosted pages to the end user. Values are ‘en’ (for English), and ‘ar’ for Arabic. The default is ‘en’
  • currency (str) – The ISO currency code. Defaults to ‘KWD’. If you change this, make sure the terminal supports the currency.
  • tracking_id (str) – This is a unique id for each transaction that is required by the gateway. If not supplied, the current timestamp is used.

Once you have created an instance of the Gateway, you can specify further configuration. There are two pieces of information that are critical, the response url and the error url.

These urls cannot have any query strings or fragments; and must be publicly accessible as this is where the gateway will return the results of the transactions.

Finally, you request the redirect url from the module; which is where you should redirect the customer to start the payment process.

The example provides details on how this all works:

Example:
>>> from fsspyipay import Gateway
>>> resource_file = r'/home/me/resource.cgn'
>>> keystore_file = r'/home/me/keystore.bin'
>>> gw = Gateway(keystore_file, resource_file, 'alias', 4.546)
>>> gw.response_url = 'https://example.com/response'
>>> gw.error_url = 'https://example.com/error'
>>> url = gw.generate_purchase_request()
error_url

Set and retrieve the error URL

generate_purchase_request()[source]
get_error_url()[source]
get_response_url()[source]
get_result(response)[source]
get_udf1()[source]
get_udf2()[source]
get_udf3()[source]
get_udf4()[source]
get_udf5()[source]
response_url

Set and retrieve the response URL

set_error_url(s)[source]
set_response_url(s)[source]
set_udf1(s)[source]
set_udf2(s)[source]
set_udf3(s)[source]
set_udf4(s)[source]
set_udf5(s)[source]
udf1

Set and retrieve UDF1, the values are sanitized.

udf2

Set and retrieve UDF2, the values are sanitized.

udf3

Set and retrieve UDF3, the values are sanitized.

udf4

Set and retrieve UDF4, the values are sanitized.

udf5

Set and retrieve UDF5, the values are sanitized.

fsspyipay.util module

class fsspyipay.util.Action[source]

Bases: enum.Enum

Maps codes to more usable values.

INQUIRY = 8
PURCHASE = 1
REFUND = 2
VOID = 3
fsspyipay.util.check_if_set(props)[source]

A decorator that checks if attributes of an instance are set, before a method is called

fsspyipay.util.decrypt_payload(encrypted_text, key)[source]

Decrypts and returns plain text

Parameters:
  • encrypted_text (str) –
  • key (str) –
Returns:

plain text

fsspyipay.util.encrypt_payload(plain_text, key)[source]

Encrypts and returns cryptext given the plain text and key

Parameters:
  • plain_text (str) – the plain text to be encrypted
  • key (str) – The key, which is used for AES encryption
Returns:

encrypted text

fsspyipay.util.load_keystore(keystore_path, key_name='pgkey', passphrase='password')[source]

Loads the keystore and extracts the pgkey value.

Raises:KeyNotFound
fsspyipay.util.read_resource_file(resource_path, keystore_path, alias)[source]

Read and returns the terminal configuration from the resource file which is a xml string.

Parameters:
  • resource_path (str) – A fully qualified file system path to the resource file
  • keystore_path (str) – A fully qualified file system path to the keystore file
  • alias (str) – The terminal alias which is to be extracted
Raises:
Returns:

terminal parameters

Return type:

string

fsspyipay.util.sanitize(text)[source]

Strips invalid characters from fields. Used for user defined fields (udf)s

Returns:the passed in value, translated by removing FILTER_CHARS
fsspyipay.util.validate_gw_url(s)[source]

The gateway only supports http and https, and response urls cannot have query strings

Raises:InvalidUrl
Returns:the passed in url

Module contents

Top-level package for ipaypipe.

class fsspyipay.Gateway(keystore, resource, alias, amount, lang='en', currency='KWD', tracking_id=None)[source]

Bases: object

A class that represents a payment gateway for hosted transactions, using the resource kit.

The first step is to initialize the gateway by providing it the configuration received from the bank. This configuration consists of the following:

  • A resource file (called resource.cgn), which is an encrypted file that contains connection and credentials for the gateway.
  • A keystore file (called keystore.bin), which is a Java keystore that contains the encrption key which is used to decrypt the resource file.
  • The alias, which is a string. This is the friendly name of your terminal as setup by the bank. It it used to extract the correct configuration from the resource file.

In addition to the above three values, you must also pass in the amount that you want to charge the customer for this transaction.

Parameters:
  • keystore (str) – The file system path to the keystore file (normally called keystore.bin)
  • resource (str) – The file system path to the resource file (normally called resource.cgn)
  • alias (str) – The terminal alias that is to be used.
  • amount (float) – The amount that needs to be charged. 3 decimal places by default for KWD.

The following can be optionally specified, but are set to reasonable defaults:

Parameters:
  • lang (str) – The language which will be used for the hosted pages to the end user. Values are ‘en’ (for English), and ‘ar’ for Arabic. The default is ‘en’
  • currency (str) – The ISO currency code. Defaults to ‘KWD’. If you change this, make sure the terminal supports the currency.
  • tracking_id (str) – This is a unique id for each transaction that is required by the gateway. If not supplied, the current timestamp is used.

Once you have created an instance of the Gateway, you can specify further configuration. There are two pieces of information that are critical, the response url and the error url.

These urls cannot have any query strings or fragments; and must be publicly accessible as this is where the gateway will return the results of the transactions.

Finally, you request the redirect url from the module; which is where you should redirect the customer to start the payment process.

The example provides details on how this all works:

Example:
>>> from fsspyipay import Gateway
>>> resource_file = r'/home/me/resource.cgn'
>>> keystore_file = r'/home/me/keystore.bin'
>>> gw = Gateway(keystore_file, resource_file, 'alias', 4.546)
>>> gw.response_url = 'https://example.com/response'
>>> gw.error_url = 'https://example.com/error'
>>> url = gw.generate_purchase_request()
error_url

Set and retrieve the error URL

generate_purchase_request()[source]
get_error_url()[source]
get_response_url()[source]
get_result(response)[source]
get_udf1()[source]
get_udf2()[source]
get_udf3()[source]
get_udf4()[source]
get_udf5()[source]
response_url

Set and retrieve the response URL

set_error_url(s)[source]
set_response_url(s)[source]
set_udf1(s)[source]
set_udf2(s)[source]
set_udf3(s)[source]
set_udf4(s)[source]
set_udf5(s)[source]
udf1

Set and retrieve UDF1, the values are sanitized.

udf2

Set and retrieve UDF2, the values are sanitized.

udf3

Set and retrieve UDF3, the values are sanitized.

udf4

Set and retrieve UDF4, the values are sanitized.

udf5

Set and retrieve UDF5, the values are sanitized.