Payment processing refers to the handling of financial transactions between a customer and a business. It involves various steps, including authorizing the payment, verifying the transaction, and transferring the funds from the customer's account to the business's account. Payment processing is typically facilitated by payment processors, which are specialized companies that provide the infrastructure and technology to manage and secure online payments.
North's Custom Pay API connects to an in-house processor, EPX, making it easy to create a customized payment processing flow by providing several API endpoints to implement tasks such as authorizing and capturing a payment, making refunds, and retrieving past transactions.
In this article, you will learn how you can integrate North's Custom Pay API with your Python application. You will implement a Flask web application that prompts the user for payment details, use the Custom Pay API to process the payment, and display the payment results to the end user.

Benefits of the Custom Pay API
North's Custom Pay API lets you tailor your payment processing to your needs by accepting payments from various sources such as backend servers, a Point of Sale (POS) system, a website, or any other payment gateway that acts as a plugin or middleware. It is flexible enough to be used to accept payments online as well as through Semi-Integrated hardware. This makes the solution suitable for both card-present and card-not-present environments.
The API gives you access to a range of useful payment features, including the following:
- Address verification system—a fraud-prevention measure that verifies a customer's billing address against the address on file with their credit card company to ensure that the transaction is legitimate.
- Batch—to process multiple transactions at once, either closing all or partial transactions based on the ID provided. Batch transactions can also be used to retrieve batch totals and details.
- Refund—to return funds to an account that was previously charged in a sale or captured transaction.
- Reverse—to reverse the authorization of funds on a credit card, which releases the funds being held at the issuing bank. This feature is typically used when a customer cancels an order or returns a product.
- Sale—to authorize and capture a transaction in one step, provided that the authorization portion is approved and able to settle.
- Tip adjust—to allow the tip amount on a transaction to be adjusted after the payment has been processed.
Implementing the Custom Pay API
In this section, you will create a web application with Flask (a micro web framework written in Python) that prompts the user for payment details, use North's Custom Pay API to process the transaction, and display the transaction results.
You can find the code for this tutorial on GitHub.
Prerequisites
To follow along, you need to have the following:
- Custom Pay API test credentials, which you get by contacting the integrations team
- Python version 3+ installed on your development machine
- A code editor—this article uses VS code
Setting Up the Development Environment
Start by creating a project folder named 'python-custom-pay-api' and then create a Python virtual environment inside the folder by running this command in your terminal:
If you're using a Linux-based operating system, run the command below to activate the virtual environment:
If you're using a Windows operating system, use:
To create a Flask application, you need to install Flask in the virtual environment. You also need to install the Python requests module, which you will use to make API requests. To install these two modules, run the command:
Creating the Payment Solution
Now you're ready to create your solution.
In the project root folder, create a file named app.py and paste the code below into it:
This code imports the required modules and defines an API route '/' that accepts GET and POST requests.
When a GET request is sent to this API route, it renders an index.html file that you will create later in the tutorial. When the route receives a POST request, it extracts the JSON data from the request body, and the send_payment_request method is used to send a payment request to the North EPX servers. It takes one argument—userData—which is the user’s payment details.
Generate the EPI-Signature following the instructions in the "How To Authenticate" section of the Custom Pay API Integration Guide. Note that you'll need to create a free North Developer account to view the Integration Guide. To get the JSON payload, the send_payment_request method creates a dictionary named payload that contains the fields required by the Custom Pay API in the request schema. To learn more about each of the fields, check out the official documentation.
The dictionary is then serialized using the json.dumps() method and concatenated with the string /sale, which is the endpoint. The result is stored in a variable called concat_payload.
A dictionary named headers is then created with all the parameters required by the /sale endpoint.
Finally, the requests.post() method is used to send a payment request to the North EPX servers. The data parameter contains the serialized payload while the headers parameter contains the headers dictionary. The response.json() method is used to parse the JSON response from the EPX servers and return it as a Python dictionary. The results of the transaction are then returned to the index.html template.
Remember to replace and with the credentials you received from the North Integrations team.
Next, create a folder named templates in the project root directory. Inside this folder, create a file named index.html and add the code below to it:
HTML
The code above renders a webpage with a product from the DummyJSON website and a form to collect the user details.
When the user clicks the Buy Now button, a POST request with the customer payment details and a hard-coded product price is made to the '/' endpoint. The code awaits the response from the API and extracts the JSON data from it using the response.json() method. It then checks if the data received includes the string "APPROVAL" and displays an appropriate alert message accordingly.
Demonstrating the Final Application
To test the application, run the command below in your terminal:
Navigate to http://localhost:5000 in your browser where you should see the payment form that has been prefilled with the test data provided by North. Click on the Buy Now button and you should see the payment result page.
The complete code for this article is available on GitHub .
How To Get Started
In this article, you learned how to integrate North's Custom Pay API into your Python Flask application to create a customized payment processing flow. As you could see, using the Custom Pay API is very easy. Even though this article only covered capturing a payment, you can do much more with this API. Contact us to learn more about how the Custom Pay API and other tools can meet your business needs.