How to implement payex payment gateway in asp net api


Implementing a payment gateway in an ASP.NET API is a common requirement for many e-commerce applications. Payex is a popular payment gateway that provides a secure and reliable way to process online payments. In this article, we will explore how to integrate the Payex payment gateway into an ASP.NET API.

Step 1: Obtain Payex API Credentials

The first step is to obtain the necessary API credentials from Payex. You will need a Merchant ID, a Secret Key, and a Base URL. These credentials will be used to authenticate your API requests and establish a secure connection with the Payex payment gateway.

Step 2: Install Payex SDK

To simplify the integration process, we can use the Payex SDK, which provides a set of pre-built classes and for with the Payex API. You can install the Payex SDK using NuGet package manager by running the following command in the Package Manager Console:

Install-Package Payex.SDK

Step 3: Payex Client

Once the Payex SDK is installed, we need to configure the Payex client with our API credentials. This can be done in the startup class of your ASP.NET API project. Add the following code to the ConfigureServices :

.AddPayexClient(options =>
    options.MerchantAccountID = "YOUR_MERCHANT_ACCOUNT_ID";
    options.SecretKey = "YOUR_SECRET_KEY";
    options.BaseUrl = "PAYEX_BASE_URL";

Step 4: Payment Flow

Now that the Payex client is configured, we can start implementing the payment flow in our ASP.NET API. This typically involves creating an endpoint that receives the payment request from the client and communicates with the Payex API to process the payment.

Here is an example of how to implement a payment endpoint:

In this example, we are using the Payex client to process the payment request received from the client. If the payment is successful, we update the and return a success response. Otherwise, we return an error response.

Step 5: Handle Payment Callback

After the payment is processed, Payex will send a callback to a specified URL to notify your API about the payment status. You need to implement a callback endpoint in your ASP.NET API to handle this notification.

Here is an example of how to implement a callback endpoint:

In this example, we are using the Payex client to retrieve the payment status based on the payment ID received in the callback. Depending on the payment status, we update the order status and return an appropriate response.


the Payex payment gateway into an ASP.NET API is a straightforward process. By following the steps outlined in this article, you can easily implement a secure and reliable payment flow in your e-commerce application.

Rate this post

Leave a Reply

Your email address will not be published. Required fields are marked *

Table of Contents