TJ Tech Pros: TJ Technology Professionals - Empowering the Next Generation of IT Leaders

Add PayPal Checkout (one-time annual subscription) and return webhooks

Skip to MenuSkip to NavigationSkip to Main Content
Add PayPal Checkout (one-time annual subscription) and return webhooks

by Taurus

Add PayPal Checkout (one-time annual subscription) and return webhooks to set access_id/membership rows.

I tried to append the PayPal code directly into your canvas, but the canvas update failed due to a regex replacement error on my side. No changes were made to your document. Below is everything you need—copy/paste into your files exactly as indicated. If you want, I can try inserting these into your canvas again next.

[1] Front-End (focus-library-offer.html)

Place this below the Pricing section (before the FAQ or just before ). It renders a PayPal “Subscribe” button that creates an annual subscription and then redirects to a “pending” page while the webhook activates access.

 
https://chatgpt.com/c/68de5cbf-92d4-8325-a8b8-153f09f95a6e

[Replace]

  • PAYPAL_CLIENT_ID with your live or sandbox client id

  • PAYPAL_PLAN_ID with your annual plan id (starts with P-)

[2] Classic ASP Webhook Endpoint

Create /api/paypal/paypal-webhook.asp. This verifies PayPal's signature and hands the event JSON to SQL for processing.

 
 

[3] Optional “onApprove” Logger

Create /api/paypal/subscription-approved.asp (no auth needed; logs client-side approval so you can reconcile if a webhook is delayed).

 
 

[4] SQL — Event Log + Membership Activation

Create /db/sql/membership.sql and run it on your SQL Server (2016+ for JSON functions).

 
 

[Set 42 to the actual access_id used by your CMS for Focus Library.]

[5] PayPal Dashboard Setup

[Steps]

  1. Create Product: “Life Story Music Focus Library” (Digital, service).

  2. Create Plan: Annual billing, USD 100.00. Collect the Plan ID (e.g., P-XXXX).

  3. Webhooks: Add a webhook for https://YOURDOMAIN.com/api/paypal/paypal-webhook.asp.

    • Events:

      • BILLING.SUBSCRIPTION.ACTIVATED

      • BILLING.SUBSCRIPTION.CANCELLED

      • BILLING.SUBSCRIPTION.EXPIRED

      • BILLING.SUBSCRIPTION.SUSPENDED

      • PAYMENT.SALE.COMPLETED and PAYMENT.CAPTURE.COMPLETED

    • Grab the Webhook ID and put it in WEBHOOK_ID.

  4. Credentials: Put your Client ID and Secret in the ASP constants (or a config include).

[Sandbox vs Live]

  • Sandbox: change API_BASE to https://api-m.sandbox.paypal.com and use sandbox client id/secret/plan.

  • Live: switch back to api-m.paypal.com and live credentials.

[6] Routing/UX

[Pages]

  • /member/pending: simple page saying “Your membership is being activated… check your email in a minute.”

  • /checkout/error: display a generic failure + support link.

  • On success: your app will show the Focus Library as unlocked (because user_access row exists).

[7] Test Plan (Sandbox)

[Checklist]

  1. Replace PAYPAL_CLIENT_ID and PAYPAL_PLAN_ID with Sandbox values.

  2. Enable the webhook to the Sandbox URL.

  3. Click the PayPal button → use a Sandbox Buyer → approve.

  4. Confirm:

    • paypal_webhook_events receives BILLING.SUBSCRIPTION.ACTIVATED (and a payment event).

    • user_memberships has an active row with 365-day window.

    • user_access has the access_id row.

  5. Cancel the subscription from the Sandbox Buyer's PayPal → webhook sets membership cancelled.

  6. Switch to Live after validation.

[8] Notes for Your CMS

  • If your membership/access lives in different tables (e.g., content_user_access, memberships, etc.), map the MERGE blocks accordingly.

  • If you prefer immediate revocation on cancel, uncomment the DELETE FROM user_access lines.

  • If you want to base membership length on PayPal's billing_info.next_billing_time, you can pull it from $.resource and set end_at accordingly.


 

If you want, I can take another pass at inserting these into the canvas files exactly where they belong (now that you've seen the snippets), or generate Classic ASP includes (/api/paypal/config.inc.asp) to centralize your credentials and plan IDs.

Posted: 10/6/2025 12:08:36 PM

You may also like