---
title: Payment gateways in MVC
related:
  - https://docs.kentico.com/k11/developing-websites/developing-sites-using-asp-net-mvc/developing-on-line-stores-in-mvc/checkout-process-in-mvc/preview-step-in-mvc-checkout.md
  - https://docs.kentico.com/k11/developing-websites/developing-sites-using-asp-net-mvc/developing-on-line-stores-in-mvc/checkout-process-in-mvc.md
  - https://docs.kentico.com/k11/e-commerce-features/configuring-your-store/configuring-payment-methods.md
  - https://docs.kentico.com/k11/e-commerce-features/customizing-and-developing-your-store/payment-related-customizing/working-with-payment-results.md
  - https://docs.kentico.com/k11/e-commerce-features/managing-your-store/orders.md
  - https://docs.kentico.com/k11/e-commerce-features/managing-your-store/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 you build the [checkout process on your MVC site](https://docs.kentico.com/k11/developing-websites/developing-sites-using-asp-net-mvc/developing-on-line-stores-in-mvc/checkout-process-in-mvc.md), you may want to enable [customers](https://docs.kentico.com/k11/e-commerce-features/managing-your-store/customers.md) to pay directly via a payment gateway (for example, PayPal or credit card) when they create an [order](https://docs.kentico.com/k11/e-commerce-features/managing-your-store/orders.md).

When using [the MVC development framework](https://docs.kentico.com/k11/developing-websites/developing-sites-using-asp-net-mvc.md), you need to [implement](#developing-payment-gateways-in-mvc-applications) payment gateways for the payment methods in the MVC application and [add the related payment methods to Kentico](#configuring-payment-methods-in-kentico). You cannot use the default payment gateways in Kentico (PayPal and Authorize.NET).

On this page, you can find how to work with API of the [Kentico.Ecommerceintegration package](https://docs.kentico.com/k11/developing-websites/developing-sites-using-asp-net-mvc/starting-with-mvc-development/installing-kentico-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.

## Configuring payment methods in Kentico

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

> **Tip:** See [Configuring payment methods](https://docs.kentico.com/k11/e-commerce-features/configuring-your-store/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 MVC application decides which payment gateway to use based on the method's [code name](https://docs.kentico.com/k11/e-commerce-features/configuring-your-store/configuring-payment-methods/reference-payment-methods.md).

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

## Developing payment gateways in MVC applications

In the controller action of the last checkout process step (usually [the preview step](https://docs.kentico.com/k11/developing-websites/developing-sites-using-asp-net-mvc/developing-on-line-stores-in-mvc/checkout-process-in-mvc/preview-step-in-mvc-checkout.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.PaymentMethod.PaymentOptionName.Equals("PaymentMethodCodeName"))
>             {
>                 return RedirectToAction("ActionForPayment", "MyPaymentGateway");
>             }
>
>
> ```

Since most services require a different approach to connecting with them, you need to implement the connection based on their documentation.

The payment gateway then receives a response from the service. Create a new [PaymentResultInfoobject](https://docs.kentico.com/k11/e-commerce-features/customizing-and-developing-your-store/payment-related-customizing/working-with-payment-results.md) with information from the response. Use the **SetPaymentResult** method of the **Order** class 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
                Order order = orderRepository.GetById(response.InvoiceNo);

                // Checks whether the paid amount of money matches the order price
                // and whether the payment was approved
                if (response.Amount == order.TotalPrice && response.Approved)
                {
                    // Creates a payment result object that will be viewable in Kentico
                    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.SetPaymentResult(result);
                }
            }


```

Kentico sets the [order status](https://docs.kentico.com/k11/e-commerce-features/managing-your-store/orders/order-statuses.md) as [configured in the payment method](#configuring-payment-methods-in-kentico).
