How to Retrieve All Payment Methods
For the latest version of Commerce Server 2007 Help, see the Microsoft Web site.
A payment method is a way that the customer can pay for orders. "CreditCard" and "GiftCertificate" are examples of payment methods. You can retrieve all the payment methods that are configured for the site from the PaymentMethodCollection member of the PaymentMethodManager object.
To retrieve all payment methods
Create an OrderManagementContext object.
For more information about how to perform this step, see How to Create an OrderManagementContext Object.
Get the PaymentMethodManager object from the OrderManagementContext object.
Get the PaymentMethodCollection member from the PaymentMethodManager object.
Example
The following code example displays the name and ID of each payment method.
using System;
using System.Data;
using Microsoft.CommerceServer;
using Microsoft.CommerceServer.Orders;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
try
{
// Create the OrderManagementContext object. This
// example accesses the Orders System in local mode by
// creating an OrderSiteAgent object. You could also
// access the Orders System in agent mode by creating
// an OrderServiceAgent object.
// In the following, replace "StarterSite" with the
// name of your site.
OrderSiteAgent ordersAgent = new OrderSiteAgent("StarterSite");
OrderManagementContext context = OrderManagementContext.Create(ordersAgent);
// Get the PaymentMethodManager object.
PaymentMethodManager manager = context.PaymentMethodManager;
// Get the collection of all payment methods.
PaymentMethodCollection paymentMethods = manager.PaymentMethods;
// Retrieve and display information about each
// payment method.
foreach (PaymentMethod method in paymentMethods)
{
string methodName = method.GetPaymentMethodName();
Guid groupId = method.PaymentGroupId;
Console.WriteLine("Name: {0} Group ID: {1}", methodName, groupId);
}
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine("Exception: {0}\r\nMessage: {1}", ex.GetType(), ex.Message);
if (ex.InnerException != null)
{
Console.WriteLine("\r\nInner Exception: {0}\r\nMessage: {1}", ex.InnerException.GetType(), ex.InnerException.Message);
}
Console.ReadLine();
}
}
}
}
Compiling the Code
To run this code example, create a console application and add references to the following assemblies:
Microsoft.CommerceServer.CrossTierTypes.dll
Microsoft.CommerceServer.Orders.CrossTierTypes.dll
Microsoft.CommerceServer.Orders.DataManagement.dll