# PayPal Payments

PayPal is available as a payment method alongside Stripe and crypto (XMR/DOGE).

## Privacy Warning

PayPal requires invasive identity verification to receive payments:

- ML-based face scanning (biometric capture)
- Two images of your face from different angles
- Photos of both sides of government-issued ID (driver's license, passport)
- Business verification for merchant accounts

This verification is required to move from sandbox to live production payments. There is no way to accept PayPal payments anonymously or privately. If privacy is important to you, consider crypto payments (XMR/DOGE) instead.

## Shop Setup

1. Go to https://developer.paypal.com/dashboard/
2. Create an app (sandbox for testing, live for production)
3. Complete identity verification (face scan + government ID)
4. Copy Client ID and Secret
5. In Shop Settings → PayPal Settings, enter credentials and save

## Configuration

Global settings in `development.ini`:

```ini
app.payments.paypal.enabled = True
app.paypal.sandbox_mode = True
```

Or environment variables:

```bash
export MPS_PAYMENTS_PAYPAL_ENABLED=True
export MPS_PAYPAL_SANDBOX_MODE=True
```

## How It Works

- Each shop configures their own PayPal credentials
- PayPal button appears at checkout when enabled
- Payment info stored on Invoice (`paypal_order_id`, `paypal_capture_id`)
- `Invoice.payment_method` returns "paypal" for PayPal payments
- Saved payment methods stored in `PayPalUserShop`

## Webhooks

Webhooks provide resilience when JavaScript callbacks fail. Configure in PayPal Developer Dashboard:

1. Go to https://developer.paypal.com/dashboard/applications
2. Select your app → Webhooks → Add Webhook
3. Enter URL: `https://yourdomain.com/webhooks/paypal`
4. Subscribe to events:
   - `PAYMENT.CAPTURE.COMPLETED`
   - `CHECKOUT.ORDER.APPROVED`
   - `PAYMENT.CAPTURE.DENIED`
   - `CUSTOMER.DISPUTE.CREATED`
5. Copy the Webhook ID
6. Set in your ini: `paypal.webhook_id = YOUR_WEBHOOK_ID`

## Code

- `make_post_sell/views/cart.py` - PayPal checkout functions (`paypal_create_order`, `paypal_complete_checkout`)
- `make_post_sell/views/billing.py` - Disconnect saved PayPal
- `make_post_sell/views/webhooks.py` - Webhook handlers

## Database

**mps_shop columns:**
- `paypal_client_id` - Shop's PayPal Client ID
- `paypal_secret` - Shop's PayPal Secret
- `paypal_enabled` - Toggle PayPal on/off

**mps_invoice columns:**
- `paypal_order_id` - PayPal order reference
- `paypal_capture_id` - PayPal capture reference

**mps_paypal_user_shop table:**
- Tracks saved PayPal payment methods per user/shop
