---
title: Connecting to payment gateways
related:
  - https://docs.kentico.com/13/e-commerce-features/developing-on-line-stores/implementing-a-checkout-process/building-the-order-review-step.md
  - https://docs.kentico.com/13/e-commerce-features/developing-on-line-stores/implementing-a-checkout-process.md
  - https://docs.kentico.com/13/e-commerce-features/configuring-on-line-stores/configuring-payment-methods.md
  - https://docs.kentico.com/13/e-commerce-features/customizing-on-line-stores/payment-related-customizing/working-with-payment-results.md
  - https://docs.kentico.com/13/e-commerce-features/managing-on-line-stores/orders.md
  - https://docs.kentico.com/13/e-commerce-features/managing-on-line-stores/orders/order-statuses.md
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

When building the checkout process on your e-commerce site, you may want to enable your [customers](https://docs.kentico.com/13/e-commerce-features/managing-on-line-stores/customers.md) to pay directly via a payment gateway (e.g. PayPal or credit card).

This page demonstrates how to work with API from the _CMS.Ecommerce_ assembly (installed into your project as part of the [Kentico.Xperience.Libraries integration package](https://docs.kentico.com/13/developing-websites/starting-with-mvc-development/installing-xperience-integration-packages.md)) that deals with payment of orders. However, the specific implementation can differ for each service, and we recommend that you work closely with documentation of the implemented payment gateway provider.

You need to [implement](#developing-payment-gateways) payment gateways for the payment methods in the live site application itself and [add the related payment methods](#configuring-payment-methods-in-xperience) to Xperience via the administration interface.

## Configuring payment methods in Xperience

Set up all payment methods for which you want to [implement a payment gateway](#developing-payment-gateways) as manual payment methods.

> **Tip:** See [Configuring payment methods](https://docs.kentico.com/13/e-commerce-features/configuring-on-line-stores/configuring-payment-methods.md) to learn more about manual payment methods.

When configuring the payment method, leave the **Payment gateway URL** and **Payment gateways provider class** fields blank. The live site application decides which payment gateway to use based on the method's code name.

**Note**: Payment gateways that you implement in your live site application cannot be used from the administration interface of the Xperience application (for example when manually creating or editing orders).

## Developing payment gateways

In the controller action of the last checkout process step (usually [the order review step](https://docs.kentico.com/13/e-commerce-features/developing-on-line-stores/implementing-a-checkout-process/building-the-order-review-step.md)), redirect the customer to a controller that takes care of the specific payment gateway.

> **Tip:** If you provide multiple payment methods and you need to distinguish their payment gateways, check the cart's payment method code name. For example:
>
> ```csharp
>
>             if (shoppingCart.PaymentOption.PaymentOptionName.Equals("PaymentMethodCodeName"))
>             {
>                 return RedirectToAction("ActionForPayment", "MyPaymentGateway");
>             }
>
>
> ```

> **Note:** Most payment service providers require a specific way of interfacing with their payment service. You need to implement the connection in a way that adheres to the provider's documentation and specification.

The payment gateway then receives a response from the service. Create a new [PaymentResultInfo object](https://docs.kentico.com/13/e-commerce-features/customizing-on-line-stores/payment-related-customizing/working-with-payment-results.md) with information from the response. Use the **UpdateOrderStatus** method of the _OrderInfo_ object representing the order to save the payment result to the database. For example:

```csharp

            if (response != null)
            {
                // Gets the order based on the invoice number from the response
                OrderInfo order = orderInfo.Get(response.InvoiceNo);
                if (order?.OrderSiteID != siteService.CurrentSite.SiteID)
                {
                    order = null;
                }

                // Checks whether the paid amount of money matches the order price
                // and whether the payment was approved
                if (order != null && response.Amount == order.OrderTotalPrice && response.Approved)
                {
                    // Creates a payment result object that will be viewable in Xperience
                    PaymentResultInfo result = new PaymentResultInfo
                    {
                        PaymentDate = DateTime.Now,
                        PaymentDescription = response.Message,
                        PaymentIsCompleted = response.Completed,
                        PaymentTransactionID = response.TransactionID,
                        PaymentStatusValue = response.ResponseCode,
                        PaymentMethodName = "PaymentName"
                    };

                    // Saves the payment result to the database
                    order.UpdateOrderStatus(result);
                }
            }


```

The system sets the [order status](https://docs.kentico.com/13/e-commerce-features/managing-on-line-stores/orders/order-statuses.md) as [configured in the payment method](#configuring-payment-methods-in-xperience).
