Getting Started

Download the SDK

Download the Paysafe Python SDK from GitHub

Before You Begin

Before you use an SDK, you’ll need the API credentials (API Key) that it uses to make JSON requests to our server via the Paysafe REST API.

  • Your Paysafe API Key Username
  • Your Paysafe API Key Password
  • Your Paysafe Account Number

To get your test account, if you intend to use the Direct Debit SDK, contact Paysafe support, otherwise click Sign Up above. Once logged in to the Back Office you can retrieve your Account Number (choose Accounts and copy it from the Account column) and your API Key User name and Password (choose Settings > API Key). See More about Authentication for more information.

Installation

The Python SDK supports the following operation systems:

  • MS Windows XP
  • MS Windows 7
  • Ubuntu 14.04 (Linux)
  • Mac OS X 10.9.5

The sections that follow include commands you should enter at the command prompt.

Download Python

Before you can install the Python SDK, you must first download Python 3.2.x or later from https://www.python.org/downloads and then install it, as described below.

You can check your current version by executing the following:

python --version

Install Python

Navigate to the sub-folder src and execute the following commands for your operating system:

Windows

The Windows installation command is:

python setup.py install

and then install the pip package management system by navigating to the folder containing get-pip.py and executing the following:

python get-pip.py

Unix

The Unix installation command is:

sudo python3 setup.py install

and then install the pip package management system by executing the following:

sudo curl https://bootstrap.pypa.io/get-pip.py | python3

Install SSL Certificates

The Paysafe Python SDK needs the certifi package (version 14.5.14) so that it can validate SSL certificates when it performs HTTPS operations. Install it using the following command for your operating system:

Windows

The Windows installation command is:

python –m pip install certifi

Unix

The Unix installation command is:

sudo python3 –m pip install certifi

Install Python HTTP Client

The Paysafe Python SDK needs the urllib3 HTTP client, which you install using the following command for your operating system:

Windows

The Windows installation command is:

python –m pip install urllib3

Unix

The Unix installation commands are:

sudo python3 –m pip install urllib3

Launch the Sample Application

  1. Navigate to the \src\sample_application folder.
  2. Update the following parameters in Config.py with the credentials you generated when creating an account on the Paysafe system, ensuring that each value is enclosed within matching quotes.
    Key Value
    account_number

    Your Paysafe Account Number

    api_key

    Your Paysafe API Key user name

    api_password

    Your Paysafe API Key password

    currency_code The appropriate currency code, such as USD
    currency_base_units_mulitplier

    Transactions are actually measured in fractions of the currency specified in the currency_code; for example, USD transactions are measured in cents. This multiplier is how many of these smaller units make up one of the specified currency. For example, with the currency_code USD the value is 100 but for Japanese YEN the multiplier would be 1 as there is no smaller unit.

    environment

    TEST or LIVE

  3. By default the Python server uses port 3000. If you do not want to use this port, execute the following for your operating system:
    Windows:
    set PORT=required-server-port
    Unix:
    export PORT=required-server-port
  4. Type the following command to start the Python server:
    python ExecuteScriptServer.py
  5. If your Python server is running on port 3000, open a browser and navigate to the sample URLs below, substituting actual attribute values for the placeholders delimited by angle brackets, <>. If you changed the port number in the step above also substitute your chosen number for 3000.
    • http://localhost:3000/CreateProfile.py – for creating a profile using dummy data
    • http://localhost:3000/CreateCard.py?profileId=<profile_id>&cardNumber=<card_number> – for creating a card using dummy data
    • http://localhost:3000/SilentHosted.py – for executing a Silent Post using dummy data
    • http://localhost:3000/SimpleHosted.py – for executing a Hosted Payment order using dummy data
    • http://localhost:3000/CardPayment.py?cardNumber=<card_number> – for processing a card payment using dummy data
    • http://localhost:3000/CardCustomer.py?paymentToken=<card_payment_token> – for processing a payment using a dummy token

Server Environment Parameters

For the Python SDK to work with your merchant application, the server hosting the application must be able to connect to the relevant Paysafe server, either:

  • TEST – The Paysafe Test server
  • LIVE – The Paysafe Production server

The following environment configuration parameters for both servers are defined in the script file, src\bin\Environment.py:

  • connection_timeout – The number of seconds the Python SDK waits to establish a connection with the Paysafe API before timing-out
  • host_url - the base URL for the API request
  • max_connections – The maximum number of connections per connection pool in the Python SDK
  • pool_enable - Enable (set to 'True') or disable (set to 'False') a connection pool. To make repeated requests, enable a pool.
  • read_timeout – Once connected to the Paysafe API, the number of seconds the Python SDK waits for the API to respond to requests before timing-out

Initializing the SDK in Your Application

To initialize the Paysafe SDK in your application use the following commands:

  1. Import the configuration file containing your API key, etc.
    from Config import Config
  2. Import the PaysafeApiClient module into your application:
    from PythonPaysafeSDK.PaysafeApiClient import PaysafeApiClient
  3. Create the Paysafe API client to initalize the SDK
    client = PaysafeApiClient(Config.api_key, Config.api_password, Config.environment, Config.account_number)

During SDK initialization you can change the server environment parameters using this command:

Environment(host_url, max_connections, pool_enable, connection_timeout, read_timeout)

For example:

environment_url['TEST'] = Environment('api.test.paysafe.com', 10, True, connection_timeout=30, read_timeout=30)

Example Code

The following topics contain example code for each API:

  • Card Payments API – Process all major credit cards through the Paysafe payment gateway.
  • Direct Debit API – Process purchases and credits through a variety of bank schemes.
  • Customer Vault API – Make repeat payments without having to directly access the cardholder information.
  • 3D Secure API – Mitigate fraud while providing additional security for customers using their cards online.
  • Exceptions – Handle various exceptions to ensure accurate payment processing.

The above examples do not include initialization.

Did you find this page useful?