> ## Documentation Index
> Fetch the complete documentation index at: https://dev.moonpay.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Pay with Cash App

> Let customers link Cash App once, then buy crypto with it from the buy button.

Use this guide to let a connected customer buy crypto with Cash App. The customer links Cash App once. MoonPay saves it as a payment method, like a card, and the customer pays with it on later purchases.

Cash App needs a signed-in customer to hold the linked account. It isn't available in [guest checkout](https://dev.moonpay.com/platform/guides/guest-checkout.md).

See the [Going Live](https://dev.moonpay.com/platform/overview/going-live.md) section for details on the requirements you must meet before you can take this integration to production.

## Prerequisites

* A connected customer (via `client.getConnection()` or `client.connect()`).
* `@moonpay/platform-sdk-web` or `@moonpay/platform-sdk-react-native` 1.35.0 or later.
* A UI surface where you can render the [Buy Button frame](https://dev.moonpay.com/platform/frames/buy-button.md). For a Cash App quote, it renders the Cash App button.
* In a native app or a desktop browser, code that handles the Cash App link when the frame asks for it. See [Native apps](#native-apps) and [Desktop browsers](#desktop-browsers).

## Flow overview

The first time, the customer links Cash App on the button. After that, the same button pays.

```mermaid theme={null}
sequenceDiagram
    autonumber
    actor C as Customer
    participant FE as Your frontend
    participant API as MoonPay API
    participant BBF as Buy Button frame
    participant CA as Cash App

    Note over C,CA: Prerequisite: customer is connected

    FE->>API: GET /platform/v1/payment-methods
    API-->>FE: { paymentMethodConfigs: [{ type: "cash_app", availability }] }

    C->>FE: Enters amount
    FE->>API: POST /platform/v1/quotes/buy
    API-->>FE: { quote }

    FE->>BBF: Render buy button
    BBF-->>FE: ready

    alt Cash App not linked yet
        C->>BBF: Taps "Connect Cash App"
        BBF->>CA: Opens the Cash App link (a tab on a phone)
        BBF-->>FE: challenge({ kind: "link_payment_method", url, qrCodeSvgUrl })
        Note over FE: In an app, open url. On a desktop, show the QR code.
        C->>CA: Approves the link
        BBF->>BBF: Saves Cash App as a payment method
        BBF-->>FE: resolved({ kind: "link_payment_method", paymentMethod })
        Note over BBF: Button now reads "Pay with $cashtag"
    end

    C->>BBF: Taps "Pay with $cashtag"
    alt Happy path
        BBF-->>FE: complete({ transaction: { id, status } })
    else Verification required
        BBF-->>FE: challenge({ kind: "frame", url })
    end

    FE->>API: GET /platform/v1/transactions/{id}
    Note over FE: Poll for final status
```

## Linking on each platform

The customer approves the link in Cash App. What differs is who opens it. The frame works out where it's running and picks the flow.

| Where the frame runs | Who opens Cash App | What the frame sends you | What you build |
| - | - | - | - |
| Phone browser | The frame, in a new tab | Nothing | Nothing. If your iframe is sandboxed, add the flags in [Web iframes](#web-iframes). |
| Desktop browser | The customer, by scanning a QR code with their phone | A `challenge` when linking starts, and again each time Cash App replaces the links, with the same `requestId` | A dialog that shows the QR code. See [Desktop browsers](#desktop-browsers). |
| Native app (WebView) | Your app, by opening the `url` in the `challenge` | One `challenge` | Code that opens the link. See [Native apps](#native-apps). |

In every flow the frame keeps checking until the customer approves, saves the account, and sends a `resolved` event. If the customer cancels in the frame, it sends `cancelled`. Close any QR code on `resolved`, `cancelled`, or an `error`.

## The button

The buy button moves through these states. You don't build or style them.

| State | The button reads | What a tap does |
| - | - | - |
| Checking | **Connect Cash App**, dimmed, with a spinner | Nothing. |
| Not linked | **Connect Cash App** | Starts linking and opens Cash App. |
| Linking | **Connecting to Cash App…**, with a spinner | Cancels. Tapping again starts a new link. |
| Linked | **Pay with \$cashtag** | Pays with the saved Cash App account. |
| Paying | **Pay with \$cashtag**, dimmed, with a spinner while the payment runs | Nothing. |

If Cash App has no `$cashtag` for the customer, the linked button reads **Pay with Cash App**.

The button never shows an error message. When something goes wrong, it goes back to **Connect Cash App**, and the frame sends an `error` event so your app decides what to tell the customer:

| `code` | When | The button |
| - | - | - |
| `cashAppDeclined` | The customer declined in Cash App. | Goes back to **Connect Cash App**. |
| `cashAppLinkExpired` | The link expired before the customer finished. | Goes back to **Connect Cash App**. |
| `cashAppLinkTimedOut` | The customer didn't finish in time. | Goes back to **Connect Cash App**. |
| `cashAppUnavailable` | A network or server failure while linking, or while checking for a linked account. | Shows **Connect Cash App**. |
| `cashAppAccountNotAllowed` | This Cash App account can't be used, for example because it's already in use or its name doesn't match the customer's. | Goes back to **Connect Cash App**. |
| `cashAppRejected` | MoonPay refused the link request. | Removes the button. Offer another payment method. |

When the saved account can no longer pay, the button goes back to **Connect Cash App** and the frame sends no event.

## Display payment methods

Cash App appears in `paymentMethodConfigs` with its `availability`. After the customer links it, the account also appears in `paymentMethods`. Use the SDK or API to list what's available right now.

```ts List payment methods theme={null}
const paymentMethodsResult = await client.getPaymentMethods();

if (!paymentMethodsResult.ok) {
  // Handle error
}

console.log(paymentMethodsResult.value.data);
```

```ts Result theme={null}
{
  paymentMethodConfigs: [
    {
      type: "cash_app",
      capabilities: {
        supportedCurrencies: ["USD"],
        supportedTransactionTypes: ["buy"],
        allowsDeletion: true,
        requiresWidget: false,
      },
      availability: { active: true },
    },
  ],
  paymentMethods: [
    { id: "pm_01", type: "cash_app", cashtag: "$example" },
  ],
}
```

`cashtag` is absent when Cash App doesn't return one. The linked account has no `availability` of its own. Use the one on the `cash_app` entry in `paymentMethodConfigs`.

> [!NOTE]
>
> Which features a customer can use depends on their country and on the
> capabilities enabled for your partner account. Availability also shifts over
> time with MoonPay's compliance decisions. The `capabilities`
> object on the
> [connection](https://dev.moonpay.com/platform/sdk-reference/web/get-connection.md) gives
> the live answer; the regions and payment methods named on a docs page are
> for planning, not a contract. Gate each feature on its capability being
> present instead of keeping your own region list.

## Get quotes

Request a quote with the `cash_app` payment method. The quote is executable before the customer links Cash App. The buy button won't take a payment until Cash App is linked, so the customer can link and pay without you requesting a new quote.

See the [quotes API reference](https://dev.moonpay.com/api-reference/platform/endpoints/quotes/get.md) for the fields required to receive `executable: true`.

```ts Get quote theme={null}
const quoteResult = await client.getQuote({
  source: { asset: { code: "USD" }, amount: "100.00" }, // The fiat currency and amount to pay
  destination: { asset: { code: "ETH" } }, // The crypto the customer will receive
  wallet: { address: "0x1234..." }, // The destination wallet address
  paymentMethod: { type: "cash_app" }, // The payment method type
});

if (!quoteResult.ok) {
  // Handle error
}
```

## Execute the transaction

Call `client.setupBuyButton()` with your `cash_app` quote. The buy button renders the Cash App button. Don't pass `headless: true`. Headless mode accepts card and SEPA bank transfer quotes only, and rejects a `cash_app` quote with an `error` event, code `unsupportedPaymentMethod`. For the frame URL, size, permissions, and events, see the [Buy Button frame](https://dev.moonpay.com/platform/frames/buy-button.md) reference.

```ts Cash App theme={null}
import type { BuyButtonEvent } from "@moonpay/platform-sdk-web";

const cashAppResult = await client.setupBuyButton({
  quote: quoteResult.value.signature, // The quote signature from getQuote

  container: document.querySelector("#cashAppContainer"), // DOM element to render the button

  onEvent: (event: BuyButtonEvent) => {
    switch (event.kind) {
      case "ready":
        // The frame looked up the customer's Cash App account and is ready.
        break;

      case "complete": {
        const txn = event.payload.transaction;

        if (txn.status === "failed") {
          // The transaction failed. Branch on failureCode for programmatic handling.
          break;
        }

        // The transaction is executing. Track the final status via polling and/or webhooks.
        console.log(txn);
        break;
      }

      case "challenge":
        // Verification required. Render the challenge frame at the provided URL.
        // See: /platform/guides/handling-challenges
        console.log(event.payload.url);
        break;

      case "error":
        switch (event.payload.code) {
          case "quoteExpired":
            // Fetch a new quote, then pass its signature into the frame
            // cashAppResult.value.setQuote(newQuote.value.signature);
            break;

          case "invalidQuote":
            // Cash App isn't available for this customer. Offer another payment method.
            break;

          case "cashAppDeclined":
          case "cashAppLinkExpired":
          case "cashAppLinkTimedOut":
          case "cashAppUnavailable":
          case "cashAppAccountNotAllowed":
            // The button is back on "Connect Cash App". Tell the customer if you want to.
            break;

          case "cashAppRejected":
            // The button is gone. Offer another payment method.
            break;

          default:
            console.error(event.payload.message);
            break;
        }
        break;
    }
  },
});

if (!cashAppResult.ok) {
  // Handle error setting up the buy button
}
```

On a phone's browser, you don't handle the Cash App link yourself. The frame opens it. In a native app or a desktop browser, handle the `link_payment_method` challenge as described below.

## Web iframes

On a phone's browser, the frame opens the Cash App app link in a new tab when the customer taps.

If your iframe uses the [`sandbox`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/iframe#sandbox) attribute, include `allow-popups` and `allow-popups-to-escape-sandbox`, so the tab can open and Cash App loads without the sandbox. See [Permissions](https://dev.moonpay.com/platform/frames/buy-button.md#permissions).

## Desktop browsers

On a desktop, the frame doesn't open Cash App. It sends a `challenge` event whose `payload.kind` is `link_payment_method`, with a QR code the customer scans with their phone.

```ts theme={null}
onEvent: (event) => {
  switch (event.kind) {
    case "challenge":
      if (event.payload.kind === "link_payment_method") {
        // Show or update the QR code. The same requestId arrives again with new links.
        showQrCode(event.payload.requestId, event.payload.qrCodeSvgUrl);
      }
      break;

    case "resolved":
    case "cancelled":
      // Cash App is linked, or the customer cancelled. Close the QR code.
      hideQrCode();
      break;
  }
},
```

See [Cash App Pay link challenge](https://dev.moonpay.com/platform/frames/buy-button.md#cash-app-pay-link-challenge) for the full payload and a checklist.

## Native apps

In a native app, the frame can't open another app from inside a WebView. It sends your app a `challenge` event whose `payload.kind` is `link_payment_method`, and your app opens `url`. See [Cash App Pay link challenge](https://dev.moonpay.com/platform/frames/buy-button.md#cash-app-pay-link-challenge) for the message and a checklist.

With the React Native SDK, the buy button passes this to your `onEvent` handler:

```tsx theme={null}
<MoonPayBuyButton
  quote={quoteSignature}
  linkReturnUrl="myapp://moonpay-return"
  onEvent={(event) => {
    if (event.kind !== "challenge") return;

    if (event.payload.kind === "link_payment_method") {
      // Open the link in Cash App. Check the host first.
      if (isTrustedCashAppLink(event.payload.url)) {
        Linking.openURL(event.payload.url);
      }
      return;
    }

    // A frame challenge. Render the challenge frame at event.payload.url.
  }}
/>
```

This needs `@moonpay/platform-sdk-react-native` 1.35.0 or later. If your app doesn't open the link, the button stays on **Connecting to Cash App…** until the customer cancels or the link times out.

Offer Cash App only when your app handles this event. See the [`<MoonPayBuyButton>` reference](https://dev.moonpay.com/platform/sdk-reference/react-native/components/moonpay-buy-button).

## Delete a Cash App account

A customer can remove their saved Cash App account. Use [`client.deletePaymentMethod()`](https://dev.moonpay.com/platform/sdk-reference/web/delete-payment-method) or the [Delete payment method API](https://dev.moonpay.com/api-reference/platform/endpoints/payment-methods/delete.md) with the account's `id`. The next purchase asks the customer to link Cash App again.

The call returns a conflict while a payment with that account is pending. Deleting an ID that doesn't exist also succeeds.

## Transaction statuses

Transactions have the following statuses:

* **Pending:** The transaction has been initiated and the payment accepted. The assets are being transferred.
* **Complete:** The transaction is finalized. The payment is complete and the assets have been delivered to their destination.
* **Failed:** The transaction has failed. The payment was not executed and funds were not transferred.
