Skip to content
Hardcount
Run it locally
Pre-1.0 · one maintainer · Stripe and cards only · no SDKs (client libraries) yet · no production users yet. Docs describe v0.12.0 (30 Nov 2026) · What’s new →

Connect Stripe and take card payments

This guide connects your Stripe account to Hardcount, saves a test customer’s card, and follows the first charge. Hardcount works out each bill and makes the invoice; Stripe charges the card, and the money goes straight to your Stripe account.

Do it in test mode first. Each mode, test and live, has its own Stripe connection. You connect live mode the same way when you are ready, in the dashboard’s live mode or with a live key.

  • Hardcount running, with its address in HARDCOUNT and a test secret key in HARDCOUNT_KEY (first invoice).
  • A test customer, with its Hardcount ID (hc_cus_…) in CUSTOMER_ID for step 3. The first invoice page creates one in its step 3.
  • A Stripe account, in test mode.
  • An address Stripe can reach. Stripe sends its webhooks (messages about payments) to Hardcount over the internet. It cannot reach your own computer: there, install the Stripe CLI and sign it in to your Stripe account with stripe login. Step 2 uses it to pass the webhooks on.

How payments work, in short: Payments.

  1. In Stripe, open Developers → API keys. Copy the secret key (sk_test_…, or a restricted key, rk_test_…) and the publishable key (pk_test_…).

  2. In Hardcount, open Settings → Payments, with the dashboard in test mode. Under Connect your Stripe API keys, paste both keys and click Connect test mode.

    You see: “Verified as” and your Stripe account’s name.

Or with the API. read -rs asks for the secret key without showing it, so the key is not on your screen and not in the command your shell records. Paste the key, then press Enter:

Terminal window
read -rs STRIPE_SK
jq -n --arg sk "$STRIPE_SK" --arg pk "pk_test_…" \
'{livemode: false, secret_key: $sk, publishable_key: $pk}' \
| curl -s -X POST "$HARDCOUNT/v1/settings/stripe" \
-H "Authorization: Bearer $HARDCOUNT_KEY" \
-H "Content-Type: application/json" \
-d @- | jq '{id, stripe_account_name, verified_at, last_verified_error, last_verified_error_kind}'
unset STRIPE_SK

You see: the connection’s id (hc_spc_…), your account’s name, a verified_at time, and null for the two error fields. When the check fails, the keys are still saved, but nothing can be charged until a check passes. last_verified_error says why, and last_verified_error_kind says what to do:

  • rejected: Stripe refused the key. Save a working key.
  • unavailable: Hardcount could not reach Stripe, so the key was not checked. Save the same keys again to check them.

A key manages only its own mode’s Stripe connection. Your test key connects test mode, and a request from it for live mode answers 403. Connect live mode with a live key (hc_secret_live_…), or in the dashboard in live mode.

Hardcount learns that a card was saved, or a payment succeeded, from Stripe’s webhooks. Each connection has its own webhook address: <your Hardcount address>/v1/webhooks/stripe/<id>, with the id from step 1. Settings → Payments shows it under Deliver Stripe events to Hardcount.

  1. Send Stripe’s events to that address.

    • On a server Stripe can reach: in Stripe, open Developers → Webhooks and add an endpoint with that address. Choose the Snapshot payload style: Hardcount refuses a thin event with 400. Pick these 12 events, the ones Hardcount lists under the address:

      • payment_intent.succeeded, payment_intent.payment_failed
      • checkout.session.completed
      • setup_intent.succeeded, setup_intent.setup_failed
      • charge.refund.updated, refund.created, refund.updated, refund.failed
      • charge.dispute.created, charge.dispute.updated, charge.dispute.closed

      You see: the endpoint’s signing secret (whsec_…) in Stripe.

    • On your own computer: Stripe cannot reach it, so skip the endpoint in the Stripe Dashboard. With the Stripe CLI signed in to your Stripe account, run this in a second terminal and leave it running. It passes Stripe’s events on to Hardcount. Settings → Payments shows the command with your own address.

      Terminal window
      stripe listen \
      --events payment_intent.succeeded,payment_intent.payment_failed,checkout.session.completed,setup_intent.succeeded,setup_intent.setup_failed,charge.refund.updated,refund.created,refund.updated,refund.failed,charge.dispute.created,charge.dispute.updated,charge.dispute.closed \
      --forward-to http://localhost:8080/v1/webhooks/stripe/hc_spc_…

      The command names the events to forward, the same list as above: the Stripe CLI does not start without one.

      You see: the CLI prints a signing secret (whsec_…).

  2. Paste the signing secret into Hardcount and click Finish setup. Or send it with PATCH /v1/settings/stripe/test/webhook and {"webhook_secret": "whsec_…"}.

    You see: the card reads Stripe test mode connected, with a Ready badge.

Until the secret is saved, Hardcount answers Stripe’s webhooks with 404. A customer then sees “card saved” on Stripe’s page, but Hardcount does not learn of the card until Stripe sends the event again. Stripe sends a failed delivery again for up to three days in live mode, and for a few hours in test mode.

The customer types their card on a Stripe page, never on yours. You give them a link to it:

  • From the dashboard: on the customer’s page, Payment methods, click Add payment method, then email the link or copy it.

  • From the API:

    Terminal window
    curl -s -X POST "$HARDCOUNT/v1/customers/$CUSTOMER_ID/payment-methods/setup-session" \
    -H "Authorization: Bearer $HARDCOUNT_KEY" \
    -H "Content-Type: application/json" \
    -d '{}' | jq -r .url

    You see: a https://checkout.stripe.com/… address. Send it to the customer, or open it yourself in test mode. Add "return_url" to the body to choose where Stripe sends them afterwards. Hardcount adds ?status=success or ?status=cancel to it.

    An error with return_address_not_set instead? Hardcount has no address to send the customer back to. The quick start sets one. On another install, set CUSTOMER_PORTAL_URL (below), or pass "return_url".

  • By email from Hardcount: POST /v1/customers/{customer_id}/payment-methods/send-setup-email sends the link to the customer’s email address. It needs email set up (Set up email).

In test mode, save Stripe’s test card 4242 4242 4242 4242, with any future expiry, any CVC and any postal code.

You see: on the customer’s page, Payment methods lists Visa ····4242. GET /v1/customers/{customer_id}/payment-methods lists it too. A card saved this way becomes the customer’s default, the one Hardcount charges.

A customer can also save a card by paying an invoice with Pay on its hosted invoice page.

An invoice the customer already has. An invoice issued before the card was saved stays open, such as the one the first invoice page made (its step 7 saves the ID in INVOICE_ID). Charge it now:

  • From the dashboard: open the invoice and click Collect payment, then confirm.

  • From the API:

    Terminal window
    curl -s -X POST "$HARDCOUNT/v1/invoices/$INVOICE_ID/collect" \
    -H "Authorization: Bearer $HARDCOUNT_KEY" | jq '{status, payment_status}'

    You see: "status": "paid" and "payment_status": "succeeded".

Left alone, the invoice is charged on the next billing run (Payments).

A new invoice. Put the customer on a plan and let an invoice be issued. For a test customer, you need not wait for the period end: canceling the subscription issues its final invoice at once (first invoice, step 6). Right after the invoice is issued, Hardcount uses any credit the customer holds, then charges the card for the rest.

You see, either way:

  • the invoice reads Paid in the dashboard, and the payment shows in your Stripe dashboard, under Payments;
  • your app gets invoice.paid and payment.succeeded (Receive webhooks).

To see a failure, save 4000 0000 0000 0341 on another customer. Stripe saves it, then declines every charge. The invoice’s payment goes to failed, payment.failed is sent, and dunning starts: Hardcount’s automatic payment retries for an unpaid invoice.

A dispute is a customer asking their bank to reverse a card payment. With the three charge.dispute.* events in step 2, Hardcount records each dispute on its invoice, which stays paid, and sends payment.dispute_opened, then payment.dispute_closed when Stripe closes it. Read them with GET /v1/invoices/{id}/disputes. Respond to a dispute in Stripe, before its deadline.

More: Card disputes.

After a customer saves a card or pays, Stripe sends them to a page of your dashboard. Set these on your Hardcount server. None has a default: while one is unset, the flow it serves is refused, so no customer is sent to an address that doesn’t exist.

Setting The page after Where the customer lands While it is unset
CUSTOMER_PORTAL_URL a setup link from step 3, with no return_url <CUSTOMER_PORTAL_URL>/payment-method-added?status=success (or cancel) The setup link is refused with return_address_not_set
PAYMENT_UPDATE_RETURN_URL the “add a payment method” email Hardcount sends when an invoice finds no card <PAYMENT_UPDATE_RETURN_URL>?status=success (or cancel); it is a full address That email is not sent
HOSTED_INVOICE_BASE_URL Pay on the hosted invoice page <HOSTED_INVOICE_BASE_URL>/invoice/<token>?paid=1, the invoice’s own page The page shows no Pay button

More: Settings.

Next: go live: Production on one VM. To test a whole charge, from saving a card to a refund: Stripe end-to-end test.

Stuck, or found a bug? Ask in Discussions · Open an issue