PayPal Payments
Take every payment through PayPal alongside or instead of Stripe — listings, claims, the store and subscriptions. Create the app, wire the webhook, set the env vars, test in the sandbox and go live.
Stripe does not accept merchants in every country. If yours is one of them — or your businesses simply prefer it — a buyer can pay with PayPal instead of a card. The money lands in your own PayPal account, and what they bought is granted from a verified webhook event, by the same rules Stripe's is.
Paid listings, listing claims, the store — both "Buy now" and the cart — sponsor blocks, promotion placements and lead subscriptions. There is nothing left that only Stripe can take, and nothing extra to configure for any of it: the same three variables, and the same webhook events.
What PayPal handles
| Flow | Where the buyer starts | Price comes from |
|---|---|---|
| Premium listing | /submit, picking the Premium plan | price on the premium plan in config/plans.config.ts |
| Standard → Premium upgrade | Dashboard, or the listing's own page | The same plan price |
| Sponsor block | /promote | pricePerMonth in config/advertising.config.ts |
| Promotion placements | /promote | pricePerMonth per placement, summed |
| Lead subscription | The owner's leads inbox | price in config/quotes.config.ts |
| Listing claim | The claim form on a listing | price in config/claims.config.ts |
| Store order | A product page's "Buy now", or the cart | The product and variant rows, re-read from the database |
The first two, claims and store orders are one-time; sponsors, placements and lead subscriptions are monthly. See Payments for the Stripe side of each.
Step 1 — Create a PayPal app
- Sign in at developer.paypal.com → Apps & Credentials
- Pick Sandbox while you test, Live when you ship
- Create an app, then copy its Client ID and Secret
PAYPAL_CLIENT_SECRET never belongs in Git or in a NEXT_PUBLIC_ variable. .env.local is
already .gitignored. Sandbox and live credentials are separate sets — they are not
interchangeable.
Step 2 — Create the webhook
Without a webhook, a buyer can pay and the listing is never granted. In the app's settings, under Webhooks, add one pointing at:
https://your-domain.com/api/webhooks/paypalSubscribe it to these five, which cover paid listings:
| Event | Why it matters |
|---|---|
CHECKOUT.ORDER.APPROVED | The buyer approved and then closed the tab. This captures the money anyway. |
PAYMENT.CAPTURE.COMPLETED | The money arrived. This is what grants the listing. |
PAYMENT.CAPTURE.DENIED | Logged, so a buyer's "but I paid" can be checked. |
PAYMENT.CAPTURE.REFUNDED | Drops the listing back to the free plan, and takes back the dofollow link the payment granted (not one won as a weekly winner or given by an admin). |
PAYMENT.CAPTURE.REVERSED | The same, for a chargeback. |
If the directory also sells sponsor blocks, promotion placements or lead subscriptions, add these seven:
| Event | Why it matters |
|---|---|
BILLING.SUBSCRIPTION.ACTIVATED | The subscription is live. This is what switches the sponsor block, placement or lead subscription on. |
BILLING.SUBSCRIPTION.UPDATED | Status or billing period changed. |
BILLING.SUBSCRIPTION.SUSPENDED | Paused — after repeated failed charges, among others. |
BILLING.SUBSCRIPTION.CANCELLED | Ended by the subscriber or by you. |
BILLING.SUBSCRIPTION.EXPIRED | Ran to its end. |
BILLING.SUBSCRIPTION.PAYMENT.FAILED | Marks it past due. |
PAYMENT.SALE.COMPLETED | A renewal went through; keeps the billing period current. |
BILLING.SUBSCRIPTION.ACTIVATED is what turns the placement on. Leave the subscription
events off and PayPal still takes the monthly payment — the sponsor block or promotion
simply never appears, and nobody finds out until the buyer asks where their ad is.
In PayPal's event picker, Checkout order approved sits inside a collapsible Checkout group. Ticking that group's own checkbox does not select it — PayPal selects Checkout order completed instead, a different event this app does not handle. The group shows as ticked either way, so nothing looks wrong.
What quietly breaks is the safety net. CHECKOUT.ORDER.APPROVED is what captures an order
when the buyer approved the payment on paypal.com and never came back to your site. Without
it, that order just expires uncaptured: the buyer believes they paid, and nothing was taken.
Expand the Checkout group and tick Checkout order approved on its own. The same caution applies to every group here: tick the child events, never the group heading.
The mistake, as it actually looks — the group is ticked, and the wrong child event with it.
Then copy the webhook ID PayPal shows beside it. That is what verifies every incoming event, and it differs between your sandbox and live apps.
Check the events actually saved
Back on the Webhooks list, read the Events Tracked column on your webhook's row. For a listings-only directory it must name exactly these five, and the first word of the list is the one to check:
Checkout order approved, Payment capture completed, Payment capture denied,
Payment capture refunded, Payment capture reversedIf it starts with Checkout order completed, you hit the trap above — edit the webhook, clear that event, and tick Checkout order approved.
Selling subscriptions as well, the same column should also carry the seven
BILLING.SUBSCRIPTION.* and PAYMENT.SALE.COMPLETED entries — twelve in all.
Wrong: the list starts with Checkout order completed.
Right: Checkout order approved first, and the five listing events in all. Add the subscription events on top if you sell them.
Step 3 — Set the environment variables
PAYPAL_CLIENT_ID=...
PAYPAL_CLIENT_SECRET=...
PAYPAL_WEBHOOK_ID=...
# optional: sandbox | live — overrides testMode in config/payments.config.ts
PAYPAL_ENV=sandboxThe app refuses to start in production with a client id and no webhook id. PayPal events can only be verified against a webhook id, a listing is only ever granted from a verified event, so a half-configured install would take money and grant nothing. Set all three together, or leave all three unset.
With them unset, nothing changes: the paid-listing flow is the Stripe checkout it was.
Step 4 — Choose the default provider
config/payments.config.ts is yours and survives every upgrade:
export const paymentsConfig = definePayments({
provider: 'paypal', // 'stripe' | 'paypal' | 'none'
testMode: true, // sends PayPal to its sandbox API
});provider is only the default. Whatever else you have configured by environment stays
available, and the buyer picks:
| Stripe keys | PayPal keys | What the buyer sees |
|---|---|---|
| set | unset | Card only — exactly as before PayPal existed |
| unset | set | PayPal only |
| set | set | A choice, with provider preselected |
There is nothing to configure for the choice itself. The payment step asks the server which providers are live and renders nothing extra when there is only one.
Step 5 — Make the two prices agree
The providers read the price from different places, and nothing reconciles them:
- Stripe charges whatever its Price says — set in the Stripe dashboard, reached through
STRIPE_PRICE_ID_PREMIUMand theSTRIPE_PRICE_ID_PROMO_*variables. - PayPal charges what your config says, because a PayPal order and plan each carry their
own amount:
priceon thepremiumplan inconfig/plans.config.tsfor a listing,pricePerMonthinconfig/advertising.config.tsfor sponsors and placements, andpriceinconfig/quotes.config.tsfor lead subscriptions — each in thecurrencyfrom the same file.
Where a Stripe Price and the matching config value disagree, buyers pay different amounts depending on which button they press. Make each pair equal, and change them together.
The bundle discount is the same trap in a second form. Stripe takes 30% off through
STRIPE_COUPON_ID_PROMO_ALL_THREE; PayPal has no coupons, so the all-three plan's price
already has allThreeDiscountPercent taken off it. Nothing links the two.
How a payment runs
buyer clicks pay
→ the payment route creates a PayPal order, saved on the listing
→ buyer approves on paypal.com
→ back on your site: the order is captured, the listing granted, buyer redirected
→ PAYMENT.CAPTURE.COMPLETED webhook
grants the listing — the authority, and a no-op if the return already didBoth paths end in the same fulfilment function Stripe uses, so a listing is granted by the same rules whichever provider took the money. It is idempotent — the capture id is stored under a unique constraint, so a replayed webhook changes nothing.
If the buyer approves and then closes the tab, nothing captures on the way back.
CHECKOUT.ORDER.APPROVED captures it server-side instead.
No migration. PayPal reuses the columns Stripe already writes, and
payments.payment_method now records which provider took the money.
Paid claims
A claim fee runs exactly like a listing payment: an order, the buyer approves, the return trip captures it, and the listing is handed to its new owner by the same function the Stripe webhook calls.
A refund marks the claim refunded and stops there — the listing stays with its new owner.
That is deliberate, and the same on Stripe: a refund is as often a goodwill gesture as a
reversal, so taking a listing back is a decision for you, not for the webhook.
How a store order runs
"Buy now" and the cart checkout both offer PayPal once it is configured, with the choice sitting above the pay button.
The cart travels inside the order. Stripe keeps it in the checkout session's metadata;
PayPal has nowhere to put it — its custom_id holds 127 characters — so each line rides in its
own order item with <productId>:<variantId> in the sku, and the webhook reads the cart back
from there. Prices are re-read from the database whichever provider took the money, and nothing
is stored before the buyer pays.
What PayPal is told about shipping depends on the cart:
| The cart | What PayPal is asked for |
|---|---|
| Print-on-demand, address already on the shipping form | That address, with the Printful rate as the order's shipping line |
| Physical goods, no address yet | Ask the buyer for one |
| Digital only | No address at all |
Stripe applies shippingCountries on its own checkout page. PayPal cannot — but approving is
not paying, so the app reads the approved order and refuses to capture one shipping
outside the list. The buyer is not charged, lands on the cancel page with "We can't ship
there", and keeps their cart. The webhook's safety-net capture runs the same check, so there
is no way around it.
Fulfilment is the code the Stripe webhook runs: the order and its items are recorded, stock goes
down, print-on-demand lines go to Printful, and the buyer gets the confirmation email. A
refund marks the order refunded; stock is not put back and the Printful order is not
cancelled, because the goods may already be printed or on their way.
PayPal refuses them. Amounts are formatted per currency, so a ¥1500 item is sent as 1500,
not 1500.00. Nothing to configure — worth knowing if you are reconciling by hand.
How a subscription runs
PayPal will not take a price straight into a checkout the way Stripe does. A subscription points at one Plan, and a plan belongs to a Product — catalogue objects that have to exist before anyone can pay. The app creates them for you and reuses them:
- One product per installation, named
DirectoryLaunch subscriptions. - One plan per price and period, named after what it bills. A restarted server finds the plan it made last week instead of adding a second one. Plans accumulate in Products & Plans in the PayPal dashboard — that is expected, not a leak.
A promotion with several placements is one plan, not several subscriptions. Its price is the sum of the placements chosen, which keeps one row, one subscription and one lifecycle — the shape the Stripe flow already has.
No migration. The subscription id lives in the existing stripe_subscription_id column on
partners, promotions and lead_subscriptions. The name is historical; which provider
issued an id is read off the id itself — Stripe's are sub_…, PayPal's are I-….
Testing in the sandbox
- Set
PAYPAL_ENV=sandboxwith your sandbox app's credentials - In the developer dashboard, Testing Tools → Sandbox accounts, copy a personal account's email and password — that account is your test buyer
The Personal account is your test buyer.
- Submit a Premium listing, pay as that buyer, and check the listing comes back premium
PayPal has to post to a public HTTPS URL. Either expose your dev port with a tunnel
(ngrok http 3000) and point the sandbox webhook at
https://<id>.ngrok.app/api/webhooks/paypal, or test on a preview deployment. Without a
reachable webhook the return trip still captures and still grants the listing — but you will
not have tested the path that matters in production.
The boilerplate's next.config.ts already allows the usual tunnel hosts to pull dev
resources. Without that, a page served through a tunnel renders blank.
Testing Tools → Webhooks simulator replays a single event — the quickest way to exercise the refund branch, which is otherwise tedious to produce.
Going live
- Swap in the live app's client id and secret
- Create the webhook again on the live app — its ID is different
- Set
PAYPAL_ENV=live, or drop the variable and leavetestMode: false - Redeploy, then buy one real listing and refund it
Sandbox and live share no data: sandbox payments never appear in the live dashboard, and a live webhook id does not verify sandbox events.
Revenue in the admin dashboard
Card revenue is read from the Stripe API. PayPal revenue is read from your own payments rows,
because PayPal's equivalent (Transaction Search) is reporting-grade — delayed by hours and
absent from the sandbox. Both are summed into the same chart, and the footnote under it names
the sources it actually used.
Troubleshooting
| What you see | Usually |
|---|---|
Refuses to start, asking for PAYPAL_WEBHOOK_ID | A client id with no webhook id. Set all three. |
| "signature verification failed" in the logs | Wrong PAYPAL_WEBHOOK_ID, or a sandbox webhook id against live events (or the reverse). |
| Buyer paid, listing still pending | The webhook never arrived. The dashboard asks PayPal directly on the next load and heals it; check the webhook's delivery log in the developer dashboard. |
| "PayPal is not configured on this site" | Only some of the three variables are set, or the deployment was not redeployed after adding them. |
| Buyer approved on paypal.com, never returned, and nothing was ever captured | The webhook is not subscribed to CHECKOUT.ORDER.APPROVED — check the Events Tracked column, see Step 2. |
Capture fails with INSTRUMENT_DECLINED | The buyer's funding source was refused. They have to start a new order; nothing was taken. |
| Buyers charged different amounts | A Stripe Price and the matching config value disagree — see Step 5. |
| Subscriber was charged, the sponsor block or placement never appeared | The webhook is missing BILLING.SUBSCRIPTION.ACTIVATED. Add the seven subscription events and check the Events Tracked column. |
| Plans piling up in PayPal → Products & Plans | Expected. One plan per price and period, reused; a new price makes a new plan. |
| Buyer approved a store order and landed on the cancel page saying "We can't ship there" | Their address is outside shippingCountries. Nothing was captured and nothing was charged. |
See also
- Payments — the Stripe side of every flow below
- Payments Config — picking the default provider
- Plans Config — where PayPal reads the premium price
- Advertising Config — sponsor and placement pricing
- Listing Claims — the claim flow and its fee
- Store & Fulfillment — the cart, orders and Printful
- Environment Variables — every key in one place
- Webhook Routes — what each webhook handler does
- PayPal Orders API docs