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

# Design a Bitcoin Lightning crypto payment form

To let users deposit Bitcoin faster and with lower fees, you can use the Bitcoin Lightning Network. Lightning is a second-layer protocol built on top of Bitcoin that enables fast, low-cost payments by processing transactions off-chain instead of recording each one directly on the Bitcoin blockchain.

This guide outlines the main features of Lightning payments and provides an example of how to implement a Bitcoin Lightning deposit form using AlphaPo.

## Key characteristics of Lightning payments

Bitcoin Lightning deposits use **Lightning invoices** instead of standard BTC wallet addresses. A **Lightning invoice** is a payment request that contains the amount to pay and the details needed to complete the transaction.

Example Lightning invoice:

```
lnbcrt1m1p5u93tfpp53wwjfugpyypf68mgwjfzq99x8cghlurxwpp680r9uyvd8qxkjulqdqqcqzysxqzuysp5fdzuturj4cttdaafw09j739adh4slxxqynnjpl6n208wqfc8ny6q9qxpqysgqgdgwm5hdt736pm3jkn0spp85zwx0023vlxj8s0fjkha55wtyg5hjxvmkjl6ee4ztxrc75j3q7qzxua7r28qujlvc3ykmaklczwccmkspazvfhu
```

**Lightning invoice rules**

* Each invoice is created for a specific amount and can only be paid once.
* The invoice contains the exact payment amount, so it must be paid in full and exactly as issued. Partial payments and overpayments are not possible.
* The invoice expires 15 minutes after it is created. The exact expiration time is included in the API response when the Lightning invoice is generated.
* The amount cannot be changed after the invoice is created.
* The maximum supported amount is 0.045 BTCLN. For larger deposits, use the Bitcoin network.

## How the payment form can be implemented

<Steps>
  <Step title="Display a Generate Lightning invoice form to a user">
    Add an **Amount** field for the user to fill in:

    <Frame>
      <img src="https://mintcdn.com/alphapo/NL5laDElXg-98xE-/images/deposits/lightning-1.png?fit=max&auto=format&n=NL5laDElXg-98xE-&q=85&s=430a839af3268a92e615e2865c246dc8" alt="Image 3" width="2580" height="1548" data-path="images/deposits/lightning-1.png" />
    </Frame>
  </Step>

  <Step title="Send POST /addresses/take to AlphaPo">
    After the user enters an amount and clicks **Generate**, your site should send a POST request to the [/addresses/take](/api-reference/endpoints/addresses-take) endpoint.

    ```text highlight={9,11} theme={null}
    POST /api/v2/addresses/take HTTP/1.1
    Host: app.alphapo.net
    X-Processing-Key: <api-key>
    X-Processing-Signature: <api-key>
    Content-Type: application/json
    Accept: */*
        
    {
      "currency": "BTCLN",
      "foreign_id": "1909242403",
      "amount": 0.0025
    }
    ```
  </Step>

  <Step title="Process the API response">
    Extract the Lightning invoice from the `address` field in the API response:

    ```text highlight={5} theme={null}
    {
      "data": {
        "id": 240379058,
        "currency": "BTCLN",
        "address": "lnbcrt1m1p5u93tfpp53wwjfugpyypf68mgwjfzq99x8cghlurxwpp680r9uyvd8qxkjulqdqqcqzysxqzuysp5fdzuturj4cttdaafw09j739adh4slxxqynnjpl6n208wqfc8ny6q9qxpqysgqgdgwm5hdt736pm3jkn0spp85zwx0023vlxj8s0fjkha55wtyg5hjxvmkjl6ee4ztxrc75j3q7qzxua7r28qujlvc3ykmaklczwccmkspazvfhu",
        "tag": null,
        "foreign_id": "1909242403",
        "expires_at": 1774373101
      }
    }
    ```
  </Step>

  <Step title="Show the Lightning invoice to the user">
    Generate a QR code for the user to scan, or provide an **Open wallet** button:

    <Frame>
      <img src="https://mintcdn.com/alphapo/NL5laDElXg-98xE-/images/deposits/lightning-2.png?fit=max&auto=format&n=NL5laDElXg-98xE-&q=85&s=825e653c945383934d1744854f6862cb" alt="Image 4" width="2580" height="1548" data-path="images/deposits/lightning-2.png" />
    </Frame>
  </Step>

  <Step title="Payment successful">
    Wait for a [deposit callback](/api-reference/callbacks/deposit-callbacks) from AlphaPo where `status` is `confirmed`, then show a deposit confirmation message.

    <Frame>
      <img src="https://mintcdn.com/alphapo/NL5laDElXg-98xE-/images/deposits/lightning-3.png?fit=max&auto=format&n=NL5laDElXg-98xE-&q=85&s=c204cb73b7c5b20fb3231beabfb2bb24" alt="Image" width="2580" height="1596" data-path="images/deposits/lightning-3.png" />
    </Frame>
  </Step>
</Steps>

## Adding an Open wallet button on mobile

To let users pay Lightning invoices on mobile, you can add an **Open wallet** button with a Lightning deeplink. When the user taps the button, a compatible Lightning wallet opens with the payment details pre-filled.

Lightning deeplink example:

```
lightning:lnbcrt1m1p5u93tfpp53wwjfugpyypf68mgwjfzq99x8cghlurxwpp680r9uyvd8qxkjulqdqqcqzysxqzuysp5fdzuturj4cttdaafw09j739adh4slxxqynnjpl6n208wqfc8ny6q9qxpqysgqgdgwm5hdt736pm3jkn0spp85zwx0023vlxj8s0fjkha55wtyg5hjxvmkjl6ee4ztxrc75j3q7qzxua7r28qujlvc3ykmaklczwccmkspazvfhu
```

**How it works**

1. The customer taps the link on their mobile device.
2. Your site opens the `lightning:lnbc...` deeplink.
3. If the customer has a compatible wallet site installed, it opens with the invoice ready to pay.
4. If no compatible wallet is installed, the deeplink does not open and the customer may see an error such as **No Lightning wallet is installed on your device**.

## Additional details

* Bitcoin withdrawals using the Lightning Network are not supported. To withdraw funds, first exchange BTCLN to BTC or another supported currency. Exchanges between BTCLN and BTC are always at a 1:1 rate with no fees.

* You can also convert BTCLN to any supported currency and withdraw in a single step by using the [/withdrawal/crypto](/api-reference/callbacks/withdrawal-callbacks) endpoint with the `convert_to` parameter set to the target currency.

* For more details about the **/addresses/take** endpoint, refer to [Generate a crypto address](/api-reference/endpoints/addresses-take).
