---
title: Making payment methods dependent on shipping options
related:
  - https://docs.kentico.com/k10/e-commerce-features/configuring-your-store/configuring-payment-methods.md
  - https://docs.kentico.com/k10/e-commerce-features/configuring-your-store/configuring-shipping-options.md
  - https://docs.kentico.com/k10/custom-development/customizing-providers.md
  - https://docs.kentico.com/k10/e-commerce-features/customizing-and-developing-your-store/payment-related-customizing.md
  - https://docs.kentico.com/k10/e-commerce-features/customizing-and-developing-your-store/shipping-related-customizing/implementing-custom-shipping-carrier-providers.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).

If you want to limit the availability of [payment methods](https://docs.kentico.com/k10/e-commerce-features/configuring-your-store/configuring-payment-methods.md) based on a specified [shipping option](https://docs.kentico.com/k10/e-commerce-features/configuring-your-store/configuring-shipping-options.md), shipping country or a different attribute from the shopping cart, you need to customize the **PaymentOptionProvider** class from the **CMS.Ecommerce** namespace.

The following example disables the _PayPal_ payment method when the [customer](https://docs.kentico.com/k10/e-commerce-features/managing-your-store/customers.md) selects USA in the shipping address or selects _USPS_ as the shipping option.

1. Open your Kentico project in Visual Studio.
2. Create a new class in the **App\_Code** folder (or **Old\_App\_Code** on web application installations). For example, name the class **CustomPaymentOptionInfoProvider**.
3. Make the class inherit from the **PaymentOptionInfoProvider** class.
4. Add _using_ statements for the **CMS**, **CMS.Base** and **CMS.Ecommerce** namespaces.
5. [Register](https://docs.kentico.com/k10/custom-development/customizing-providers/registering-providers-using-assembly-attributes.md) the new InfoProvider class:

   ```csharp

   [assembly: RegisterCustomProvider(typeof(CustomPaymentOptionInfoProvider))]

   ```
6. Override the **IsPaymentOptionApplicable**method:

   ```csharp

   using CMS;
   using CMS.Ecommerce;
   using CMS.Base;

   [assembly: RegisterCustomProvider(typeof(CustomPaymentOptionInfoProvider))]
   public class CustomPaymentOptionInfoProvider : PaymentOptionInfoProvider
   {
       protected override bool IsPaymentOptionApplicableInternal(ShoppingCartInfo cart, PaymentOptionInfo paymentOption)
       {
           // Does not check availability if the shopping cart or payment option is not available.
           if ((cart == null) || (paymentOption == null))
           {
               return true;
           }

           // Allows all methods except PayPal.
           if (!paymentOption.PaymentOptionName.EqualsCSafe("PayPal"))
           {
               return true;
           }

           // Forbids PayPal within USA.
           if ((cart.ShoppingCartBillingAddress != null) &&
               cart.ShoppingCartBillingAddress.GetCountryThreeLetterCode().EqualsCSafe("USA"))
           {
               return false;
           }

           // Forbids PayPal if the USPS shipping method is selected.
           return (cart.ShippingOption == null) || !cart.ShippingOption.ShippingOptionName.EqualsCSafe("USPS");
       }
   }

   ```
7. Save your project and reload you Kentico website.

If a customer now selects the USA as their country or selects _USPS_ as their shipping option, they will not be able to use _PayPal_ as the payment method.

> **Tip:** If you want to use the user interface for setting the limitations, you can either [create a user interface](https://docs.kentico.com/k10/custom-development/creating-custom-modules/manually-creating-the-interface-for-custom-modules.md) or [create a custom table](https://docs.kentico.com/k10/developing-websites/defining-website-content-structure/custom-tables/creating-custom-tables.md) and use the [custom table API](https://docs.kentico.com/k10/custom-development/custom-table-internals-and-api.md) to add the values for the _Dictionary_ variable with the limitations. Do not forget to [set caching](https://docs.kentico.com/k10/configuring-kentico/optimizing-website-performance/configuring-caching.md) (you can use the [CacheHelper](https://docs.kentico.com/k10/custom-development/caching-in-custom-code.md) class).
