---
title: Payment methods
---

> 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).

List of examples:

## Payment methods

### Creating a payment method

```csharp

// Creates a new payment method object
PaymentOptionInfo newMethod = new PaymentOptionInfo();

// Sets the payment method properties
newMethod.PaymentOptionDisplayName = "New method";
newMethod.PaymentOptionName = "NewMethod";
newMethod.PaymentOptionSiteID = SiteContext.CurrentSiteID;
newMethod.PaymentOptionEnabled = true;

// Saves the payment method to the database
PaymentOptionInfo.Provider.Set(newMethod);

```

[> Back to list of examples](#toc)

### Updating a payment method

```csharp

// Gets the payment method
PaymentOptionInfo updateMethod = PaymentOptionInfo.Provider.Get("NewMethod", SiteContext.CurrentSiteID);

if (updateMethod != null)
{
    // Updates the payment method properties
    updateMethod.PaymentOptionDisplayName = updateMethod.PaymentOptionDisplayName.ToLowerCSafe();

    // Saves the changes to the database
    PaymentOptionInfo.Provider.Set(updateMethod);
}

```

[> Back to list of examples](#toc)

### Updating multiple payment methods

```csharp

// Gets all payment methods on the current site whose code name starts with 'New'
var methods = PaymentOptionInfo.Provider.Get()
                                          .OnSite(SiteContext.CurrentSiteID)
                                          .WhereStartsWith("PaymentOptionName", "New");

// Loops through the payment methods
foreach (PaymentOptionInfo method in methods)
{
    // Updates the payment method properties
    method.PaymentOptionDisplayName = method.PaymentOptionDisplayName.ToUpperCSafe();

    // Saves the changes to the database
    PaymentOptionInfo.Provider.Set(method);
}

```

[> Back to list of examples](#toc)

### Deleting a payment method

```csharp

// Gets the payment method
PaymentOptionInfo deleteMethod = PaymentOptionInfo.Provider.Get("NewMethod", SiteContext.CurrentSiteID);

if (deleteMethod != null)
{
    // Deletes the payment method from the database
    PaymentOptionInfo.Provider.Delete(PaymentOptionInfo.Provider.Get(deleteMethod.PaymentOptionID));
}

```

[> Back to list of examples](#toc)

## Customer credit

### Creating a customer credit event

```csharp

// Gets the first customer whose last name is 'Smith'
CustomerInfo customer = CustomerInfo.Provider.Get()
                                            .WhereEquals("CustomerLastName", "Smith")
                                            .TopN(1)
                                            .FirstOrDefault();

if (customer != null)
{
    // Creates a new credit event object and sets up its properties
    CreditEventInfo newEvent = new CreditEventInfo
    {
        EventName = "New event",
        EventCreditChange = 500,
        EventDate = DateTime.Now,
        EventDescription = "Credit event description.",
        EventCustomerID = customer.CustomerID,
        EventSiteID = SiteContext.CurrentSiteID
    };

    // Saves the credit event to the database
    CreditEventInfo.Provider.Set(newEvent);
}

```

[> Back to list of examples](#toc)

### Updating a customer credit event

```csharp

// Gets the credit event
CreditEventInfo updateCredit = CreditEventInfo.Provider.Get()
                                            .WhereEquals("EventName", "NewEvent")
                                            .TopN(1)
                                            .FirstOrDefault();

if (updateCredit != null)
{
    // Updates the customer credit event properties
    updateCredit.EventName = updateCredit.EventName.ToLowerCSafe();

    // Saves the changes to the database
    CreditEventInfo.Provider.Set(updateCredit);
}

```

[> Back to list of examples](#toc)

### Updating multiple customer credit events

```csharp

// Gets all customer credit events whose name starts with 'New'
var credits = CreditEventInfo.Provider.Get().WhereStartsWith("EventName", "New");

// Loops through the credit events
foreach (CreditEventInfo updateCredit in credits)
{
    // Updates the credit event properties
    updateCredit.EventName = updateCredit.EventName.ToUpperCSafe();

    // Saves the changes to the database
    CreditEventInfo.Provider.Set(updateCredit);
}

```

[> Back to list of examples](#toc)

### Getting a customer's total credit

```csharp

// Gets the first customer whose last name is 'Smith'
CustomerInfo customer = CustomerInfo.Provider.Get()
                                            .WhereEquals("CustomerLastName", "Smith")
                                            .TopN(1)
                                            .FirstOrDefault();

if (customer != null)
{
    // Gets the customer's total credit on the current site
    decimal totalCredit = CreditEventInfoProvider.GetTotalCredit(customer.CustomerID, SiteContext.CurrentSiteID);
}

```

[> Back to list of examples](#toc)

### Deleting a customer credit event

```csharp

// Gets the credit event
CreditEventInfo deleteCredit = CreditEventInfo.Provider.Get()
                                                .WhereStartsWith("EventName", "New")
                                                .TopN(1)
                                                .FirstOrDefault();

if (deleteCredit != null)
{
    // Deletes the credit event from the database
    CreditEventInfo.Provider.Delete(deleteCredit);
}

```

[> Back to list of examples](#toc)
