Payments setup (operator)
Paid panels are sold through Stripe Checkout on the company's existing Stripe account. Everything is off until four settings are present, so the code can be deployed long before anything is sold.
[unverified]: the code has been tested against a stand-in for Stripe, not yet against Stripe. Do step 6 in test mode before going live.
What is sold
One-off payments, no subscription. Prices are in marketsim_api/offers.py, in USD, before tax.
| Offer key | Panel | Price | Sold when |
|---|---|---|---|
panel-300 |
300 respondents, each interviewed twice | 9 USD | BUNDLES_ON_SALE=1 |
panel-1000 |
1,000 respondents | 29 USD | BUNDLES_ON_SALE=1 |
panel-5000 |
5,000 respondents | 79 USD | also needs BATCH_PANELS=1; it is answered in bulk, in hours |
No products or prices are created in the Stripe dashboard: each checkout carries the name and amount from our own list. The browser never sends a price.
Getting started (owner, in this order)
- Database: apply
0006_paid.sqlafter0005, then run the two verification queries in its header. - Restricted key: Stripe dashboard, Developers, API keys, "Create restricted key". Give it
write access to Checkout Sessions and Refunds only. Store it as
STRIPE_SECRET_KEYon the API and the workers. Do not reuse the Caching Out key: a separate key can be revoked on its own. - Webhook endpoint: Developers, Webhooks, "Add endpoint". Address:
https://<api host>/stripe/webhook(through the web app:https://<site>/api/stripe/webhook). Events:checkout.session.completed,checkout.session.async_payment_succeeded,charge.refunded. Store its signing secret asSTRIPE_WEBHOOK_SECRETon the API. This is a new endpoint next to the Caching Out one; each has its own secret. - Tax (optional): if Stripe Tax is active on the account, set
STRIPE_AUTOMATIC_TAX=1. VAT is then added at checkout and business buyers can enter a VAT number. Without it no tax is added; ask the accountant which applies before selling. - Terms link: Stripe shows a required "I agree" box with our wording about immediate supply. Stripe needs a terms of service address in Settings, Public details, or the checkout is refused. The wording is a draft until counsel has reviewed it (PRD OQ-9).
- Test: with a test-mode key and a test-mode webhook secret, set
BUNDLES_ON_SALE=1, buy a panel with card 4242 4242 4242 4242, and check: the study shows "Paid panel", the payment email arrives, one row appears inpurchases. Deliver the same event again from the dashboard: the answer is{"received": true, "outcome": "duplicate"}and nothing changes. - Before going live, the finance app must know KolorIQ: orga-finance's migration 023 (its branch
feature/stripe-product-attribution) has to be deployed first. Until then it would count KolorIQ's sales as Caching Out's, because both are sold through one Stripe account. Check on its Connections screen that "Sales stored, by product" lists KolorIQ. See The finance feed. - Go live: replace both values with the live ones. Test and live must match: a live notification is refused while a test key is set, and the other way round.
Discount codes
Create a coupon and a promotion code in the Stripe dashboard (Products, Coupons). Buyers enter it on the payment page. A code for 100 percent off works: the panel is delivered and the purchase is recorded with amount 0. Limit such codes by number of uses and expiry date in Stripe.
Settings
| Name | Where | Meaning |
|---|---|---|
BUNDLES_ON_SALE |
API, workers | 1 shows the panels and lets follow-up emails mention them |
STRIPE_SECRET_KEY |
API, workers | Restricted key. Workers use it for refunds |
STRIPE_WEBHOOK_SECRET |
API | Signing secret of this product's endpoint |
STRIPE_AUTOMATIC_TAX |
API | 1 to let Stripe Tax add VAT |
PAID_INTERVIEW_WORKERS |
workers | Interviews in parallel inside one paid survey (default 24; free surveys use 8) |
BATCH_PANELS |
API | 1 puts the 5,000 panel on sale. Set it only after the bulk test run in Bulk surveys step 3 has worked |
How it behaves
| Behaviour | Detail |
|---|---|
| Order in the queue | Paid surveys are claimed before every free one. They use neither the free daily budget nor the account's free survey, and run while free surveys are deferred to tomorrow |
| Same event twice | Every event id is stored once; a repeat is answered and ignored. One checkout session gives one purchase |
| Wrong amount | A completed checkout whose amount before discount is not on our list is recorded as amount_mismatch and nothing is delivered. For a larger panel bought from a finished paid result the expected amount is the list price less what was paid, before tax, for the panel of that result; the webhook works that sum out again from our own records |
| Buyer on the waitlist | Admitted at once, marked purchase |
| Failure | After three failed attempts the purchase is marked refund_due; the next worker pass asks Stripe for the refund, marks it refunded and emails the buyer. If Stripe refuses, it is tried again on every pass and logged |
| Study deleted before payment arrived | The payment is recorded and refunded the same way |
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
| No offers on the study page | One of BUNDLES_ON_SALE, STRIPE_SECRET_KEY, STRIPE_WEBHOOK_SECRET is missing on the API |
Set all three and restart |
| Webhook shows 400 "Signature check failed." in Stripe | Wrong signing secret, or a proxy changed the body | Copy the secret of this endpoint again; the body must reach the API unchanged |
| Webhook shows 400 "This notification is from the other Stripe mode (test or live)." | Test key with live endpoint or the reverse | Make both test or both live |
| Paid, but the study stays "Ready to run" | The webhook did not arrive | Stripe dashboard, the event, "Resend". Check the endpoint address |
| Worker log: "needs a refund but STRIPE_SECRET_KEY is not set" | Workers lack the key | Set it on the workers; the refund goes out on the next pass |
| Worker log: "refund of purchase ... was not accepted" | Key lacks Refunds write access, or the charge is already refunded | Fix the key's permissions; or refund in the dashboard, which marks the purchase through charge.refunded |
Outcome no_study in stripe_events |
Study was deleted or busy when payment arrived | Nothing; it is refunded automatically |
Every checkout is tagged product = koloriq in Stripe so the company's finance app can tell KolorIQ's
sales from Caching Out's on the shared account; see The finance feed.
An operator can refund a purchase by hand, with a reason, from the operator console.
To see recent events: select id, type, outcome, received_at from stripe_events order by received_at desc limit 20;