Skip to content

Record Payments Without Storing Card Data

Payment providers made taking a card payment easy: a hosted form, a webhook, done. What they don't give you is the payment in your own data, next to the order it paid for. So support opens the provider's dashboard to answer "did this order get paid?", finance exports CSVs to reconcile refunds, and nobody can query "orders paid but not shipped" in one place.

The fix is to keep a record of each payment in your backend, without ever touching the card.

What to keep, and what never to keep

Keep what happened: who paid whom, how much, for what, when, whether it worked, and the provider's id of the payment. Never keep the card: its number, expiry, security code, or the provider's reusable tokens. Those belong to the provider, who is built and audited to hold them. A backend that stores them takes on PCI DSS obligations it almost certainly doesn't want.

ObjectsGrid records payments as PayActions, a Schema.org type, and makes the second rule impossible to break: a PayAction has no field for card data, and a payment that carries one is refused.

Record it from the provider's webhook

When the provider tells your server a payment succeeded, record it:

curl -X POST https://apis.objectsgrid.com/payactions \
  -H 'X-ObjectsGrid-AccessPoint: EU' -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' \
  -d '{"object": {"at_id": "https://apis.objectsgrid.com/orders/<order>"},
       "agent": {"at_id": "https://apis.objectsgrid.com/persons/<customer>"},
       "recipient": {"at_id": "https://apis.objectsgrid.com/organizations/<shop>"},
       "price": 189.70, "priceCurrency": "EUR",
       "actionStatus": "https://schema.org/CompletedActionStatus",
       "provider": {"at_id": "https://apis.objectsgrid.com/organizations/<stripe>"},
       "providerPaymentId": "pi_3Q0a1b2c3d4e5f",
       "instrument": {"at_type": "PaymentCard", "paymentMethodType": "card", "name": "Visa ending 4242"},
       "startTime": "2026-12-02T10:00:00Z", "endTime": "2026-12-02T10:00:02Z"}'
  • object is what it pays: an Order or an Invoice.
  • agent pays recipient. The agent is pinned to the version current when you record it, as an order's customer is.
  • actionStatus follows the provider: PotentialActionStatus when created, ActiveActionStatus while pending, CompletedActionStatus or FailedActionStatus with error, the provider's reason.
  • instrument is for display: a kind (PaymentCard, PaymentService for a wallet or bank service) and a name.

Webhooks arrive twice; payments don't

Providers deliver webhooks at least once, so the same "payment succeeded" can arrive twice, or "succeeded" before "processing". Find the PayAction by the provider's id before you create one:

curl -G https://apis.objectsgrid.com/payactions \
  -H 'X-ObjectsGrid-AccessPoint: EU' -H "Authorization: Bearer $TOKEN" \
  --data-urlencode 'where={"providerPaymentId": {"equals": "pi_3Q0a1b2c3d4e5f"}}'

Create it when there's none, update its status when there is. Lists are seconds behind a write, so for two deliveries arriving in the same second, keep your own short-lived lock or a unique constraint on the provider's id in your webhook handler. See how to verify webhooks and handle retries for the general rules.

Refunds go the other way

A refund is a PayAction from the shop to the customer, with refundOf naming the payment:

{"object": {"at_id": "https://apis.objectsgrid.com/orders/<order>"},
 "agent": {"at_id": "https://apis.objectsgrid.com/organizations/<shop>"},
 "recipient": {"at_id": "https://apis.objectsgrid.com/persons/<customer>"},
 "price": 89.90, "priceCurrency": "EUR",
 "actionStatus": "https://schema.org/CompletedActionStatus",
 "providerPaymentId": "re_3Q0a1b2c3d4e5g",
 "refundOf": {"at_id": "https://apis.objectsgrid.com/payactions/<payment>"}}

Read an order with its payments

The Order and the Invoice list their PayActions in GraphQL, so support's question is one request:

query {
  order(id: "<order>") {
    orderNumber
    payments { items { price priceCurrency actionStatus instrument { name } refundOf { id } } }
  }
}

Recording a payment changes nothing else. Your app moves the order's orderStatus and the invoice's paymentStatus, because only it knows whether "paid" means "ship now" or "wait for the bank transfer to clear".

What stays private

Payments are business records. They have no JSON-LD document, so they never end up in a page. Your access policy decides who reads them: finance and support, not the warehouse. And because the payer is a reference to a Person, a GDPR erasure of the person leaves the amounts for your accounts and removes who they were.

The Carts and checkout guide has the rest, and a checkout that can't charge the wrong price shows the step before.