Class CheckoutHandler
- Namespace
- Dynamicweb.Ecommerce.Cart
- Assembly
- Dynamicweb.Ecommerce.dll
A CheckoutHandler does all the business logic required to complete an order. Inherit from this base class to extend the checkout logic in Dynamicweb Ecommerce Cart.
public abstract class CheckoutHandler : ConfigurableAddIn
- Inheritance
-
CheckoutHandler
- Derived
- Inherited Members
Remarks
Make use of the Dynamicweb Configurable AddIn API to add editable properties to the checkout handler.
Fields
OrderIdRequestName
Returns the name of the request value that CartV2 should look for in order to forward the call to the CheckoutHandler's Redirect method.
protected static readonly string OrderIdRequestName
Field Value
Properties
CheckoutHandlerOrderId
Gets the OrderId based on the CheckoutHandler redirect parameter.
public static string CheckoutHandlerOrderId { get; }
Property Value
- string
The checkout handler order identifier.
DefaultCheckoutHandler
Returns an instance of DefaultCheckoutHandler.
public static CheckoutHandler DefaultCheckoutHandler { get; }
Property Value
- CheckoutHandler
The default checkout handler.
HasServerCallback
Gets or sets a value indicating whether the payment gateway makes a callback request to the server with payment
transaction details or not.
Use order.SaveGatewayResult to save transaction details in callback processing.
Default value is false
.
protected bool HasServerCallback { get; set; }
Property Value
- bool
true
if this instance has server callback; otherwise,false
.
ShouldRedirectToCheckoutHandler
Gets a value indicating whether CartV2 should redirect to CheckoutHandler.
public static bool ShouldRedirectToCheckoutHandler { get; }
Property Value
- bool
true
if CartV2 should redirect to CheckoutHandler; otherwise,false
.
Methods
BeginCheckout(Order)
This method is called when the checkout procedure is started and the order is handled to the checkout handler.
public OutputResult BeginCheckout(Order order)
Parameters
order
OrderThe order that need to be checked out.
Returns
- OutputResult
The module output.
Remarks
Return a OutputResult to control the flow of checkout, be that content or redirection.
BeginCheckout(Order, CheckoutParameters)
This method is called when the checkout procedure is started in a headless context with custom urls and the order is handled to the checkout handler.
public virtual OutputResult BeginCheckout(Order order, CheckoutParameters parameters)
Parameters
order
OrderThe order that need to be checked out.
parameters
CheckoutParametersParameters to configure how the checkout process should go.
Returns
- OutputResult
The module output.
Remarks
Return a OutputResult to control the flow of checkout, be that content or redirection.
CheckoutDone(Order)
This method should be called when the handler is done with the checkout even if the checkout fails.
protected void CheckoutDone(Order order)
Parameters
order
OrderThe order
GetBaseUrl(Order)
protected virtual string GetBaseUrl(Order order)
Parameters
order
Order
Returns
GetBaseUrl(Order, bool)
Gets the base URL.
protected virtual string GetBaseUrl(Order order, bool headless = false)
Parameters
Returns
- string
System.String.
GetCheckoutHandlerFromPayment(Payment)
Returns the CheckoutHandler from the given payment, or null if it doesn't exist
public static CheckoutHandler GetCheckoutHandlerFromPayment(Payment payment)
Parameters
payment
PaymentThe payment
Returns
- CheckoutHandler
CheckoutHandler.
GetCheckoutHandlerFromPaymentID(string)
Returns the checkout handler from the given payment id, or null if it doesn't exist
public static CheckoutHandler GetCheckoutHandlerFromPaymentID(string paymentID)
Parameters
paymentID
stringId of the payment
Returns
- CheckoutHandler
The CheckoutHandler linked with the payment.
GetOrderFromCallback<T>(CallbackData)
Gets the order from checkout handler callback
public static Order GetOrderFromCallback<T>(CallbackData data) where T : ICheckoutHandlerCallback
Parameters
data
CallbackDataCallback data.
Returns
Type Parameters
T
Checkout handler which implements the ICheckoutHandlerCallback interface.
GetPostedInfo(Order)
Returns all posted info as xml string
protected virtual string GetPostedInfo(Order order)
Parameters
order
OrderThe order
Returns
- string
System.String.
GetSubmitFormResult(string, IDictionary<string, string>)
Gets a OutputResult that can submit a form to e.g. a gateway.
protected static OutputResult GetSubmitFormResult(string formAction, IDictionary<string, string> hiddenInputs)
Parameters
formAction
stringThe url of the action.
hiddenInputs
IDictionary<string, string>Dictionary of input name and input value.
Returns
Remarks
The generated form is posted with javascript. If you need to be able to post without javascript, just render a template with a form and a submit button.
GetSubmitFormResult(string, IDictionary<string, string>, bool)
Gets a OutputResult that can submit a form to e.g. a gateway.
protected static OutputResult GetSubmitFormResult(string formAction, IDictionary<string, string> hiddenInputs, bool urlEncodeAtPost)
Parameters
formAction
stringThe url of the action.
hiddenInputs
IDictionary<string, string>Dictionary of input name and input value.
urlEncodeAtPost
boolIf set to
true
, values are url encoded before post.
Returns
Remarks
The generated form is posted with javascript. If you need to be able to post without javascript, just render a template with a form and a submit button.
HandleRequest(Order)
Function that is called from CartV2 when OrderIdRequestName is in the Request.
Implement this method to receive redirects from CartV2
public virtual OutputResult HandleRequest(Order order)
Parameters
order
OrderThe order with order ID equal to the request OrderIdRequestName
Returns
- OutputResult
Returns the output to the module.
Remarks
The most common use of this method is to receive callbacks and redirect urls from a gateway.
To enable the Redirect method to be called on a callback parse an url with the current page id and the order id in the query string to the gateway as the callback url. The order id must be stored in a query string variable named with the return value of the property OrderIdRequestName of the CheckoutHandler base class.
Return a OutputResult to control the flow of checkout, be that content or redirection.
HideCardNumber(string)
Hide part of card number, e.g. for card number 4711100000009999 it returns XXXXXXXXXXXX9999
protected static string HideCardNumber(string cardNumber)
Parameters
cardNumber
stringThe card number
Returns
- string
System.String.
LogError(Order, Exception, string, params object[])
Logs an error. This is written in the error log and in the event log
protected void LogError(Order order, Exception ex, string message, params object[] args)
Parameters
order
OrderThe current order or null
ex
ExceptionOptional Exception that caused the error
message
stringThe message to log
args
object[]String.Format args to the message
Remarks
It is highly recommended to make use of the logging methods of the CheckoutHandler base class.
The LogError methods creates a text file of all known system information including session variables, server variables and more. All objects logged are parsed and sub-objects stored in properties are also logged down to a certain level.
This log file can easily consume several Mb of disk space, wo use only LogError on true errors. Otherwise use LogEvent.
LogError(Order, string, params object[])
Logs an error. This is written in the error log and in the event log
protected void LogError(Order order, string message, params object[] args)
Parameters
order
OrderThe current order or null
message
stringThe message to log
args
object[]String.Format args to the message
Remarks
It is highly recommended to make use of the logging methods of the CheckoutHandler base class.
The LogError methods creates a text file of all known system information including session variables, server variables and more. All objects logged are parsed and sub-objects stored in properties are also logged down to a certain level.
This log file can easily consume several Mb of disk space, wo use only LogError on true errors. Otherwise use LogEvent.
LogEvent(Order, string, DebuggingInfoType, params object[])
Logs an event. This is written in the event log.
protected void LogEvent(Order order, string message, DebuggingInfoType infoType, params object[] args)
Parameters
order
OrderThe current order or null. This is used to link the log entry to the order.
message
stringThe message to log
infoType
DebuggingInfoTypeType of message to log
args
object[]String.Format args to the message
LogEvent(Order, string, params object[])
Logs an event. This is written in the event log.
protected void LogEvent(Order order, string message, params object[] args)
Parameters
order
OrderThe current order or null. This is used to link the log entry to the order.
message
stringThe message to log
args
object[]String.Format args to the message
Remarks
It is highly recommended to make use of the logging methods of the CheckoutHandler base class.
The LogEvent method creates a single line entry to the event log file, with the time of the event, the order id and the message. If the order given is not null, the entry is also linked to the order, making it visible in the order details view of the admin area.
PassCallbackToCheckoutHandler(Order, CallbackData)
Passes the callback data to checkout handler.
public static OutputResult PassCallbackToCheckoutHandler(Order order, CallbackData data)
Parameters
order
OrderThe order being checked out.
data
CallbackDataCallback data.
Returns
- OutputResult
Return a OutputResult to control the flow of checkout, be that content or redirection.
PassToCart(Order)
This method should be called when ready to pass responsibility back to the cart. Called when the checkout handler is done processing the order for the request and letting the cart finish the request.
protected static OutputResult PassToCart(Order order)
Parameters
order
OrderThe order that is currently being checked out.
Returns
PassToCheckoutHandler()
Passes responsibility for handling the request to the CheckoutHandler. This handler is found through the order created by the id in OrderIdRequestName
public static OutputResult PassToCheckoutHandler()
Returns
- OutputResult
Return a OutputResult to control the flow of checkout, be that content or redirection.
PassToCheckoutHandler(Order)
Passes responsibility for handling the request to the CheckoutHandler. This handler is found through the order created by the id in OrderIdRequestName
public static OutputResult PassToCheckoutHandler(Order order)
Parameters
order
OrderThe order being checked out.
Returns
- OutputResult
Return a OutputResult to control the flow of checkout, be that content or redirection.
Render(Order, Template)
Renders the specified order.
protected virtual string Render(Order order, Template renderingTemplate)
Parameters
Returns
- string
System.String.
RenderInlineForm(Order)
Render inline payment form.
public virtual string RenderInlineForm(Order order)
Parameters
order
OrderThe order that need to be checked out.
Returns
SetOrderComplete(Order)
Performs the logic for setting the order complete
protected void SetOrderComplete(Order order)
Parameters
order
OrderThe order to set complete
Remarks
If you have a transaction number from e.g. a gateway, use SetOrderComplete(Order order, string transactionNumber).
SetOrderComplete(Order, string)
Sets the transaction number and performs the logic for setting the order complete
protected void SetOrderComplete(Order order, string transactionNumber)