Creating payment methods
This topic contains the following:
- Creating a payment method that uses a payment processor
- Creating an offline payment method
For more information about payment processor and payment processor settings, see the Payment processors section.
Creating a payment method that uses a payment process
To create a payment method that uses a payment processor, you must perform the following:
- Get the orders manager.
Get an instance of the OrdersManager object.
- Create new payment method.
To create a new payment method, call the CreatePaymentMethod method of the orders manager.
- Set the properties of the payment method.
In this example the following properties of the PaymentMethod instance are set:
- Title
Gets or sets the title of the payment method.
- PaymentMethod
Gets or sets whether the payment is offline or uses payment processor. In this example the property is set to PaymentMethodType.PaymentProcessor.
- Description
Gets or sets the description of the payment method.
- IsActive
Specifies whether the payment method is active and can be used.
- Set the payment processor.
To set the payment processor, you must perform the following:
- Set the ID of the processor.
For more information about how to get the ID of one of the available payment processor providers, see Querying payment processor providers.
- Set the processor settings.
For the PaymentProcessorSettings property, you must specify a string in JSON format. For more information how to create settings for the different payment processors, see the Payment processors section.
- Save the changes.
Save the changes to the orders manager.
Here is a code example:
public static void CreatePaymentProcessorPaymentMethod(string title, string description, Guid processorId, string PaymentProcessorSettings, bool isActive)
{
OrdersManager ordersManager = OrdersManager.GetManager();
var paymentMethod = ordersManager.CreatePaymentMethod();
paymentMethod.Title = title;
paymentMethod.PaymentMethodType = PaymentMethodType.PaymentProcessor;
paymentMethod.Description = description;
paymentMethod.PaymentProcessorId = processorId;
paymentMethod.PaymentProcessorSettings = PaymentProcessorSettings;
paymentMethod.IsActive = isActive;
ordersManager.SaveChanges();
}
Creating an offline payment method
To create an offline payment method, you must perform the following:
- Get the orders manager.
Get an instance of the OrdersManager object.
- Create new payment method.
To create a new payment method, call the CreatePaymentMethod method of the orders manager.
- Set the properties of the payment method.
In this example the following properties of the PaymentMethod instance are set:
- Title
Gets or sets the title of the payment method.
- PaymentMethod
Gets or sets whether the payment is offline or uses payment processor. In this example the property is set to PaymentMethodType.Offline.
- Description
Gets or sets the description of the payment method.
- IsActive
Specifies whether the payment method is active and can be used.
- Save the changes.
Save the changes to the orders manager.
Here is a code example:
public static void CreateOfflinePaymentMethod(string title, string description, bool isActive)
{
OrdersManager ordersManager = OrdersManager.GetManager();
var paymentMethod = ordersManager.CreatePaymentMethod();
paymentMethod.Title = title;
paymentMethod.PaymentMethodType = PaymentMethodType.Offline;
paymentMethod.Description = description;
paymentMethod.IsActive = isActive;
ordersManager.SaveChanges();
}