Checkout beforeRedirect

beforeRedirect Callback

The beforeRedirect callback is invoked before browser redirects occur during the payment flow. The return value of the callback will be stored until the browser is returned to the merchant page. The value can be recovered with the afterRedirect callback.

Payment method such as PayPal requires the browser to be redirected away from a merchant page.


Usage Copied to clipboard

The beforeRedirect callback must be defined using the data-beforeRedirect attribute on the Checkout script tag. The attribute value must be the name of a global function.


Example Copied to clipboard

<html>
    <head>
        <script src="https://na.gateway.mastercard.com/checkout/version/59/checkout.js"
                data-beforeRedirect="getPageState"></script>
            
        <script type="text/javascript">
                function getPageState() {
                    return {
                        foo: "string",
                        bar: 123.45
                    };
                }
        </script>
    </head>
    ...
</html>

Arguments Copied to clipboard

None


Return Value Copied to clipboard

data Copied to clipboard Object

A JSON serializable object.