AL lPyment methods fully fucntion onstripe and paypal on sandbox

This commit is contained in:
IGNY8 VPS (Salman)
2026-01-20 19:21:01 +00:00
parent c777e5ccb2
commit fa548c3da9
9 changed files with 605 additions and 30 deletions

View File

@@ -226,12 +226,53 @@ Go to [developer.paypal.com](https://developer.paypal.com)
5. Click **"Save"**
6. Copy the **Webhook ID** (starts with `WH-...`)
#### Step 4: Create Subscription Plans (Optional)
#### Step 4: Create Subscription Plans (Required for Subscriptions)
If you want PayPal subscriptions:
1. Go to **Products** in PayPal dashboard
2. Create subscription plans matching your Stripe plans
3. Copy the **Plan IDs**
PayPal subscriptions require creating **Products** and **Plans** in the PayPal dashboard. This is a manual process (not done via API in our implementation).
##### 4.4.1 Create a PayPal Product
1. Go to [sandbox.paypal.com/billing/plans](https://www.sandbox.paypal.com/billing/plans) (Sandbox) or [paypal.com/billing/plans](https://www.paypal.com/billing/plans) (Live)
2. Click **"Create product"** (or go to Products tab first)
3. Fill in:
- **Product name**: `IGNY8 Subscription`
- **Product type**: `Service`
- **Product ID**: `IGNY8-SUB` (or auto-generate)
- **Description**: `IGNY8 subscription plans`
4. Click **"Create product"**
5. Note the **Product ID** (e.g., `PROD-xxxxxxxxxxxxx`)
##### 4.4.2 Create PayPal Plans (One Per IGNY8 Plan)
For each plan in your system (Starter, Growth, Scale), create a PayPal plan:
1. In PayPal dashboard, click **"Create plan"**
2. Select the product you just created
3. Fill in plan details:
**Starter Plan:**
- **Plan name**: `Starter Plan - Monthly`
- **Description**: `Basic plan for small projects`
- **Pricing**:
- Billing cycle: `Monthly`
- Price: `$99.00 USD`
- Total cycles: `0` (infinite)
- **Setup fee**: `$0.00` (optional)
4. Click **"Create plan"**
5. **Copy the Plan ID** (starts with `P-...`, e.g., `P-5ML4271244454362WXXX`)
Repeat for Growth ($199/month) and Scale ($299/month) plans.
##### 4.4.3 Map PayPal Plan IDs to Django Plans
1. Go to Django Admin → **Auth → Plans**
2. Edit **Starter Plan**:
- Scroll to **"PayPal Integration"** section
- **Paypal plan id**: Paste `P-xxxxxxxxxxxxx`
3. Click **"Save"**
4. Repeat for Growth and Scale plans
**Note:** Without `paypal_plan_id` set, the subscription creation API will return an error.
### 4.2 Adding to Django Admin
@@ -266,6 +307,65 @@ Config (JSON):
4. Click **"Save"**
### 4.3 Live PayPal Payment Enablement (Production)
Use this section when switching from sandbox to live PayPal payments.
#### Step 1: Create/Select a Live App
1. Go to [developer.paypal.com](https://developer.paypal.com)
2. Select **Live** (top toggle)
3. Create a new app or select your existing live app
4. Copy the **Live Client ID** and **Live Secret**
#### Step 2: Configure Live Webhook
1. In your live app settings, add a webhook:
```
https://api.igny8.com/api/v1/billing/webhooks/paypal/
```
2. Select events:
- `CHECKOUT.ORDER.APPROVED`
- `PAYMENT.CAPTURE.COMPLETED`
- `PAYMENT.CAPTURE.DENIED`
- `BILLING.SUBSCRIPTION.ACTIVATED`
- `BILLING.SUBSCRIPTION.CANCELLED`
3. Copy the **Live Webhook ID**
#### Step 3: Update Django Admin Provider (Live)
1. Go to **System → Integration providers → paypal**
2. Update fields:
- **API key**: Live Client ID
- **API secret**: Live Secret
- **API endpoint**: `https://api-m.paypal.com`
- **Config (JSON)**: set `webhook_id` to the live webhook ID
3. Set:
- ✅ `is_active` = True
- ✅ `is_sandbox` = False
4. Click **"Save"**
#### Step 3.1: Map PayPal Plan IDs in Django
PayPal subscription webhooks only work if your plans are mapped.
1. Go to Django Admin → **Auth → Plans**
2. For each plan, set:
- **Paypal plan id**: Live PayPal Plan ID (starts with `P-...`)
3. Save each plan
#### Step 4: Validate Live Payment Flow
1. Open frontend: `/account/usage`
2. Select **PayPal** and complete a real payment
3. Confirm:
- Order is captured
- Credits are added
- Payment email is sent
#### Step 5: Validate PayPal Subscriptions (If Enabled)
1. Open frontend: `/account/plans`
2. Select **PayPal** and subscribe to a plan
3. Confirm:
- Subscription is activated
- Webhook events are processed
- Account plan is updated
---
## 5. Resend Configuration
@@ -561,21 +661,83 @@ Go to Admin → **System → Integration providers**
### 8.3 Test PayPal Integration
1. **Get Config Endpoint:**
```bash
curl -X GET https://api.igny8.com/api/v1/billing/paypal/config/ \
-H "Authorization: Bearer YOUR_JWT_TOKEN"
```
Should return client_id and sandbox status
#### 8.3.1 Verify PayPal Provider Config
2. **Test Credit Purchase:**
- Go to frontend: `/account/usage`
- Select "PayPal" as payment method
- Click "Buy Credits" on a package
- Should redirect to PayPal
- Login with sandbox account
- Complete payment
- Should capture order and add credits
```bash
curl -X GET https://api.igny8.com/api/v1/billing/paypal/config/ \
-H "Authorization: Bearer YOUR_JWT_TOKEN"
```
Should return `client_id` and `sandbox: true`.
#### 8.3.2 Test One-Time Credit Purchase (Orders API)
1. Go to frontend: `/account/usage`
2. Select **PayPal** as payment method
3. Click **"Buy Credits"** on a package
4. Should redirect to PayPal sandbox
5. Login with sandbox buyer account:
- Email: `sb-buyer@personal.example.com` (from PayPal sandbox accounts)
- Password: (your sandbox password)
6. Complete payment
7. **Verify:**
- Order is captured (check webhook logs)
- Credits are added to account
- Payment email is sent
#### 8.3.3 Test PayPal Subscriptions (Subscriptions API)
**Prerequisites:**
- [ ] PayPal Plans created in dashboard (see Section 4, Step 4)
- [ ] `paypal_plan_id` set on each Django Plan (Auth → Plans)
**Test Steps:**
1. **Verify Plan Configuration:**
```bash
# Check if plan has paypal_plan_id
docker exec -it igny8_backend python manage.py shell -c "
from igny8_core.auth.models import Plan
for p in Plan.objects.filter(is_active=True):
print(f'{p.name}: paypal_plan_id={p.paypal_plan_id}')
"
```
All paid plans should show a `P-xxxxx` ID.
2. **Create PayPal Subscription:**
- Go to frontend: `/account/plans`
- Select **PayPal** as payment method
- Click **"Subscribe"** on Starter/Growth/Scale plan
- Redirects to PayPal for approval
- Login with sandbox buyer account
- Approve the subscription
3. **Verify Subscription Activation:**
- Check webhook logs: `BILLING.SUBSCRIPTION.ACTIVATED` should fire
- Account plan should be updated
- `Subscription` record created with `external_payment_id` = PayPal subscription ID
- Credits added based on plan's `included_credits`
4. **Verify in Django Admin:**
- Go to **Auth → Subscriptions**
- Find the new subscription
- Confirm:
- `status` = `active`
- `external_payment_id` = `I-xxxxx` (PayPal subscription ID)
- `plan` = correct plan
5. **Test Subscription Cancellation:**
- In PayPal sandbox, go to **Pay & Get Paid → Subscriptions**
- Cancel the test subscription
- `BILLING.SUBSCRIPTION.CANCELLED` webhook should fire
- Subscription status should update to `canceled`
**Sandbox Test Accounts:**
Create sandbox accounts at [developer.paypal.com/dashboard/accounts](https://developer.paypal.com/dashboard/accounts):
- **Business account** - receives payments (seller)
- **Personal account** - makes payments (buyer)
Use the personal account credentials when approving payments/subscriptions.
### 8.4 Test Email Service
@@ -694,6 +856,28 @@ Go to Admin → **System → Integration providers**
- Check order status (must be APPROVED)
- Verify order hasn't already been captured
**"PayPal plan ID not configured for this plan"**
- The Plan model is missing `paypal_plan_id`
- Go to Django Admin → **Auth → Plans**
- Edit the plan and add the PayPal Plan ID (starts with `P-...`)
- Create the plan in PayPal dashboard first if not done
**"No plan found with paypal_plan_id=..."**
- Webhook received but no matching plan in Django
- Verify the `paypal_plan_id` in Django matches exactly what's in PayPal
- Check for typos or extra whitespace
**Subscription not activating after approval**
- Check webhook logs for `BILLING.SUBSCRIPTION.ACTIVATED` event
- Verify webhook URL is correctly configured in PayPal app
- Check that `webhook_id` in config JSON matches PayPal dashboard
- Ensure sandbox/live environment matches between app and PayPal
**PayPal subscription appears but no credits added**
- Check `included_credits` field on the Plan model
- Verify subscription webhook handler completed successfully
- Look for errors in Django logs during webhook processing
### Resend Issues
**"Invalid API key"**