Payment methods


List of examples:

Payment methods

Creating a payment method



// 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

Updating a payment method



// 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

Updating multiple payment methods



// 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

Deleting a payment method



// 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

Customer credit

Creating a customer credit event



// 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

Updating a customer credit event



// 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

Updating multiple customer credit events



// 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

Getting a customer’s total credit



// 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

Deleting a customer credit event



// 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