> This page is for Afterpay Button Documentation.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://developers.afterpay.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://developers.afterpay.com/_mcp/server.

# Mobile Redirection

On Mobile, instead of a QR code, the customer is redirected to the Cash App. When the customer approves, the customer is taken back to the url specified in the `redirectConfirmUrl` in the `initializeForCashAppPay` call. This can be the same page where the Cash App Pay button is rendered e.g. `merchant.com/checkout`, or a new page e.g. `merchant.com/review`

> **Query Params can be added to the \`redirectConfirmURL\`**
>
> If you want to determine if the page is loading as a result of redirect from the Cash App, you can add a query param to your redirectConfirmURL. e.g. `merchant.com/checkout?cashapppay=true`
>
> **The `redirectCancelURL` is not used by Cash App Pay**
>
> On mobile, the customer will always be redirected to the `redirectConfirmUrl` for approved and declined flows

The page the `redirectConfirmUrl` points to should initialize afterpay-button.js and define the below `onComplete` callback on page load. The data returned by `onComplete` includes the [virtual card object](/afterpay-button-documentation/guides/afterpay-button/getting-started/process-the-credit-card) and customer's cashtag.

```javascript
function onPageLoad () {
  var cashAppPayListenerOptions = { 
        onComplete: function(event) {
          // event.data includes the virtual card object + customer's cashtag
          const { status, virtualCard, token, cashtag } = event.data;
        },
        eventListeners: {
            "CUSTOMER_INTERACTION": ({ isMobile }) => {
                console.log(`CUSTOMER_INTERACTION`)
                if (isMobile) {
                    // Capture mobile metrics
                } else {
                    // Capture desktop metrics
                };
            },
            "CUSTOMER_DISMISSED": () => {
              console.log(`CUSTOMER_REQUEST_FAILED`);
            },
            "CUSTOMER_REQUEST_DECLINED": () => {
                console.log(`CUSTOMER_REQUEST_DECLINED`)
            },
              "CUSTOMER_REQUEST_APPROVED": () => {
                console.log(`CUSTOMER_REQUEST_APPROVED`)
            },
            "CUSTOMER_REQUEST_FAILED": () => {
                console.log(`CUSTOMER_REQUEST_FAILED`)
            }
        }
      }

    AfterPay.initializeCashAppPayListeners({countryCode: "US", cashAppPayListenerOptions});
}
```