It looks like you're using Google Chrome - try our powerful extension! Find out more. Add to Chrome
x

Handling Successful Embedded Actions

Once a successful action has been performed on an embedded component (such as a successful payment or card saved), you have a few options for handling the result. You should also verify the response came from ChargeDesk if using the results to perform business logic.

Option 1: Do Nothing

There is no need to handle successful actions on embedded pages if you don't wish to. If you don't add a specific method for handling the successful response, an informative message will be displayed to the customer letting them know that the action was performed successfully. The charge will still be successfully created, or card saved without any action from you. This data will be passed to your payment gateway and synced to ChargeDesk automatically.

Option 2: Use the 'successURL' field

You can enter a URL to redirect the customer to on a successful action using the successURL field. Typically this will be another page on your site which lets the customer know the action was performed successfully. You can include any of the response fields listed below in this URL using by wrapping them in {}. For example, to obtain the customer id and charge id, you could use the following URL.

successURL: "https://yourdomain.com/success?customer={customer_id}&charge={charge_id}"

To perform business logic based on the result, you should only use the secure parameters e.g.

successURL: "https://yourdomain.com/success?secure_response={secure_response}"

Option 3: Use the 'onSuccess' handler

The final option is to handle a successful result programmatically using the onSuccess handler. This will call a JavaScript function which you can use to decide how to handle the response. The response fields in the next section will be available on the response object.

Please note: If you provide both a successURL and an onSuccess handler, the onSuccess handler will be ignored. If you provide an onSuccess handler then no message will be shown to the user on a successful action (the embedded component will be blank), so you should inform the user that the action was a success.

onSuccess: function(response) {
    alert("Success: "+response.msg+" Your customer ID is "+response.customer_id);
}

Response Fields

The following fields may available to be replaced in the successURL and as keys in the response object for the onSuccess handler. The available fields depends on the type of the action performed and the payment gateway used.