Table of Contents

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 to checkout logic in Dynamicweb Ecommerce Cart.
public abstract class CheckoutHandler : ConfigurableAddIn
Inheritance
CheckoutHandler
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

string
See Also

Properties

CheckoutHandlerOrderId

Gets the OrderId based on the CheckoutHandler redirect parameter.
public static string CheckoutHandlerOrderId { get; }

Property Value

string
The checkout handler order identifier.
See Also

DefaultCheckoutHandler

Returns an instance of DefaultCheckoutHandler.
public static CheckoutHandler DefaultCheckoutHandler { get; }

Property Value

CheckoutHandler
The default checkout handler.
See Also

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.
See Also

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.
See Also

Methods

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 Order
The order

Examples

Public Overrides Function StartCheckout(ByVal order As eCommerce.Orders.Order) As String
    LogEvent(order, "StartCheckout")
    Try
    SetOrderComplete(order)
    LogEvent(order, "SetOrderComplete succeeded")
    Catch ex As Exception
    LogError(order, "SetOrderComplete failed with the message: {0}", ex.Message)
    End Try
    CheckoutDone(order)
    RedirectToCart(order)
    Return Nothing
    End Function
See Also

GetBaseUrl(Order)

Gets the base URL.
protected virtual string GetBaseUrl(Order order)

Parameters

order Order
The order.

Returns

string
System.String.
See Also

GetCheckoutHandlerFromPayment(Payment)

Returns the CheckoutHandler from the given payment, or null if it doesn't exist
public static CheckoutHandler GetCheckoutHandlerFromPayment(Payment payment)

Parameters

payment Payment
The payment

Returns

CheckoutHandler
CheckoutHandler.

Examples

Payment myPayment;
    ...
    CheckoutHandler myCheckoutHandler = CheckoutHandler.GetCheckoutHandlerFromPayment(myPayment);
See Also

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 string
Id of the payment

Returns

CheckoutHandler
The CheckoutHandler linked with the payment.

Examples

string myPaymentId;
    ...
    CheckoutHandler myCheckoutHandler = CheckoutHandler.GetCheckoutHandlerByPaymentId(myPaymentId);
See Also

GetCheckoutHandlerFromPaymentID(string, string)

Returns the checkout handler from the given payment id, or null if it doesn't exist
public static CheckoutHandler GetCheckoutHandlerFromPaymentID(string paymentID, string langID)

Parameters

paymentID string
Id of the payment
langID string
The Language code

Returns

CheckoutHandler
The CheckoutHandler linked with the payment.

Examples

string myPaymentId;
    ...
    CheckoutHandler myCheckoutHandler = CheckoutHandler.GetCheckoutHandlerByPaymentId(myPaymentId);
See Also

GetPostedInfo(Order)

Returns all posted info as xml string
protected virtual string GetPostedInfo(Order order)

Parameters

order Order
The order

Returns

string
System.String.

Examples

Order myOrder;
    Get transaction number from gateway
    string transNum;
    ...
    Set the order complete
    SetOrderComplete(myOrder, transNum);
See Also

HideCardNumber(string)

Hide part of card number, e.g. for card number 4711100000009999 it returns XXXXXXXXXXXX9999
protected static string HideCardNumber(string cardNumber)

Parameters

cardNumber string
The card number

Returns

string
System.String.
See Also

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 Order
The current order or null
ex Exception
Optional Exception that caused the error
message string
The message to log
args object[]
String.Format args to the message

Examples

Order myOrder;
    ...
    LogError(myOrder, "Something happened in the flow");
Order myOrder;
    string eventMessage;
    ...
    LogEvent(myOrder, "Something happened in the flow: {0}", eventMessage);

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.

See Also

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 Order
The current order or null
message string
The message to log
args object[]
String.Format args to the message

Examples

Order myOrder;
    ...
    LogError(myOrder, "Something happened in the flow");
Order myOrder;
    string eventMessage;
    ...
    LogEvent(myOrder, "Something happened in the flow: {0}", eventMessage);

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.

See Also

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 Order
The current order or null. This is used to link the log entry to the order.
message string
The message to log
infoType DebuggingInfoType
Type of message to log
args object[]
String.Format args to the message
See Also

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 Order
The current order or null. This is used to link the log entry to the order.
message string
The message to log
args object[]
String.Format args to the message

Examples

Order myOrder;
    ...
    LogEvent(myOrder, "Something happened in the flow");
Order myOrder;
    string eventMessage;
    ...
    LogEvent(myOrder, "Something happened in the flow: {0}", eventMessage);

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.

See Also

Redirect(Order)

Function that is called from CartV2 when OrderIdRequestName is in the Request.

Implement this method to receive redirects from CartV2

public abstract string Redirect(Order order)

Parameters

order Order
The order with order ID equal to the request OrderIdRequestName

Returns

string
Returns the output to the module.

Examples

//Write the port if it is not default
    var portString = HttpContext.Current.Request.Url.IsDefaultPort ? "" : string.Format(":{0}", HttpContext.Current.Request.Url.Port);
    var pageId = Dynamicweb.Context.Current.Request("ID") == null ? string.Empty : string.Format("ID={0}&", Dynamicweb.Context.Current.Request("ID"));
    Url
    var myUrl = string.Format("{0}://{1}{2}/Default.aspx?{3}{4}={5}",
    HttpContext.Current.Request.Url.Scheme,
    HttpContext.Current.Request.Url.Host,
    portString,
    pageId,
    OrderIdRequestName,
    order.Id);

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 string to control the module output. If a redirect is made within the method, it is not needed to return a string.

See Also

RedirectToCart(Order)

This method should be called when ready to redirect back to the cart.
protected void RedirectToCart(Order order)

Parameters

order Order
The order.

Examples

Public Overrides Function StartCheckout(ByVal order As eCommerce.Orders.Order) As String
    LogEvent(order, "StartCheckout")
    Try
    SetOrderComplete(order)
    LogEvent(order, "SetOrderComplete succeeded")
    Catch ex As Exception
    LogError(order, "SetOrderComplete failed with the message: {0}", ex.Message)
    End Try
    CheckoutDone(order)
    RedirectToCart(order)
    Return Nothing
    End Function
See Also

RedirectToCheckoutHandler()

Shared function to redirect to the custom CheckoutHandler. This handler is found through the order created by the id in OrderIdRequestName
public static string RedirectToCheckoutHandler()

Returns

string
System.String.
See Also

Render(Order, Template)

Renders the specified order.
protected virtual string Render(Order order, Template template)

Parameters

order Order
The order.
template Template
The template.

Returns

string
System.String.
See Also

RenderInlineForm(Order)

Render inline payment form.
public virtual string RenderInlineForm(Order order)

Parameters

order Order
The order that need to be checked out.

Returns

string
See Also

SetOrderComplete(Order)

Performs the logic for setting the order complete
protected void SetOrderComplete(Order order)

Parameters

order Order
The order to set complete

Examples

Public Overrides Function StartCheckout(ByVal order As eCommerce.Orders.Order) As String
    LogEvent(order, "StartCheckout")
    Try
    SetOrderComplete(order)
    LogEvent(order, "SetOrderComplete succeeded")
    Catch ex As Exception
    LogError(order, "SetOrderComplete failed with the message: {0}", ex.Message)
    End Try
    CheckoutDone(order)
    RedirectToCart(order)
    Return Nothing
    End Function

Remarks

If you have a transaction number from e.g. a gateway, use SetOrderComplete(Order order, string transactionNumber).
See Also

SetOrderComplete(Order, string)

Sets the transaction number and performs the logic for setting the order complete
protected void SetOrderComplete(Order order, string transactionNumber)

Parameters

order Order
The order to set complete
transactionNumber string
The transaction number

Examples

Order myOrder;
    Get transaction number from gateway
    string transNum;
    ...
    Set the order complete
    SetOrderComplete(myOrder, transNum);
See Also

StartCheckout(Order)

This method is called when the checkout procedure is started and the order is handled to the checkout handler.
public abstract string StartCheckout(Order order)

Parameters

order Order
The order that need to be checked out.

Returns

string
The module output.

Examples

Public Overrides Function StartCheckout(ByVal order As eCommerce.Orders.Order) As String
LogEvent(order, "StartCheckout")
Try
SetOrderComplete(order)
LogEvent(order, "SetOrderComplete succeeded")
Catch ex As Exception
LogError(order, "SetOrderComplete failed with the message: {0}", ex.Message)
End Try
CheckoutDone(order)
RedirectToCart(order)
Return Nothing
End Function

Remarks

Return a string to control the module output. If a redirect is made, like in the example, it is not needed to return a string.
See Also

SubmitForm(string, IDictionary<string, string>)

Submits a form to e.g. a gateway
protected void SubmitForm(string formAction, IDictionary<string, string> hiddenInputs)

Parameters

formAction string
The url of the action
hiddenInputs IDictionary<string, string>
Dictionary of input name and input value

Examples

string myMerchant;
    string myPriceFormatted;
    string myCurrency;
    ...
    var formValues = new Dictionary<string, string>
    {
    {"merchant", myMerchantId},
    {"amount", myPriceFormatted},
    {"currency", myCurrency}
    }
    SubmitForm("https://secure.somegateway.com/authorize", formValues);

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.
See Also

SubmitForm(string, IDictionary<string, string>, bool)

Submits a form to e.g. a gateway
protected void SubmitForm(string formAction, IDictionary<string, string> hiddenInputs, bool urlEncodeAtPost)

Parameters

formAction string
The url of the action
hiddenInputs IDictionary<string, string>
Dictionary of input name and input value
urlEncodeAtPost bool
if set to true [URL encode at post].

Examples

string myMerchant;
    string myPriceFormatted;
    string myCurrency;
    ...
    var formValues = new Dictionary<string, string>
    {
    {"merchant", myMerchantId},
    {"amount", myPriceFormatted},
    {"currency", myCurrency}
    }
    SubmitForm("https://secure.somegateway.com/authorize", formValues);

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.
See Also

See Also

To top