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

# Quickstart

> Get started with PayLink SDK quickly

# PayLink SDK Quickstart

<div className="intro-box">
  <div className="intro-icon">🚀</div>

  <div className="intro-content">
    Get started with the PayLink SDK in minutes. This guide will walk you through setup, configuration, and your first payment processing.
  </div>
</div>

## Before You Begin

<div className="prerequisites-box">
  <h3>You'll Need:</h3>

  <ul>
    <li>✅ Python 3.8 or higher</li>
    <li>✅ A PayLink account with API access</li>
    <li>✅ Payment provider credentials (e.g., M-Pesa)</li>
  </ul>
</div>

## Step 1: Set Up Your PayLink Account

<div className="step-box">
  <div className="step-content">
    <h3>1. Create a PayLink Account</h3>
    <p>Visit <a href="https://paylink-platform-izl1.vercel.app/" target="_blank" rel="noopener noreferrer" className="signup-link">[https://paylink-platform-izl1.vercel.app/](https://paylink-platform-izl1.vercel.app/)</a> and create your account.</p>

    <div className="image-container">
      <img src="https://mintcdn.com/paylink/nixULzcSPO_B-cPs/images/sign-up.png?fit=max&auto=format&n=nixULzcSPO_B-cPs&q=85&s=7d1519504508b0bd7c6a579f662b8f80" alt="PayLink Sign Up Page" width="100%" className="screenshot" data-path="images/sign-up.png" />

      <p className="image-caption">Fill in your details to create your PayLink account</p>
    </div>
  </div>
</div>

<div className="step-box">
  <div className="step-content">
    <h3>2. Generate Your API Key</h3>
    <p>After signing in, navigate to <strong>Settings</strong> and generate your API key.</p>

    <div className="image-container">
      <img src="https://mintcdn.com/paylink/nixULzcSPO_B-cPs/images/generate-api-key.png?fit=max&auto=format&n=nixULzcSPO_B-cPs&q=85&s=0fe74d6405f789ab3ba79f5dc1573607" alt="Generate API Key" width="100%" className="screenshot" data-path="images/generate-api-key.png" />
    </div>
  </div>
</div>

<div className="step-box">
  <div className="step-content">
    <h3>3. Copy Your API Key</h3>
    <p>Copy your API key from the dashboard. You'll need it for your integration. </p>

    <div className="image-container">
      <img src="https://mintcdn.com/paylink/nixULzcSPO_B-cPs/images/copy-api-key.png?fit=max&auto=format&n=nixULzcSPO_B-cPs&q=85&s=a5894d3cebae255d59a6f87ecd3b676e" alt="Copy API Key" width="100%" className="screenshot" data-path="images/copy-api-key.png" />
    </div>
  </div>
</div>

## Step 2: Configure Environment Variables

<div className="code-setup-box">
  <p>Create a <code>.env</code> file in your project root with your PayLink credentials:</p>
  <p>You can create a project on the PayLink platform and use the same name or just specify your preferred name under <code>PAYLINK\_PROJECT</code> and PayLink will create the project automatically.</p>

  ```bash theme={null}
  # PayLink credentials
  PAYLINK_API_KEY=your_api_key_here      # From your account dashboard
  PAYLINK_PROJECT=your_name         # From project settings
  PAYLINK_TRACING=enabled                 # Optional for debugging
  PAYMENT_PROVIDER=["mpesa"]             # JSON array of providers

  # M-Pesa specific settings (if using M-Pesa)
  MPESA_BUSINESS_SHORTCODE=your_shortcode
  MPESA_CONSUMER_SECRET=your_consumer_secret
  MPESA_CONSUMER_KEY=your_consumer_key
  MPESA_CALLBACK_URL=your_callback_url
  MPESA_PASSKEY=your_passkey
  MPESA_BASE_URL=your_base_url
  ```
</div>

## Step 3: Install the SDK

<div className="install-box">
  <p>Run this command in your terminal to install the PayLink SDK and its dependencies:</p>

  ```bash theme={null}
  pip install paylink-sdk python-dotenv
  ```

  <div className="version-note">
    <strong>Note:</strong> This will install the latest version of the SDK. For a specific version, use <code>pip install paylink-sdk==X.Y.Z</code>
  </div>
</div>

## Step 4: Set Up a Basic Client

<div className="client-setup-box">
  <p>Create a new file named <code>client\_example.py</code> with the following code:</p>

  ```python theme={null}
  import asyncio
  from dotenv import load_dotenv
  from paylink_sdk import PayLinkClient

  # Load environment variables from .env file
  load_dotenv(override=True)

  async def main():
      # Initialize the client - it will automatically use your .env variables
      client = PayLinkClient()
      
      # List available tools
      tools = await client.list_tools()
      
      # Print available tools
      print(f"Available tools: {tools}")
      
      return tools

  if __name__ == "__main__":
      asyncio.run(main())
  ```
</div>

<div className="test-connection-box">
  <h4>Test Your Connection</h4>
  <p>Run this script to verify your connection to the PayLink server:</p>

  ```bash theme={null}
  # From your project directory
  python client_example.py
  ```

  <p>If successful, you should see a list of available payment tools printed to your console.</p>
</div>

## Step 5: Process a Payment

<div className="code-example-box">
  <h3>Process Your First Payment</h3>
  <p>Create a new file named <code>process\_payment.py</code> with this code:</p>

  ```python theme={null}
  import asyncio
  from dotenv import load_dotenv
  from paylink_sdk import PayLinkClient

  async def process_payment():
      # Load environment variables
      load_dotenv(override=True)
      
      # Initialize the client - it will automatically use your .env variables
      client = PayLinkClient()
      
      # Process a payment using M-Pesa STK Push
      result = await client.call_tool("stk_push", {
          "phone_number": "2547123456789",  # Replace with actual phone number
          "amount": 1,                      # Amount in your currency
          "account_reference": "invoice",    # Your reference
          "transaction_desc": "invoice-123", # Description
          "transaction_type": "CustomerBuyGoodsOnline",
      })
      
      print(f"Payment initiated: {result}")
      return result

  if __name__ == "__main__":
      asyncio.run(process_payment())
  ```

  <div className="run-example">
    <h4>Run the Payment Example</h4>
    <pre><code>python process\_payment.py</code></pre>
  </div>
</div>

<div className="info-box">
  <div className="info-icon">ℹ️</div>

  <div className="info-content">
    <p>In production, replace the example phone number with your customer's actual phone number. M-Pesa will send a push notification to this number requesting payment confirmation.</p>
  </div>
</div>

## Step 6: Check Payment Status

<div className="status-check-box">
  <h3>Verify Payment Completion</h3>
  <p>Create a file named <code>check\_status.py</code> to verify the payment status:</p>

  ```python theme={null}
  import asyncio
  from dotenv import load_dotenv
  from paylink_sdk import PayLinkClient

  async def check_payment_status(transaction_id):
      # Load environment variables
      load_dotenv(override=True)
      
      # Initialize the client - it will automatically use your .env variables
      client = PayLinkClient()
      
      # Check payment status
      status = await client.call_tool("stk_push_status", {
          "checkout_request_id": transaction_id
      })
      
      print(f"Payment status: {status}")
      return status

  if __name__ == "__main__":
      # Replace with your transaction ID from the previous step
      transaction_id = "ws_CO_12052025033128264797357665"
      asyncio.run(check_payment_status(transaction_id))
  ```

  <div className="run-example">
    <h4>Run the Status Check</h4>
    <pre><code>python check\_status.py</code></pre>
  </div>
</div>

<div className="next-steps-box">
  <h3>🎉 Next Steps</h3>
  <p>Now lets move on to how to view your tools in the PayLink dashboard:</p>

  <ul>
    <li>View your tools in the PayLink dashboard</li>
  </ul>
</div>
