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

# PayPal

> Accept PayPal payments and recurring PayPal subscriptions.

## Prerequisites

* A [PayPal Business](https://www.paypal.com/business) account
* PayPal REST API credentials

## 1. Create a PayPal app

1. Go to [developer.paypal.com](https://developer.paypal.com)
2. Navigate to **Apps & Credentials**
3. Create a new app (one for sandbox, one for live)
4. Copy the **Client ID** and **Secret**

## 2. Configure in `.env`

PayPal credentials are set in the environment file:

```ini theme={null}
PAYPAL_MODE=live               # sandbox | live
PAYPAL_LIVE_CLIENT_ID=your_client_id
PAYPAL_LIVE_CLIENT_SECRET=your_client_secret
PAYPAL_CURRENCY=USD
PAYPAL_WEBHOOK_ID=             # Set after step 3
```

For sandbox/testing:

```ini theme={null}
PAYPAL_MODE=sandbox
PAYPAL_SANDBOX_CLIENT_ID=your_sandbox_client_id
PAYPAL_SANDBOX_CLIENT_SECRET=your_sandbox_secret
```

## 3. Set up the webhook

1. In the PayPal developer portal, go to your app → **Webhooks**
2. Add webhook URL:
   ```
   https://yourdomain.com/paypal/webhook
   ```
3. Subscribe to these events:
   * `PAYMENT.CAPTURE.COMPLETED`
   * `BILLING.SUBSCRIPTION.ACTIVATED`
   * `BILLING.SUBSCRIPTION.CANCELLED`
   * `BILLING.SUBSCRIPTION.SUSPENDED`
   * `PAYMENT.SALE.COMPLETED`
4. Copy the **Webhook ID** and set `PAYPAL_WEBHOOK_ID` in `.env`

## 4. Payment flow

StartMyVPN supports two PayPal payment modes:

**Checkout (one-time)**:

* Customer is redirected to PayPal to approve payment
* On return, StartMyVPN captures the payment and activates the service

**Subscriptions (recurring)**:

* A PayPal subscription plan is created automatically
* Customer approves a recurring billing agreement
* PayPal charges automatically at each renewal; webhook triggers service renewal

## Testing

Use [PayPal sandbox accounts](https://developer.paypal.com/tools/sandbox/accounts/) to simulate buyer and seller. Set `PAYPAL_MODE=sandbox` and use sandbox credentials.
