Complete the order

When the customer clicks a button to submit the order, the Store API createOrder endpoint is called.

The request includes a parameter ("op":"complete") to specify that a previously initiated order is being completed. The request must also include the order ID and the payment group ID.

The server invokes the Generic Payment webhook, which sends an authorization transaction request to the checkout system. Any custom properties in the order are included in the webhook request. The webhook response should indicate whether the authorization succeeded. If the authorization succeeds, the order is submitted and the shopper is redirected to the Order Confirmation page.

Validate the data

Before submitting the order, it is a good idea to validate the data being sent, including any custom properties. To do this, you can register a callback function with the OrderViewModel that is executed when the handlePlaceOrder() function is called. You can use the callback function to add validation and error handling.

The code below registers a callback function that validates the widget data. This function first calls the widget’s validate() function. If that function returns true, the callback function adds a custom property to the payment data in the OrderViewModel. If widget.validate() returns false, the callback function adds a validation error to the OrderViewModel.

widget.validate = function {
  return true;
}

widget.order().addValidationCallback(function() {

if (widget.validate()) {
    var customProperties = {genericPaymentId: widget.genericPaymentId};
    widget.genericPayment.customProperties = customProperties;
    widget.updatePayment(widget.genericPayment);
    }
    else {
    widget.order().addValidationError("genericPayment",
      widget.translate('errorMessage'));
    }
});