---
title: Making payment methods dependent on shipping options
related:
  - https://docs.kentico.com/13/e-commerce-features/configuring-on-line-stores/configuring-payment-methods.md
  - https://docs.kentico.com/13/e-commerce-features/configuring-on-line-stores/configuring-shipping-options.md
  - https://docs.kentico.com/13/custom-development/customizing-providers.md
  - https://docs.kentico.com/13/e-commerce-features/customizing-on-line-stores/payment-related-customizing.md
  - https://docs.kentico.com/13/e-commerce-features/customizing-on-line-stores/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/13/e-commerce-features/configuring-on-line-stores/configuring-payment-methods.md) based on a specified [shipping option](https://docs.kentico.com/13/e-commerce-features/configuring-on-line-stores/configuring-shipping-options.md), shipping country or a different attribute from the shopping cart, you need to customize the **PaymentOptionInfoProvider** class from the **CMS.Ecommerce** namespace.

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

> **Note:** **Note**: The example assumes that the code name of the corresponding payment method is _PayPal_.

Prepare an assembly (_Class Library_ project) with class discovery enabled in your Xperience solution (or use an existing one). See [Adding custom assemblies](https://docs.kentico.com/13/custom-development/adding-custom-assemblies.md). - Reference the project from both your live site and Xperience administration (_CMSApp_) projects.

Continue by creating a custom implementation of the _PaymentOptionInfoProvider_ class:

1. Add a new class under the custom project, for example named **CustomPaymentOptionInfoProvider**.
2. Make the class inherit from the **PaymentOptionInfoProvider** class.
3. [Register](https://docs.kentico.com/13/custom-development/customizing-providers/registering-providers-using-assembly-attributes.md) the custom provider class using the **RegisterCustomProvider** assembly attribute.
4. Override the provider's **IsPaymentOptionApplicableInternal**method:

   ```csharp

   using System;

   using CMS;
   using CMS.Ecommerce;
   using CMS.Globalization;

   [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 payment methods except for PayPal
           if (!paymentOption.PaymentOptionName.Equals("PayPal", StringComparison.InvariantCultureIgnoreCase))
           {
               return true;
           }

           // Disables PayPal if the billing address is within the USA
           if (cart.ShoppingCartBillingAddress != null)
           {
               CountryInfo country = CountryInfo.Provider.Get(cart.ShoppingCartBillingAddress.AddressCountryID);
               if ((country != null) && 
                   country.CountryThreeLetterCode.Equals("USA", StringComparison.InvariantCultureIgnoreCase))
               {
                   return false;
               }
           }

           // Disables PayPal if the USPS shipping method is selected
           return (cart.ShippingOption == null) ||
               !cart.ShippingOption.ShippingOptionName.Equals("USPS", StringComparison.InvariantCultureIgnoreCase);
       }
   }

   ```
5. Save all changes and **Build** the custom project.

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

> **Tip:** If you want to allow users to configure the payment method limitations in the administration interface, you can either [create a custom module with an interface](https://docs.kentico.com/13/custom-development/creating-custom-modules.md) or [create a custom table](https://docs.kentico.com/13/developing-websites/defining-website-content-structure/managing-custom-tables/creating-custom-tables.md) and use the [custom table API](https://docs.kentico.com/13/developing-websites/defining-website-content-structure/managing-custom-tables/custom-table-internals-and-api.md) to add the values for the _Dictionary_ variable with the limitations. Do not forget to set caching (you can use the [CacheHelper](https://docs.kentico.com/13/configuring-xperience/configuring-caching/caching-in-custom-code.md) class).
